Solaris 11.2中的奇怪的mktime行为,bug还是其他什么?

时间:2014-10-16 09:41:34

标签: timezone solaris mktime

看起来像个bug,先看看代码:

#include <time.h>
#include <stdio.h>

int main() {

    time_t t;
    struct tm tm1;

    tzset();

    time(&t);
    localtime_r(&t, &tm1);

    tm1.tm_mday = 27;
    tm1.tm_sec = 59;
    tm1.tm_min = 59;
    tm1.tm_hour = 0;
    tm1.tm_mon = 9;

    t = mktime(&tm1);
    printf(" tm_hour = %d:\t\t(%d) %s", tm1.tm_hour, t, asctime(&tm1));

    tm1.tm_mday = 26;
    tm1.tm_sec = 59;
    tm1.tm_min = 59;
    tm1.tm_hour = 0;
    tm1.tm_mon = 9;

    t = mktime(&tm1);
    printf(" tm_hour = %d:\t\t(%d) %s", tm1.tm_hour, t, asctime(&tm1));

}

我相信它会像这样运行:


     $ ./tzcheck3
     tm_hour = 0:           (1414360799) Mon Oct 27 00:59:59 2014
     tm_hour = 0:           (1414270799) Sun Oct 26 00:59:59 2014

相反,我得到了这个:


     $ ./tzcheck3
     tm_hour = 0:           (1414360799) Mon Oct 27 00:59:59 2014
     tm_hour = 1:           (1414274399) Sun Oct 26 01:59:59 2014

安装的操作系统是Solaris 11.2.2.8.0 + IDR 1418.1,时区数据是2014f,这里是时区zdump:


    # zdump -v Europe/Moscow | tail -10
    Europe/Moscow  Sat Mar 27 22:59:59 2010 UTC = Sun Mar 28 01:59:59 2010 MSK isdst=0
    Europe/Moscow  Sat Mar 27 23:00:00 2010 UTC = Sun Mar 28 03:00:00 2010 MSD isdst=1
    Europe/Moscow  Sat Oct 30 22:59:59 2010 UTC = Sun Oct 31 02:59:59 2010 MSD isdst=1
    Europe/Moscow  Sat Oct 30 23:00:00 2010 UTC = Sun Oct 31 02:00:00 2010 MSK isdst=0
    Europe/Moscow  Sat Mar 26 22:59:59 2011 UTC = Sun Mar 27 01:59:59 2011 MSK isdst=0
    Europe/Moscow  Sat Mar 26 23:00:00 2011 UTC = Sun Mar 27 03:00:00 2011 MSK isdst=0
    Europe/Moscow  Sat Oct 25 21:59:59 2014 UTC = Sun Oct 26 01:59:59 2014 MSK isdst=0
    Europe/Moscow  Sat Oct 25 22:00:00 2014 UTC = Sun Oct 26 01:00:00 2014 MSK isdst=0
    Europe/Moscow  Tue Jan 19 03:14:07 2038 UTC = Tue Jan 19 06:14:07 2038 MSK isdst=0
    Europe/Moscow  Mon Jan 18 03:14:07 2038 UTC = Mon Jan 18 06:14:07 2038 MSK isdst=0

你可以看到太阳10月26日02:00有转换,但我仍然无法理解为什么mktime在这个日期00:59从01:59开始。

您怎么看?

0 个答案:

没有答案