Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Perl mktime/gmtime peculiarities (Inc. Testcase) [Cygwin/Windows]

by NeilSaunders (Initiate)
on Aug 04, 2008 at 14:22 UTC ( #702067=perlquestion: print w/ replies, xml ) Need Help??
NeilSaunders has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I'm writing an application in Perl that processes a logfile with timestamps with differing timezones - One in UTC, and one in BST. For the uninitiated, BST, or British Summer Time is UTC, with Daylight savings time running from 1am on the last Sunday of March until 1am UTC/2am BST on the Last Sunday in October; So in 2008 this means BST runs from 01:00:00 AM 30th March through to 01:00:00 AM 26th October.
Test Program:
#!/usr/bin/perl use POSIX; use Time::Local; print "Timezone: " . $ENV{TZ} . "\n\n"; &dateTimeToTimestamp("2008-03-30T00:59:59"); &dateTimeToTimestamp("2008-03-30T01:00:00"); &dateTimeToTimestamp("2008-03-30T01:00:01"); &dateTimeToTimestamp("2008-03-30T02:00:00"); &dateTimeToTimestamp("2008-10-26T00:59:59"); &dateTimeToTimestamp("2008-10-26T01:00:00"); &dateTimeToTimestamp("2008-10-26T01:00:01"); &dateTimeToTimestamp("2008-10-26T01:00:02"); &dateTimeToTimestamp("2008-10-26T01:30:00"); &dateTimeToTimestamp("2008-10-26T01:30:01"); &dateTimeToTimestamp("2008-10-26T01:30:01"); &dateTimeToTimestamp("2008-10-26T01:45:00"); &dateTimeToTimestamp("2008-10-26T01:50:00"); &dateTimeToTimestamp("2008-10-26T01:55:00"); &dateTimeToTimestamp("2008-10-26T01:55:59"); &dateTimeToTimestamp("2008-10-26T01:56:00"); &dateTimeToTimestamp("2008-10-26T01:57:00"); &dateTimeToTimestamp("2008-10-26T01:58:00"); &dateTimeToTimestamp("2008-10-26T01:59:58"); &dateTimeToTimestamp("2008-10-26T01:59:59"); &dateTimeToTimestamp("2008-10-26T02:00:00"); &dateTimeToTimestamp("2008-10-26T02:00:01"); &dateTimeToTimestamp("2008-10-26T02:59:59"); &dateTimeToTimestamp("2008-10-26T03:00:00"); &dateTimeToTimestamp("2008-10-26T03:00:01"); sub dateTimeToTimestamp { print $_[0] . " "; $_[0] =~ /(\d{4})-(\d{2})-(\d{2})([ |T])(\d{2}):(\d{2}):(\d{2} +)/; my($year, $mon, $day, $GMT, $hour, $min, $sec) = ($1, $2, $3, +$4, $5, $6, $7); print "UTC\t" . timegm($sec, $min, $hour, $day, $mon - 1, $yea +r - 1900) . "\t"; print "BST\t" . mktime($sec, $min, $hour, $day, $mon - 1, $yea +r - 1900, 0, 0) . "\n"; }
For which I get the output:
2008-03-30T00:59:59 UTC 1206838799 BST 1206838799 2008-03-30T01:00:00 UTC 1206838800 BST 2008-03-30T01:00:01 UTC 1206838801 BST 2008-03-30T02:00:00 UTC 1206842400 BST 1206838800 ------------------------------------------------ << Added for clarity 2008-10-26T00:59:59 UTC 1224982799 BST 1224979199 2008-10-26T01:00:00 UTC 1224982800 BST 1224979200 2008-10-26T01:00:01 UTC 1224982801 BST 1224979201 2008-10-26T01:00:02 UTC 1224982802 BST 1224979202 2008-10-26T01:30:00 UTC 1224984600 BST 1224981000 2008-10-26T01:30:01 UTC 1224984601 BST 1224981001 2008-10-26T01:30:01 UTC 1224984601 BST 1224981001 2008-10-26T01:45:00 UTC 1224985500 BST 1224981900 2008-10-26T01:50:00 UTC 1224985800 BST 1224982200 2008-10-26T01:55:00 UTC 1224986100 BST 1224982500 2008-10-26T01:55:59 UTC 1224986159 BST 1224982559 2008-10-26T01:56:00 UTC 1224986160 BST 1224986160 <<< + BST Ends at 01:56:00?? 2008-10-26T01:57:00 UTC 1224986220 BST 1224986220 2008-10-26T01:58:00 UTC 1224986280 BST 1224986280 2008-10-26T01:59:58 UTC 1224986398 BST 1224986398 2008-10-26T01:59:59 UTC 1224986399 BST 1224986399 2008-10-26T02:00:00 UTC 1224986400 BST 1224986400 2008-10-26T02:00:01 UTC 1224986401 BST 1224986401 2008-10-26T02:59:59 UTC 1224989999 BST 1224989999 2008-10-26T03:00:00 UTC 1224990000 BST 1224990000 2008-10-26T03:00:01 UTC 1224990001 BST 1224990001
So we can see that on the 30th of March, 1AM fails to exist in BST, as it gets shifted forwards an hour - All is good. My confusion is what happens on the 26th of October, as the time seems to go back at 01:56:00am instead of 02:00:00am. I can see the output change as I change timezones in Windows, but am confused as to where this 4 minute disparity comes from.

Any assistance gratefully received - It's driving me mad!

Kind Regards,

Neil Saunders.

Comment on Perl mktime/gmtime peculiarities (Inc. Testcase) [Cygwin/Windows]
Select or Download Code
Re: Perl mktime/gmtime peculiarities (Inc. Testcase) [Cygwin/Windows]
by Anonymous Monk on Aug 04, 2008 at 14:39 UTC
    I think it comes from the library implementing time/gmtime (i think c runtime) :)

    I'd try to compare results with DateTime

    On some Windows machine I get

    Timezone: 2008-03-30T00:59:59 UTC 1206838799 BST 1206867599 2008-03-30T01:00:00 UTC 1206838800 BST 1206867600 2008-03-30T01:00:01 UTC 1206838801 BST 1206867601 2008-03-30T02:00:00 UTC 1206842400 BST 1206871200 2008-10-26T00:59:59 UTC 1224982799 BST 1225011599 2008-10-26T01:00:00 UTC 1224982800 BST 1225011600 2008-10-26T01:00:01 UTC 1224982801 BST 1225011601 2008-10-26T01:00:02 UTC 1224982802 BST 1225011602 2008-10-26T01:30:00 UTC 1224984600 BST 1225013400 2008-10-26T01:30:01 UTC 1224984601 BST 1225013401 2008-10-26T01:30:01 UTC 1224984601 BST 1225013401 2008-10-26T01:45:00 UTC 1224985500 BST 1225014300 2008-10-26T01:50:00 UTC 1224985800 BST 1225014600 2008-10-26T01:55:00 UTC 1224986100 BST 1225014900 2008-10-26T01:55:59 UTC 1224986159 BST 1225014959 2008-10-26T01:56:00 UTC 1224986160 BST 1225014960 2008-10-26T01:57:00 UTC 1224986220 BST 1225015020 2008-10-26T01:58:00 UTC 1224986280 BST 1225015080 2008-10-26T01:59:58 UTC 1224986398 BST 1225015198 2008-10-26T01:59:59 UTC 1224986399 BST 1225015199 2008-10-26T02:00:00 UTC 1224986400 BST 1225015200 2008-10-26T02:00:01 UTC 1224986401 BST 1225015201 2008-10-26T02:59:59 UTC 1224989999 BST 1225018799 2008-10-26T03:00:00 UTC 1224990000 BST 1225018800 2008-10-26T03:00:01 UTC 1224990001 BST 1225018801

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://702067]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2014-07-23 05:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (133 votes), past polls