Windows 7 error with summer savings?

I am trying to pinpoint when the daylight saving time transition occurs in a Perl script using the Perl localtime function and printing the time zone using strftime .

The strange thing seems to work great this year and in other recent years, but if I try to get back to 2000, for example, Perl seems to think the transition is happening the same day!

According to Google, daylight saving time began on April 2, 2000:

enter image description here

... but for some reason, the Perl code below disagrees:

 use POSIX qw(strftime); use Time::Local; # 03/12/2000 01:59:59 ($year, $month, $day, $hour, $minute, $second) = (2000, 3, 12, 1, 59, 59); $epoch = timelocal($second, $minute, $hour, $day, $month - 1, $year); # Print the time print strftime "%m/%d/%Y %H:%M:%S - %Z\n", localtime($epoch); # 03/12/2000 02:00:00 ($year, $month, $day, $hour, $minute, $second) = (2000, 3, 12, 2, 0, 0); $epoch = timelocal($second, $minute, $hour, $day, $month - 1, $year); # Print the time print strftime "%m/%d/%Y %H:%M:%S - %Z\n", localtime($epoch); 

Output:

 03/12/2000 01:59:59 - Eastern Standard Time 03/12/2000 03:00:00 - Eastern Daylight Time 

Why does Perl think that daylight saving time in 2000 began on March 12, when this is clearly wrong?


EDIT:

After reading the comments below, it looks like a problem with the operating system, not Perl. It seems like this could be a bug in Windows 7.

+8
windows-7 time dst perl windows-7-x64
source share
1 answer

I don’t know the specifics of the internal Perl components (and I don’t feel like combing the source code), but such errors usually occur on Windows when using the FileTimeToLocalFileTime and LocalFileTimeToFileTime Win32 Functions. These functions do not take into account the history of time zones, but only the current rules. The documentation explains what to do:

To account for daylight saving time when converting file time to local time, use the following sequence of functions instead of FileTimeToLocalFileTime :

  • FileTimeToSystemTime
  • SystemTimeToTzSpecificLocalTime
  • SystemTimeToFileTime

A similar sequence should be performed for the inverse function using TzSpecificLocalTimeToSystemTime for the middle step.

It is likely that the version of Perl that you run calls these functions as part of the implementation of the localtime and timelocal Win32 functions. Based on the comments in the question that some cannot reproduce your results, I would suggest that newer versions of Perl were probably fixed as described above. If not, they should be. (I'm sure someone who is more familiar with Perl's internal components can specify specific code and an error report.)

+2
source share

All Articles