[erlang-questions] Storing and manipulating TAI dates and times in Erlang

Alfonso De Gregorio adg@REDACTED
Sun Oct 23 12:17:07 CEST 2011

For a project, I was looking for a way to easily store and manipulate
dates and times, defined in terms of TAI, the current international
real time standard. Time references build on TAI are unambiguous and
accurate about moment of time far in the future. Moreover, time
intervals becomes as easy to compute as the distance between two
timestamps -- something the calendar module already provides using
Gregorian seconds.

If the code was to be written in C, I would have opted for libtai.
So, I've decided to answer my need writing an Erlang port of libtai.
I'd like to share it with the list, being the recurrence of storage
and manipulation of dates and times usually high.

        Taider https://github.com/secYOUre/taider

As libtai, Taider supports two time scales: (1) TAI64, covering a few
hundred billion years with 1-second precision; (2) TAI64NA, covering
the same period with 1-attosecond precision.

Taider provides an internal format for TAI64, record tai, designed for
fast time manipulations. The taider_tai:pack() and taider_tai:unpack()
functions convert between record tai and the portable 8-byte TAI64
storage format introduced by libtai. Taider provides similar internal
and external formats for TAI64NA.

Taider provides a record, caldate, to store dates in year-month-day
form. It can convert record caldate, under the Gregorian calendar,
to a modified Julian day number for easy date arithmetic.

Taider provides also a caltime record to store calendar dates and
times along with UTC offsets. It converts from record tai to record
caltime in UTC, accounting for leap seconds, for accurate date and
time display. It also converts back from record caltime to record
tai for user input.

Taider includes 35 test cases and some utility functions:

        1> taider_utils:nowutc().
        "2011-10-23 10:12:55.439471500000000000"

        2> taider_utils:easter(2012).
        "Sun 2012-04-08 yearday 98  mjd 56025"


-- alfonso     blogs at http://Plaintext.crypto.lo.gy   tweets @secYOUre

More information about the erlang-questions mailing list