Hacker News new | ask | show | jobs
by gerjomarty 607 days ago
As an aside, if you need to play with datetime objects in Ruby, you almost certainly want to be using the Time library instead of the DateTime library, even though one of them sounds like it fits better.

At the top of the DateTime docs [1]:

> DateTime class is considered deprecated. Use Time class.

The same doc explains when you should use DateTime by using an anecdote about William Shakespeare and Miguel de Cervantes dying on the same day - except they didn't because England and Italy used different calendars at the time. [2]

DateTime is great at dealing with historical pre-1970 dates, otherwise just use Time.

[1]: https://docs.ruby-lang.org/en/3.3/DateTime.html [2]: https://docs.ruby-lang.org/en/3.3/DateTime.html#class-DateTi...

1 comments

Wow, TIL! Thanks for sharing.