3 ms·
That StackOverflow answer is wrong. Rails does correctly handle `1.day.ago`, taking into account the number of seconds in a day. `1.day.ago` is a perfect exam
by danielvf 11y ago
That StackOverflow answer is wrong.
Rails does correctly handle `1.day.ago`, taking into account the number of seconds in a day.
`1.day.ago` is a perfect example of what DHH was saying, in that it looks beautiful, but requires a bit of work under the hood. `1.day` creates a duration. This isn't just a number of seconds, but is represented by hash, more like `{:days=>1}`. When it's time to do the actual math, Rails looks at the :days number, and actually moves the day part of the date forwards and backwards.
Source here: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/date/calculations.rb#L113 https://github.com/rails/rails/blob/master/activesupport/lib...