Across all languages, what are the best libraries, with least amount if pitfalls?
(java.time seems good, anything even better elsewhere?)
(java.time seems good, anything even better elsewhere?)
jshell> ChronoUnit.SECONDS.between(Instant.parse("1974-01-01T00:00:00Z"), Instant.parse("2024-01-01T00:00:00Z")) % 86400
$22 ==> 0
astropy gets you the correct answer: >>> from astropy.time import Time
>>> (Time('2024-01-01T00:00:00Z') - Time('1974-01-01T00:00:00Z')).sec % 86400
24.0
of course astropy is bit specialized and not really something I'd use as general purpose date/time library. But this is one good litmus test for datetimes, feel free to try it with your favorites. >>> from whenever import UTCDateTime
>>> (UTCDateTime(2024, 1, 1) - UTCDateTime(1974, 1, 1)).total_seconds() % 86400
0.0(I’m voting for not being afraid of curse words; if they are relevant)
This is a conscious decision, I'll explicitly address this in the FAQ soon.
As I commented elsewhere, this is completely in line with industry standards (iCal, Unix time) and other modern libraries. I don't (yet) see any reason to deviate.
Unix time ignores leap seconds, so does RFC 5545 (iCal), and most modern libraries (Chrono, Temporal, NodaTime).
>>> UTCDateTime.from_rfc3339('1998-12-31T23:59:60Z')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/tmp/tmp.4kBsq6IYyF/venv/lib/python3.11/site-packages/whenever/__init__.py", line 797, in from_rfc3339
return cls._from_py_unchecked(_parse_utc_rfc3339(s))
^^^^^^^^^^^^^^^^^^^^^
File "/tmp/tmp.4kBsq6IYyF/venv/lib/python3.11/site-packages/whenever/__init__.py", line 2420, in _parse_utc_rfc3339
return _fromisoformat(s.upper())
^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: second must be in 0..59Probably the approach of Chrono is best: allow leap seconds to be represented (i.e. 23:59:60), but not to account for them historically.