Loosing time when using active support time helpers

Time.parse('2009-01-01')+15.days+0.5.days
=> Fri Jan 16 00:00:00 +0100 2009

Time.parse('2009-01-01')+15.days+0.5.days.to_i
=> Fri Jan 16 12:00:00 +0100 2009

12.hours gone :(

ruby version 1.8.7
Advertisements

2 thoughts on “Loosing time when using active support time helpers

  1. I think it would be more expressive to say:

    Time.parse(‘2009-01-01’)+15.days+12.hours

    which works properly. The problem appears to be that 0.5.days returns a Float, whereas 15.days returns a FixNum.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s