Article Review: Migrating from std.date to std.datetime

Jonathan M Davis jmdavisProg at gmx.com
Mon May 16 15:29:33 PDT 2011


> Jonathan M Davis wrote:
> > On 2011-05-15 03:34, Rainer Schuetze wrote:
> >> - my current uses of datetime are comparing file times and displaying
> >> the file time. Much better than std.date, the times displayed are now
> >> the same as shown by Explorer/dir most of the time, but some are off by
> >> one hour. It seems this happens for times with a different daylight
> >> saving. Is this a bug? Or do I need to call something else than
> >> 
> >> writeln(timeLastModified(file).toSimpleString());
> >> 
> >> The ISO versions or conversion to DateTime produce the same output. My
> >> local time is UTC+1+DST.
> > 
> > I'd need more data to have any idea what's going on, but it sounds like a
> > bug.
> 
> I have investigated it a bit, and I'm currently thinking that Explorer,
> dir and Total Commander are wrong, and std.datetime is right.
> 
> What I did to test:
> - create a new file, verify the dates printed are correct. fine in all
> programs
> - set the system time back to February
> - create the file again, verify the dates printed are correct. fine in
> all programs
> - set the system time back to May
> - now the displayed file time is the same when using std.datetime, but
> an hour later with all other programs.
> 
> Maybe it's an XP or NTFS issue, but I would expect the file time not to
> change with the date it is displayed.

Well, Microsoft made the mistake of making it so that Windows boxes keep their 
time in local time (which they probably can't fix and maintain backwards 
compatability, so we're likely stuck), and that can have some interesting 
consequences, since that means that the system clock actually gets changed 
when DST begins or ends. I would have thought that the OS and file system 
would handle that well enough for Explorer to display the time correctly, but 
I don't know. Given how hard it can be to catch DST-related bugs and the fact 
that people don't generally examine the times on their files closely enough to 
verify that their times aren't 1 hour off 6 months later, it wouldn't entirely 
surprise me if there were bugs with regards to that on XP. But I still would 
have thought that they would have caught it.

- Jonathan M Davis


More information about the Digitalmars-d mailing list