D. J. Bernstein
Time

libtai

libtai is discussed on the libtai mailing list.

The latest published libtai package is libtai-0.60.tar.gz.

The leap-second table was updated for leap seconds on 1998-12-31, 2005-12-31, 2008-12-31, and 2012-06-30. There were no leap seconds on the following dates: 1999-06-30, 1999-12-31, 2000-06-30, 2000-12-31, 2001-06-30, 2001-12-31, 2002-06-30, 2002-12-31, 2003-06-30, 2003-12-31, 2004-06-30, 2004-12-31, 2005-06-30, 2006-06-30, 2006-12-31, 2007-06-30, 2007-12-31, 2008-06-30, 2009-06-30, 2009-12-31, 2010-06-30, 2010-12-31, 2011-06-30, 2011-12-31.

Related package: clockspeed, which compensates for a persistently fast or slow system clock.

What is it?

libtai is a library for storing and manipulating dates and times.

libtai 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. Both scales are defined in terms of TAI, the current international real time standard.

libtai provides an internal format for TAI64, struct tai, designed for fast time manipulations. The tai_pack() and tai_unpack() routines convert between struct tai and a portable 8-byte TAI64 storage format. libtai provides similar internal and external formats for TAI64NA.

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

libtai provides struct caltime to store calendar dates and times along with UTC offsets. It can convert from struct tai to struct caltime in UTC, accounting for leap seconds, for accurate date and time display. It can also convert back from struct caltime to struct tai for user input. Its overall UTC-to-TAI conversion speed is 100x better than the usual UNIX mktime() implementation.

This version of libtai requires a UNIX system with gettimeofday(). It will be easy to port to other operating systems with compilers supporting 64-bit arithmetic.

The libtai source code is in the public domain.