[ANN] UTCDates.jl

I’d like to announce a new package called UTCDates for calculating the intervals between UTC dates, including proper handling of leap seconds.

From the readme:

Here’s an example of finding the elapsed time between two UTC dates:

using UTCDates
new_years_eve_morning = UTCDate(2016, 12, 31, 0, 0, 0.)
new_years_day = UTCDate(2017, 1, 1, 0, 0, 0.)
seconds_between_those_dates = new_years_day - new_years_eve_morning

This returns 86,401s, and that is the correct number of SI seconds between those two UTC dates. See below for more about where that extra 1 comes from.

Here’s an example of finding the UTC date that happened a certain number of elapsed seconds after a given UTC date:

gps_epoch = UTCDate(1980, 1, 6, 0, 0, 0.)
number_of_elapsed_seconds = 1454038350. # I just got this from a GPS receiver.
current_utc_date = gps_epoch + number_of_elapsed_seconds

This gives UTCDate(2026, 2, 2, 3, 32, 12.0).

Why Is This Package Useful?

A UTC date (and time) is not a number; it is a unique and unambiguous description of a moment in time, like 2016-12-31T23:59:60.500Z. That’s a perfectly valid UTC date, because the very last minute of December 31st of 2016 had 61s in it. That added second is called a “leap second”. We need (or at least, UTC uses) leap seconds because the earth doesn’t have a perfectly predictable rotation rate. When it’s been going too slow or too fast for a little while, the International Earth Rotation Service decides to add or remove a leap second so that the sun is directly over the Greenwich meridian at the time called 12:00pm, in an averaged sense, plus or minus 0.9s. So, to determine how many SI seconds are between two UTC dates, you just have to add up how many SI seconds are in each minute between the two dates. The overwhelming majority of those minutes will have 60 SI seconds, but some will have 61s, and it’s theoretically possible that some will have 59s (a “negative leap second”, which has never actually happened). This package makes such calculations easy.

If this is interesting to you, please see the readme for more.

2 Likes