Time Library Organisation
simonmar at microsoft.com
Thu Jan 27 12:17:37 EST 2005
On 27 January 2005 17:06, Daan Leijen wrote:
> Marcin 'Qrczak' Kowalczyk wrote:
>> You can't have gettimeofday() returning UTC and libtai returning TAI
>> at the same time, because they return the same thing. This is the
>> implementation from libtai:
>> DJB (the author of libtai) disagrees with POSIX about what
>> gettimeofday should return, and assumes that it actually returns
>> what he wishes it returned.
> Wow, that is terrible! Well, we can not fix libraries. If libtai is
> that broken, we can just as well do it ourselves:
That's pretty much the conclusion I came to when I looked at libtai for
implementing my library.
> if we assume that
> we can convert a current UTC time to TAI, we can calculate the TAI
> time at the start of the program and use time_t to keep track of the
> TAI delta -- here we take advantage of the time_t bug which is not
> adjusted for leap seconds!
You can't assume that time_t is not being adjusted for leap seconds: the
host might be running NTP, for example. The best thing to do seems to
be to assume that time_t is a count of seconds since the epoch minus
leap seconds, and calculate TAI from that. It might be wrong by up to a
second around a leap second on a host running NTP, and slightly more
wrong on a host not running NTP, but the latter probably don't care too
much about second-accuracy anyway.
More information about the Libraries