in Hacking

“2008-03-30”.to_date.to_time.tomorrow == “2008-03-30”

I wrote a very nice routine which would iterate over a few days.
Today I found my loop never ending !?! And this is very scary because the routine is a background process that needs to iterate over the last x-days.

But there’s a problem when you’re living in The Netherlands and you have to use daylight savings.

Try this code:

>> "2008-03-30".to_date.to_time.tomorrow.to_date
=> Sun Mar 30

WTF !! 2008-03-30 => Tomorrow => 30 March 2008 ?!?

I indeed complained, that time was passing so quickly. But I didn’t mean to keep it stuck at 30 March!
Oh.. I’ts only my Rails Application…

How’s this possible?

>> "2008-03-30".to_date.to_time.tomorrow
=> Sun Mar 30 23:00:00 +0200 2008

At 30-03-2008 the clock has been set back for daylight savings. Well I assume rails simply adds 24 hours with the method tomorrow. And yesterday we had 25 hours.

More info about this bug:

My temporary solution is to add some hours to tomorrow.

>> tomorrow_time = "2008-03-30".to_date.to_time.tomorrow + 12*60*60
=> Mon Mar 31 11:00:00 +0200 2008
>> tomorrow_time.to_date
=> Mon, 31 Mar 2008

Sometimes I hate Ruby on Rails!

why don’t we collectively protest agianst the oppression of daylight saving time?
Well Tijn, I agree!