From: Pat Maddox Date: 2006-01-30T16:10:43+09:00 Subject: Re: is it Time bug? 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? :) Now that I've taken the time to identify the problem, I honestly don't feel like solving it..but hopefully you can get started with this new found info :) Again, I'd recommend checking out runt. Pat [1] http://runt.rubyforge.org/ On 1/29/06, Valerij KIR wrote: > Hi all! I'm writing program some days ago which calculates every > Thursday day in interval given by 2 Time values and see interesting > result described later. Is it my or ruby bug? > > Result > ------- > > Thu Sep 01 00:00:00 MSD 2005 > Thu Sep 08 00:00:00 MSD 2005 > Thu Sep 15 00:00:00 MSD 2005 > Thu Sep 22 00:00:00 MSD 2005 > Thu Sep 29 00:00:00 MSD 2005 > Thu Oct 06 00:00:00 MSD 2005 > Thu Oct 13 00:00:00 MSD 2005 > Thu Oct 20 00:00:00 MSD 2005 > Thu Oct 27 00:00:00 MSD 2005 > Wed Nov 02 23:00:00 MSK 2005 > Wed Nov 09 23:00:00 MSK 2005 > Wed Nov 16 23:00:00 MSK 2005 > Wed Nov 23 23:00:00 MSK 2005 > Wed Nov 30 23:00:00 MSK 2005 > Wed Dec 07 23:00:00 MSK 2005 > > Code > ----- > > t1 = Time.mktime(2005, 9, 1) > t2 = Time.mktime(2005, 12, 11) > while t1.to_i < t2.to_i > p t1 > t1 += 3600*24*7 > end > > > -- > Posted via http://www.ruby-forum.com/. > >