From: Lloyd Zusman Date: 2006-01-30T19:18:45+09:00 Subject: Re: is it Time bug? Lloyd Zusman writes: > Pat Maddox writes: > >> First of all for doing stuff like this I highly recommend checking out >> Runt [1], it's a temporal expression library. Think regular >> expressions for time. >> >> Anyway I think it has to do with the fact that that the Date lib >> accounts for leap years, but your code doesn't. To explain it a bit.. >> >> There are 365.25 days in a year, not 365. This means that there are >> 31557600 seconds in a year, rather than the 31536000 that your code >> would generate. That leaves you with 21600 unnoticed seconds. 365 / >> 21600 = 0.0168981481, which is how many seconds are lost in each day. >> There are 63 days between your start date of Sep 01 and the "weird" >> date of Nov 02. 63 * 0.0168981481 = 1.03, so there's one lost second, >> causing the day to not roll over. >> >> Pretty fun, huh? :) > > [ ... ] > > Every day has exactly 86400 seconds (except every few years when a > leap-second is added/subtracted). The seconds-per-year issue is covered > by leap years. ... except on the daylight savings time transitions, of course. In that year in the USA, April 3 had 82,800 seconds, and October 30 had 90,000 seconds, which accounts for the discrepancy in the original date range. Also, the seconds-lost-per-day calculation above isn't correct. You need to divide 21600 by 365, not the other way around. This yields a bit less than one minute per day. -- Lloyd Zusman ljz@asfast.com God bless you.