timelocal cannot handle the ambiguous hour (from 1 to 2am at the end of daylight savings time), because it has no $isdst parameter. Example:
use strict; use Time::Local; use POSIX; my ($time,$time2,$sec,$min,$hour,$mday,$mon,$year,$isdst); my ($wday, $yday, $hm); $sec = 59; $min = 59; $hour = 0; $mon = 9; $mday = 28; $year = 2001; $time = timelocal($sec,$min,$hour,$mday,$mon,$year); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($tim +e); $hm = sprintf("%02d/%02d/%04d %02d:%02d:%02d",$mon+1,$mday,$year+1900, +$hour,$min,$sec); print "Local time: $hm and DST is $isdst\n"; # Skip ahead one hour. $time += 3600; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($tim +e); $hm = sprintf("%02d/%02d/%04d %02d:%02d:%02d",$mon+1,$mday,$year+1900, +$hour,$min,$sec); print "Local time: $hm and DST is $isdst\n"; $time2 = timelocal($sec,$min,$hour,$mday,$mon,$year); if ($time == $time2) { print "timelocal conversion correct -- timestamp is $time\n"; } else { print "timelocal conversion error -- $time converted to $time2\n"; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($t +ime2); $hm = sprintf("%02d/%02d/%04d %02d:%02d:%02d",$mon+1,$mday,$year+19 +00,$hour,$min,$sec); print "(Local time: $hm and DST is $isdst)\n"; } $time2 = POSIX::mktime($sec,$min,$hour,$mday,$mon,$year,0,0,1); if ($time == $time2) { print "mktime conversion correct -- timestamp is $time\n"; } else { print "mktime conversion error -- $time converted to $time2\n"; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($t +ime2); $hm = sprintf("%02d/%02d/%04d %02d:%02d:%02d",$mon+1,$mday,$year+19 +00,$hour,$min,$sec); print "(Local time: $hm and DST is $isdst)\n"; } # -------- end of example -----------
This prints:
Local time: 10/28/2001 00:59:59 and DST is 1 Local time: 10/28/2001 01:59:59 and DST is 1 timelocal conversion error -- 1004255999 converted to 1004259599 (Local time: 10/28/2001 01:59:59 and DST is 0) mktime conversion correct -- timestamp is 1004255999

In reply to Re: POSIX::mktime() or Time::Local::timelocal() by Anonymous Monk
in thread POSIX::mktime() or Time::Local::timelocal() by japhy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.