开发者

Why does localtime() set tm_isdst flag for 1 hour duration when DST ends and time falls back by one hour

开发者 https://www.devze.com 2023-02-12 02:42 出处:网络
I have a 开发者_StackOverflowsystem configured in Moscow Time zone. Moscow goes into daylight savings time on the last sunday of March every year. Moscow Daylights Savings time (MSD) is UTC +4 hours.

I have a 开发者_StackOverflowsystem configured in Moscow Time zone. Moscow goes into daylight savings time on the last sunday of March every year. Moscow Daylights Savings time (MSD) is UTC +4 hours. On the last sunday of october, daylight savings ends and it goes back to Moscow standards time (MSK) which is UTC +3 hours.

The transition from MSD to MSK happens on the last sunday of october at 3 AM. By 3 AM, the clock is reset back to 2 AM again. So on the last sunday of october, there will be two instances of 2 AM. At the first instance of 2 AM, Moscow is still in MSD (UTC +4). At the second instance of 2 AM Moscow is in MSK (UTC +3).

My query is, if I use localtime() function to get the local timezone information at the second instance of 2 AM on the last sunday of october, will the tm_isdst flag be set by localtime() or will it not be set. My observation is that the tm_isdst flag is set by localtime() during the one hour window 2 AM - 3 AM (the second instance) in MSK. Is this bug or is it an expected behavior?

For the records, my timezone/Europe tz database file is upto date and the corresponding timezone database file is properly compiled by zic compiler as /usr/share/zoneinfo/Europe/Moscow.


From a little research in the specs, it looks like C determines all of this info from environment variables. In this case, the TZ environment variable is specified for POSIX. Windows stores it in a registry location. During this 1 hour period, you are clearly no longer in daylight savings time, so by the definition of the tm_isdst flag, it should be clear.

To know if it is a bug with the compiler/library implementation or OS, you would have to examine the environment variable value directly during this period.

0

精彩评论

暂无评论...
验证码 换一张
取 消