4

Seems like a bug, have a look at the code first:

#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));

}

I believe it shall run like this:


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

Instead I've got this:


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

OS installed is Solaris 11.2.2.8.0 + IDR 1418.1, timezone data is 2014f, here is timezone 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

You can see that there is a switchover at Sun Oct 26 02:00, but I still cannot understand why mktime makes 01:59 from 00:59 at this date.

What do you think?

alanc
  • 4,102
  • 21
  • 24
  • Old timezone data might explain this. Russia has once used [daylight saving time](https://en.wikipedia.org/wiki/Daylight_saving_time) and switchover would take place on Sunday 26th October, should DST still be in use. –  Oct 16 '14 at 09:55
  • As I wrote timezone data is version 2014f, there is a switchover at 02:00 am, please look above. – Roman Stepanov Oct 16 '14 at 09:58
  • The switchover time is exactly what one would expect with DST, on last Sunday of October at 02:00AM. So I still think this is more about timezone data than anything else. –  Oct 16 '14 at 10:01
  • Russia isn't using DST from 2010, this switch is not DST either, localtime is set one hour backwards and it won't be ajusted anymore (at least this is what our government lied^H^H^H^H told us). And 2014f timezone data included this switchover as well. – Roman Stepanov Oct 16 '14 at 10:05

0 Answers0