[Issue 5781] New: std.datetime: On Windows, times off by one hour in some years due to DST rule changes

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 23 23:29:31 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5781

           Summary: std.datetime: On Windows, times off by one hour in
                    some years due to DST rule changes
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: jmdavisProg at gmx.com


--- Comment #0 from Jonathan M Davis <jmdavisProg at gmx.com> 2011-03-23 23:26:10 PDT ---
If are on Windows 7 in one of most of the time zones in America, this lovely
little program

import std.datetime;
import std.stdio;

void main()
{
    writeln(SysTime(Date(1999, 3, 1)));
    writeln(SysTime(Date(1999, 3, 8)));
    writeln(SysTime(Date(1999, 3, 14)));
    writeln(SysTime(DateTime(1999, 3, 14, 1, 0, 0)));
    writeln(SysTime(DateTime(1999, 3, 14, 2, 0, 0)));
    writeln(SysTime(DateTime(1999, 3, 14, 3, 0, 0)));
    writeln(SysTime(Date(1999, 3, 15)));
    writeln(SysTime(Date(1999, 3, 22)));
    writeln(SysTime(Date(1999, 3, 29)));
    writeln(SysTime(Date(1999, 4, 1)));
    writeln(SysTime(Date(1999, 4, 3)));
    writeln(SysTime(DateTime(1999, 4, 4, 1, 0, 0)));
    writeln(SysTime(DateTime(1999, 4, 4, 2, 0, 0)));
    writeln(SysTime(DateTime(1999, 4, 4, 3, 0, 0)));
    writeln(SysTime(Date(1999, 4, 5)));
}

results in this output:

1999-Mar-01 00:00:00
1999-Mar-08 00:00:00
1999-Mar-14 00:00:00
1999-Mar-14 01:00:00
1999-Mar-14 01:00:00
1999-Mar-14 02:00:00
1999-Mar-14 23:00:00
1999-Mar-21 23:00:00
1999-Mar-28 23:00:00
1999-Mar-31 23:00:00
1999-Apr-02 23:00:00
1999-Apr-04 00:00:00
1999-Apr-04 01:00:00
1999-Apr-04 03:00:00
1999-Apr-05 00:00:00

The DST rules changed in most of North America in 2007. This bug occurs in any
year prior to 2007 for time zones in North America which had their DST rules
changed in 2007. It likely similarly affects other time zones whose DST rules
changed at some point. I don't know if this affects versions of Windows prior
to 7. I would be surprised if it didn't affect Vista, but I suspect that it
doesn't affect XP (it might though). DYNAMIC_TIME_ZONE_INFORMATION was added
with Windows Vista, and I suspect that that is what is being used under the
hood in 7. And if that is the case, then XP likely has different behavior. And
I can't use DYNAMIC_TIME_ZONE_INFORMATION in Phobos, since we can't assume that
Windows programmers are using Vista or newer and do not want to compile for XP.

Essentially, it has to do with the fact that in Windows 7, the Windows'
function SystemTimeToTzSpecificLocalTime doesn't really use the
TIME_ZONE_INFORMATION struct that it's given. Instead, it looks up the correct
time zone rules for the year in question. Wine does _not_ have this behavior,
and I did most of my Windows testing for std.datetime testing in Wine (I'm now
using VirtualBox with a Windows 7 install in it, which is a much better
solution overall, so that shouldn't be a problem in the future).

I'm not quite sure what the best fix for this is, but I'll sort it out and fix
it fairly soon. In the meantime, here's a bug report so that it's clear that
the bug exists, and it'll be clear when it's fixed. And if you have a Windows
XP or Vista box and are in the Pacific, Mountain, or Eastern time zones, I'd
appreciate it if you could run the above code and add the results to this bug
so that I know if XP and/or Vista have the same behavior.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list