[Development] How does mktime() handle DST transitions ?

Welbourne Edward edward.welbourne at theqtcompany.com
Fri Nov 6 13:34:06 CET 2015


> If you're willing to compile and run the attached simple C program,
> please let me know its output and your platform's details - ideally
> off-list - I'll give a summary in a few days' time.

Thanks to those who responded, I now know:
 * that all the platforms below do the same thing if tm_isdst is 0 or 1 (Yay !)
 * with .tm_isdst = -1, there is diversity of handling.

When tm_isdst is 0 or 1, in the fall back it gets preserved;
in the spring forward, it gets flipped and tm_hour is changed
in the way it usually would for such a flip.

OSX 10.10, Xcode 6.02
 * varies within the hour (see below)
 * at half past: handled as if you'd claimed tm_isdst = 0 (see above)

MacBook, Darwin 15.0.0
Ubuntu 12.04, glibc 2.15
Debian/stretch, glibc 2.19
 * clear tm_isdst and move an hour earlier in spring
 * set tm_isdst and preserve hour in autumn

MinGW
MSVC 2015
 * set tm_isdst and move an hour later in spring
 * clear tm_isdst and preserve hour in autumn.

My initial test was, it turns out, naive.  Apparently some platforms
vary handling of -1 across the hour.  I also bit the bullet and worked
out how to auto-detect DST transitions.  One response indicates
asctime_r() isn't portable.  So I attach a new version of mktime.c, that
needs no manual configuration and is, I hope, a little more portable.  I
note that setting the TZ environment variable (on platforms that honour
it, at least) can be used to discover what your O/S thinks happens in
other time-zones than your local one.

As before, if anyone feels inclined to give this a whirl, I'd again
appreciate any responses, along with descriptions of the system they
come from (e.g. uname -a output).

    Eddy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mktime.c
Type: text/x-csrc
Size: 6196 bytes
Desc: mktime.c
URL: <http://lists.qt-project.org/pipermail/development/attachments/20151106/fb05480a/attachment.c>


More information about the Development mailing list