[TriLUG] OT?: php anomaly
Aaron S. Joyner
aaron at joyner.ws
Thu Aug 17 10:00:48 EDT 2006
Alan Porter wrote:
>
>> I have a hunch it has something to do with leap years.
>
>
> How about Daylight Savings Time?
> The change takes place on the last Sunday in October.
> That would explain the 23-hour advance.
>
> FIXING the problem is left as an exercise for the reader.
>
>
> Alan
Yeah., quite simply put, there are more than 86400 seconds in those
days, if you're adjusting the clock correctly and adding the extra hour
back in to recover from daylight savings time. As Alan mentioned,
Daylight Savings Time is the last Sunday in October:
asjoyner at bob:~$ cal 10 2006
October 2006
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
asjoyner at bob:~$ cal 10 2005
October 2005
Su Mo Tu We Th Fr Sa
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
Just another example of why dealing with date time and calendaring is a
*hard* problem. There are hundreds of edge cases that you are bound to
overlook, such as leap years and numbers of days in Feburary (much
harder than it seems unless you've really dug into how leap years work
before), leap seconds at year roll overs, etc, etc ad nauseum. When
ever possible, always use a good robust library and leverage it's
functions for the most "abstract" way of doing what you want possible.
The +1 day operator taking care of silliness like this is a fantastic
and very practical example.
Aaron S. Joyner
More information about the TriLUG
mailing list