RFC: Time Library 0.1

John Meacham john at repetae.net
Wed Jul 6 18:03:45 EDT 2005

On Wed, Jul 06, 2005 at 01:38:12AM -0700, Ashley Yakeley wrote:
> In article <20050705230703.GA26379 at momenergy.repetae.net>,
>  John Meacham <john at repetae.net> wrote:
> > It needs a 
> > getTAItime :: IO AbsoluteTime
> > and  a 
> > getLeapSecondTable :: IO LeapSecondTable 
> > 
> > Many systems have ways to get at these and it would be a travesty if we
> > didn't fix this hole in the API when we have the chance. As always, the
> > library should make its best effort to get at this info.
> ...
> How do I implement these?

I was thinking for the initial implementation

getTAITime = do
        lst <- getLeapSecondTable 
        t <- getCurrentTime
        return (utcToTAITime lst t)

getLeapSecondTable = do
        -- check for /etc/leapseconds.txt
        -- return contents of file if it exists
        -- else, return built in table. 

This will make it very straightforward for anyone to get accurate TAI
times by adding a one-liner to their crontab to grab the leapsecondtable
from NIST at least once every few months.

Of course, getLeapSecondTable and getTAITime will be modified to use any
local interfaces available or when POSIX eventually specifies some TAI
interface functions. 

> > Also, it would be nice if the LeapSecondTable was not a functional type,
> > but rather something with structure, like a list of (year,offset) pairs.
> > There could be apps that will have to look at which years the leap
> > seconds actually occured in and probing the function with every possible
> > value in its domain is not very fun.
> That's a good question. I used a function because that's the "least" 
> type necessary to do the conversions, at the same time allowing 
> estimates extending infinitely into the future (and past, if we want 
> "proleptic UTC"). A list of pairs would have to be walked through, in 
> effect converted to the function type.

> > Also, shouldn't AbsoluteTime be an instance of several Num classes? 
> No, I don't think any Num functions apply. There's no "zero time" and 
> you can't meaningfully add 3am today to 7pm tomorrow.

But the beauty of TAI is that interval and absolute times are on the
same scale. I would argue that it is the one type where arithmetic
actually makes sense. you can subtract two dates and get an absolute
measure of the time difference between them. or add two dates and get
the sum of their offsets from 1970. (there is a zero time, the TAI
epoch). Even division and multiplication make sense (but the
dimensionalities are a little more iffy with them, so I'd convert to
integers first, however the math is sound). 

For TAI, you don't need separate Difference and Absolute types because
in essence, all TAI values are offsets, with an implied endpoint at
1970-1-1 0:0:0.


John Meacham - ⑆repetae.net⑆john⑈ 

More information about the Libraries mailing list