I am trying to determine exactly when a daylight savings transition occurs in a Perl script using Perl's localtime
function and printing the time zone using strftime
.
The strange thing is this seems to work fine for this year and other more recent years, but if I try and go back to the year 2000 for example, Perl seems to think the transition occurs on the wrong day!
According to Google, daylight savings started on April 2nd in the year 2000:
...but for some reason, the Perl code below seems to disagree:
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 savings time in the year 2000 started on March 12th when clearly this is incorrect?
EDIT:
After reading the comments below it looks like this may be an issue with the operating system and not Perl. It looks like this may be a bug in Windows 7.
01:59:59 - EST
and02:00:00 - EST
. Also, perl is using system (libc) functions to determine timezones and when DST begins and ends. So I suspect the problem is in your system timezone database, not in perl. – Exoteric03/12/2000 01:59:59 - CET
and03/12/2000 02:00:00 - CET
. I'm running Ubuntu 14.04 andldd --version
shows meldd (Ubuntu EGLIBC 2.19-0ubuntu6.7) 2.19
. Tryldd --version
to show the libc's version. Interesting observation of yours, though. – Maroney