当 DST 结束并且时间回退一小时时,为什么 localtime() 将 tm_isdst 标志设置为 1 小时持续时间
我有一个在莫斯科时区配置的系统。莫斯科每年三月的最后一个星期日进入夏令时。莫斯科夏令时 (MSD) 为 UTC +4 小时。十月的最后一个星期日,夏令时结束,回到莫斯科标准时间 (MSK),即 UTC +3 小时。
从 MSD 到 MSK 的过渡发生在 10 月最后一个星期日的凌晨 3 点。到凌晨 3 点,时钟再次重置为凌晨 2 点。因此,在 10 月的最后一个星期日,将有两次凌晨 2 点。凌晨 2 点第一时间,莫斯科仍处于 MSD(UTC +4)。凌晨 2 点第二次,莫斯科采用 MSK(UTC +3)。
我的问题是,如果我使用 localtime() 函数在 10 月最后一个星期日凌晨 2 点的第二个实例获取本地时区信息,tm_isdst 标志将由 localtime() 设置还是不会设置。我的观察是,tm_isdst 标志是由 localtime() 在 MSK 的凌晨 2 点至凌晨 3 点(第二个实例)的一小时窗口期间设置的。这是错误还是预期行为?
作为记录,我的 timezone/Europe tz 数据库文件是最新的,并且相应的时区数据库文件由 zic 编译器正确编译为 /usr/share/zoneinfo/Europe/Moscow。
I have a system 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从对规范的一些研究来看,C 似乎从环境变量中确定了所有这些信息。在本例中,TZ 环境变量是为 POSIX 指定的。 Windows 将其存储在注册表位置。
在这 1 小时期间,您显然不再处于夏令时,因此根据 tm_isdst 标志的定义,应该很清楚。
要知道这是否是编译器/库实现或操作系统的错误,您必须在此期间直接检查环境变量值。
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.