An article about Javascript’s upcoming Temporal API for working with dates and times is trending on Hacker News today. I was curious how it compared with Julia, so I used a small Pluto notebook to test things out and write down my thoughts. The text remarks from the notebook are:
- There doesn’t seem to be a way to work with the Chinese calendar in Julia, not even with external packages. There’s a Calendars.jl from 2022, but it doesn’t have the Chinese (or Indian, or Japanese) calendar.
- The
Millisecond(::Period)
method doesn’t seem to be documented, so it wasn’t at all obvious that dividing byMillisecond(Hour(1))
was the easy way to go from aMillisecond
value to the number ofHour
s in it.- In general, this kind of
Period
conversion is cumbersome, awkward, and error-prone in Julia.
- In general, this kind of
- It’s nice that string interpolation of a period automatically does the right thing, eg. printing “XY hours” when it’s a
Hour
value. But this is hardcoded in the stdlib, so English locale is the only option. - There isn’t a ISO 8601 (locale-independent) duration format implementation in Julia AFAICT. There’s ISO 8601 timestamp format in NanoDates.jl, but not for duration.
- Overall, Julia already implements a large part of the planned Temporal API (either in the stdlib or in TimeZones.jl). Its biggest weaknesses compared to JS Temporal are to do with localization: locale-specific calendars, locale-specific "era"s, locale-specific string outputs.
- But the documentation and the interface in some parts could also do with more polish for ease-of-use.
temporal.jl (8.8 KB)