Re:Ask HN: Did you encounter any leap year bugs today?
by EnigmaticLion on Thursday February 29, 2024 @08:49PM
(#39557589)
We have a rails 6 app, and there's a test that essentially expects time_ago_in_words(1.year.from_now) to return "about 1 year" (as part of a user facing message). The test failed. I thought it's a flaky test but i was able to reproduce it locally. Turns out executing that code on a leap day returns "almost 1 year" instead.
Can test it in rails console if you are interested:
[ Parent
| on HN ]
Re:Ask HN: Did you encounter any leap year bugs today?
by DinaCoder99 on Thursday February 29, 2024 @09:01PM
(#39557670)
> distance_of_time_in_words(Date.new(2025, 2, 28), Date.new(2024, 2, 28))
Curiously, this is also not quite a year, even though the days and months are the same.
Re:Ask HN: Did you encounter any leap year bugs today?
by mr_toad on Thursday February 29, 2024 @09:17PM
(#39557788)
It’s probably comparing the number of days between the dates with the number of days in a year, which would usually work.
Re:Ask HN: Did you encounter any leap year bugs today?
by EnigmaticLion on Friday March 01, 2024 @01:58AM
(#39559298)
Source is a lot more complicated than i thought it will be: https://github.com/rails/rails/blob/v6.1.7.7/actionview/lib/...