DateTime#to_f and Time#to_f inconsistency


I found this different behaviour for DateTime#to_f and Time#to_f.

DateTime#to_f strips decimal part but Time#to_f doesn’t.

DateTime#to_f method is implemented in ActiveSupport and Time#to_f is native conversion method.

failing test:

I found this in mongoid pending test (

It was marked as pending in change from 3.2 to 4.0 rails. So it’ regression maybe. But I tried 3.2, 3.1, 3.0 and 2.3 in console quickly and it behaved same as now. So I’m not sure about this.

Anyway ping me if you think any patch is needed for this and I’ll do my best to provide it.


Josef Šimánek

The only related commit that I could find was

Andrew, could you take a look?

Sorry guys, Mongoid is using own kind of magic for this ( and it looks it doesn’t work with rails 4. So it is not regression in DateTime anyway.

But the question remains. Is this expected behaviour to strip decimal part for to_float conversion of DateTime?