Hi wise monks!

I've found a very strange result of function localtime(). Let's see simple peace of code:

for my $val ( qw(1 5 10 24) ) { print "Add $val hour ...\n"; for my $date (qw(1096600000 1099170000) ) { print "\tBefore: $date - ".localtime($date)."\n"; print "\tAfter: ".($date+$val*3600)." - ".localtime($date+$val +*3600)."\n"; } print "\n"; }
After run it I've got those results:
Add 1 hour ... Before: 1096600000 - Fri Oct 1 06:06:40 2004 After: 1096603600 - Fri Oct 1 07:06:40 2004 Before: 1099170000 - Sun Oct 31 00:00:00 2004 After: 1099173600 - Sun Oct 31 01:00:00 2004 Add 5 hour ... Before: 1096600000 - Fri Oct 1 06:06:40 2004 After: 1096618000 - Fri Oct 1 11:06:40 2004 Before: 1099170000 - Sun Oct 31 00:00:00 2004 After: 1099188000 - Sun Oct 31 04:00:00 2004 Add 10 hour ... Before: 1096600000 - Fri Oct 1 06:06:40 2004 After: 1096636000 - Fri Oct 1 16:06:40 2004 Before: 1099170000 - Sun Oct 31 00:00:00 2004 After: 1099206000 - Sun Oct 31 09:00:00 2004 Add 24 hour ... Before: 1096600000 - Fri Oct 1 06:06:40 2004 After: 1096686400 - Sat Oct 2 06:06:40 2004 Before: 1099170000 - Sun Oct 31 00:00:00 2004 After: 1099256400 - Sun Oct 31 23:00:00 2004
It's amazing! Any ideads why result is "Sun Oct 31 23:00:00 2004"? It should be "Mon Nov 1 00:00:00 2004"!

Well, maybe there is a bug in the implementation of function localtime() but possibly it happened because today is my last work day before holiday :)

---
Michael Stepanov aka nite_man

It's only my opinion and it doesn't have pretensions of absoluteness!


In reply to Strange result of localtime() by nite_man

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.