Good questions.
Is now()
actually, meaningfully UTC?
With NTP (normally automatically configured and up and running, you never worry about it or touch it) and standard internet connections now()
is UTC (plus TZ offset) accurately to a few tens of msec. If there is a nearby accurate NTP server, like in some university LANs, it can be better, a few msec. Therefore in Julia DateTime a time code with msec resolution is a reasonable choice. It is slightly better than the typical accuracy of now()
. As you mention, NTP warns ahead of leap seconds, and some OS react to this with slowing down and accelerating the system clock near the leap second. At these very rare occasions the error of now()
becomes of course larger, up to about 500 msec. It is also true that the OS normally does not keep tables of leap seconds, but this does not affect the correctness of now()
and comparable functionality in other software. It works anyway, too long to write out why.
In summary, now()
and similar functions in Python, Matlab, MySQL, … normally return a UTC timestamp with an accuracy of at least tens of msec, often better. Practically all timestamps that a software like Julia possibly has to deal with are UTC (including timestamped astronomical data).
How should Julia handle IO with dates that include a 23:59:60
timestamp?
Throwing an error is perhaps not a big issue, as the leap seconds are so rare, and such timestamps often don’t make it to IO to Julia, because other software handling this before also errors. But it could be handled by using internally a day segmented time code (for all times!), e.g.
struct DsTimeCode # day segmented time code, medium resolution
# (can represnt leap second times)
day2000::Int32 # day2000=0 is 2000-01-01
msec::Int32 # milliseconds of day
end
as I had suggested earlier. This allows to accept the ISO8601 string with “60” as the last second of the day, and to store the corresponding binary timestamp. It still is 64 bit in total, and comparing timestamps has very little overhead compared to a single 64 bit counter, etc. Ideally this sort of time code should have been used when UNIX and Windows were designed, but introducing it now in Julia would still have advantages.