Saturday, March 05, 2016

[kochsxfw] Time pair

Encode a date and time as a tuple: the day number of an epoch, and the number of seconds since the start of the day.  The goal is to avoid the confusion of leap seconds most of the time.  If we simply count seconds from the start of an epoch, with some people counting leap seconds and some people not, then the error, the time difference caused by leap seconds, will accumulate.

Fine tune things a bit: count time since the start of the day in units of 1/24854 second (2*17*17*43).  This allows slightly less than 2^31 time units in a day (even including a leap second).  Alternatively 1/16384 (2^14).  Both these fit in a signed 32 bit integer, convenient for doing arithmetic.

Day number encoded as a signed 31 bit integer gives a positive range of 5 million years.  A day number of an epoch already exists, the Julian day number used by astronomers, though it weirdly starts at noon (so a leap second would be added in the middle of a day).

Create code for converting between dates expressed in this format and UTC, and for computing the time difference between two dates.  It will need an accurate list of leap seconds.

Motivation was something a little bit nicer than UTC (which requires 6 different fields) for computers to work with and denote dates in a portable way.  This requires only 2 fields.

No comments :