System.Time.Clock Design Issues

Time turns out to be complicated by nature, and it's not possible to be as simple as we'd like and still be completely correct: there's a trade-off between simplicity and correctness. I lean towards correctness myself, I think there are ways of managing extra complexity. We might, for instance, be able to separate some of the less-used functions into another module fairly sensibly. There's also a trade-off between simplicity and usefulness. My earlier message has one idea of where to draw the line, as well as one way of splitting the functionality: http://www.haskell.org//pipermail/libraries/2005-January/002930.html Simon suggested naming the two modules "System.Time.Clock" and "System.Time.Calendar". These are the issues that seem to be remaining for the "Clock" module: * Can we assume that gettimeofday always returns UTC rather than TAI time? POSIX says yes. People might set it differently, but there doesn't seem to be any way of detecting that. We can't used time-zone setting AFAIK, because gettimeofday is supposed to be universal time independent of time-zone. My preference is to assume people are following the POSIX standard, since that's the assumption that most software makes (including NTP I believe). * Should there be a TAI type separate from a POSIX time type that the system clock would return? My preference is yes. If necessary we could create a third module for TAI time and explicit leap-second handling, which will keep them out of the way for most people. Separate types is more complication, but the alternatives have their own issues: http://www.haskell.org//pipermail/libraries/2005-February/003049.html * What resolution should we use, and should it be platform-dependent? My preference is (platform-independent) picoseconds to match the existing System.Time library and as a hedge against Moore's law. * Should we include a (days,ticks) UTC type separate from the POSIX time type? I have two reasons for wanting this. Firstly, correctness: the POSIX time type cannot represent leap seconds, whereas this can. Secondly, this holds the result of a useful function that splits POSIX time into the simplest possible date and time parts, which can then be used for converting to various internationalised calendars. -- Ashley Yakeley, Seattle WA

Ashley Yakeley wrote:
* Can we assume that gettimeofday always returns UTC rather than TAI time?
POSIX says yes. People might set it differently, but there doesn't seem to be any way of detecting that.
I'd like to mention a technique that doesn't seem to have been suggested yet: we can probe the configuration of the user's system at run time by calling gmtime and friends with preselected arguments. In particular, the value of, say, gmtime(80000000)->tm_sec should suffice to distinguish between the following three cases: * time_t is TAI (atomic seconds since TAI epoch) and gmtime returns UTC (with leap seconds) * time_t is UTC (atomic seconds since UTC epoch) and gmtime returns UTC (with leap seconds) * gmtime is not leap-second aware In the third case I think it's sensible to assume that gmtime returns UTC +/- one second, since gmtime's output (modulo 15 minutes) is what the user will actually see, and if it's off by 20+ seconds, either they'll fix it, or they don't care what second it is and neither need we. From that we can derive an approximate TAI (and seconds-since-UTC-epoch) using an internal table of leap seconds. In the other two cases we can use one more gmtime call to test whether the system's leap-second table is at least as current as ours, and use either the system's or ours depending on that. I don't know if the first case actually occurs in the wild. The second case does occur on Linux systems which link /etc/localtime to something under /usr/share/zoneinfo/right/. Those people clearly care about accurate timekeeping and we should do what we can to cater to them. This site was helpful: http://www.thedjbway.org/clockspeed/leapsecs.html -- Ben

In article <4201AEFA.6070400@cl.cam.ac.uk>,
Ben Rudiak-Gould
* time_t is TAI (atomic seconds since TAI epoch) and gmtime returns UTC (with leap seconds)
* time_t is UTC (atomic seconds since UTC epoch) and gmtime returns UTC (with leap seconds)
I don't understand. What actual number does gmtime return in each case? -- Ashley Yakeley, Seattle WA

Ashley Yakeley wrote:
In article <4201AEFA.6070400@cl.cam.ac.uk>, Ben Rudiak-Gould
wrote: * time_t is TAI (atomic seconds since TAI epoch) and gmtime returns UTC (with leap seconds)
* time_t is UTC (atomic seconds since UTC epoch) and gmtime returns UTC (with leap seconds)
I don't understand. What actual number does gmtime return in each case?
In the second case it returns 1972-07-14 22:13:19, because there's a 86401-second day between then and 1970-01-01 00:00:00 UTC. In the first case I suppose it would return :09, because 1970-01-01 00:00:00 TAI is 10 seconds earlier than 1970-01-01 00:00:00 UTC, and to compensate gmtime would subtract 10 from the value passed in. Like I said I don't know if there are any systems like this. In fact I'm sure there aren't, now that I noticed that the libtai documentation says "This implementation of tai_now assumes that the time_t returned from the time function represents the number of TAI seconds since 1970-01-01 00:00:10 TAI." That :10 at the end is what I hadn't noticed. -- Ben

I would support both of these positions. But I just noticed Simon M's response, and wonder if I'm missing something here: [[ I don't think we need this either, at lesat not in the external interface. Any calculations you can do with this type you can do on a calendar time. ]] Is it proposed that the primary interface include a calendar time (which I take to mean something like (year,month,day,hour,min,sec,subsec)? #g -- At 18:53 02/02/05 -0800, Ashley Yakeley wrote:
* What resolution should we use, and should it be platform-dependent?
My preference is (platform-independent) picoseconds to match the existing System.Time library and as a hedge against Moore's law.
* Should we include a (days,ticks) UTC type separate from the POSIX time type?
I have two reasons for wanting this. Firstly, correctness: the POSIX time type cannot represent leap seconds, whereas this can. Secondly, this holds the result of a useful function that splits POSIX time into the simplest possible date and time parts, which can then be used for converting to various internationalised calendars.
------------ Graham Klyne For email: http://www.ninebynine.org/#Contact

Ashley Yakeley wrote:
Time turns out to be complicated by nature, and it's not possible to be as simple as we'd like and still be completely correct: there's a trade-off between simplicity and correctness.
I lean towards correctness myself, I think there are ways of managing extra complexity. We might, for instance, be able to separate some of the less-used functions into another module fairly sensibly.
There's also a trade-off between simplicity and usefulness. My earlier message has one idea of where to draw the line, as well as one way of splitting the functionality: http://www.haskell.org//pipermail/libraries/2005-January/002930.html
Simon suggested naming the two modules "System.Time.Clock" and "System.Time.Calendar". These are the issues that seem to be remaining for the "Clock" module:
* Can we assume that gettimeofday always returns UTC rather than TAI time?
One question... get timeofday assumes things about the time-system. I would be happier with a 'gettime' call which returns some universal concept of time in an SI unit (which for time is seconds, so microseconds/picoseconds whatever) I am uncomfortable with introducing non SI notions of time interval like hours/minutes (even days) as these may vary... I feel conversion into 'familiar; units should be done from this universal time... Especially if anyone wants to write software for the Mars mission! Keean.

Ashley Yakeley wrote:
In article <4202243A.3070004@imperial.ac.uk>, Keean Schupke
wrote: One question... get timeofday assumes things about the time-system.
gettimeofday just returns POSIX time as a (seconds,microseconds) struct.
But it assumes there is a day... Lunar time for example may have no day... Keean.

Keean Schupke
One question... get timeofday assumes things about the time-system.
gettimeofday just returns POSIX time as a (seconds,microseconds) struct.
But it assumes there is a day... Lunar time for example may have no day...
It doesn't assume anything about a day. Its name is misleading. -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/
participants (5)
-
Ashley Yakeley
-
Ben Rudiak-Gould
-
Graham Klyne
-
Keean Schupke
-
Marcin 'Qrczak' Kowalczyk