Time Library Organisation

Keean Schupke k.schupke at imperial.ac.uk
Wed Jan 26 06:05:57 EST 2005

Ashley Yakeley wrote:

>>So my vote goes for the unixy way of doing it, with a simple getTime 
>>function that returns milliseconds after the epoch.
Sorry, shouldn't have mentioned unix...

My vote goes for a TAI style time, in milliseconds (64bit resolution, or an
Integer would be even better), with a library to convert this 'absolute' 
into a local date/time... The functions would look a bit like unix ie:

type Time = Word64 -- or Integer
getTime :: IO Time

localtime :: Calendar c => Time -> TimeZone -> c

Calendar is a type dependant on the calendar format, so for the normal
calendar something like:

data MyCalendar = MyCalendar {
    hour :: Int,
    minute :: Int,
    second :: Int,
    dayOfTheWeek :: Int,
    dayOfTheMonth :: Int,
    month :: Int,
    year :: Int }

dateTime = localtime getTime UK :: MyCalendar

Of course, the time in any timezone may depend on the calendar... I suspect
daylight-savings, as it depends on particular dates should only be 
applied to the
normal calendar - and not to alternate calendars...

in effect I think you want something like:

class Calendar c where
    localtime :: Time -> TimeZone -> c

Then each calendar instance can use or ignore the timezone as appropriate.


More information about the Libraries mailing list