Time library discussion (reprise)

Ketil Malde ketil+haskell at ii.uib.no
Wed Nov 12 13:22:58 EST 2003


"Simon Marlow" <simonmar at microsoft.com> writes:

> -- | A representation of absolute time, measured as picoseconds since
> --   the epoch, where the epoch is 1 January 1970 00:10 TAI.
> data ClockTime -- abstract
>   instance of (Eq, Ord, Num, Enum, Integral, Show, Read)
> 
> -- | returns the current absolute time
> getClockTime :: IO ClockTime

The advantage (what I tried to say in my previous message) is that
something like

        t1 <- getClockTime
        :
        t2 <- getClockTime
        print ("Elapsed time: "++ show (t2-t1)++" seconds")

would work correctly, and not just work "most of the time", like it
would with UTC.

> data Timezone -- abstract

> -- | Make a 'Timezone' from an offset, in seconds relative to UTC,
> -- which must be smaller in magnitude than @+/-12*60*60 at .
> timezoneFromUTCOffset :: Int -> Timezone

Don't you also need a specific time?  We have UTC+0100 in the winter,
but +0200 in summer (or was it the other way around? :-)

Perhaps we should separate between Timezones (the TLAs) and their
offsets.  We could have a

        localTime :: Timezone -> ClockTime -> CalendarTime 

and make the offset, but not TZ, a part of CalendarTime.  Would it
then make (more) sense to compare CalendarTimes?  At least it wouldn't
need to involve timezone tables.

        data Timezone = UTC | GMT | PDT ... deriving ...
        
        data TZOffset = -- abstract (or just an Int)
        instance Num TZOffset -- auto conversion from int, etc
        tzToOffset :: Timezone -> TZOffset

>  TODO: add isDSTCalendarTime? (returns True if the specified
>  CalendarTime is in daylight savings).  How do we say "what's the
>  current timezone in X", taking into account DST?

Exactly.

>    - Need to define the meaning when the offset doesn't exist.
>      eg. adding a day at the end of the month clearly rolls over
>      into the next month.  But what about adding a month to
>      January 31st?

Perhaps it would be possible to have a more flexible system, where one
could specify things like the last day of the month, the second
Wednesday every second month, and so on?  Not sure how it would look,
though. 

-kzm
-- 
If I haven't seen further, it is by standing in the footprints of giants


More information about the Libraries mailing list