nite_man has asked for the wisdom of the Perl Monks concerning the following question:
Hi wise monks!
I've found a very strange result of function localtime(). Let's see simple peace of code:
After run it I've got those results: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"; }
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"!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
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Strange result of localtime()
by muntfish (Chaplain) on Sep 30, 2004 at 11:29 UTC | |
by nite_man (Deacon) on Sep 30, 2004 at 12:23 UTC | |
|
Re: Strange result of localtime()
by Corion (Patriarch) on Sep 30, 2004 at 11:25 UTC |