Concerning Time.TimeDiff

Jon Fairbairn Jon.Fairbairn@cl.cam.ac.uk
Tue, 17 Jun 2003 21:00:15 +0100

```On 2003-06-17 at 13:53BST "Simon Marlow" wrote:
>
> Cheers,
> 	Simon
>
> ------------------------------------------------------------------------
> ----
> -- * ClockTime
>
> -- | A representation of absolute time
> data ClockTime
>   = ClockTime { ctSeconds :: Integer,
>                 ctPicoseconds :: Integer }

Two Integer fields seems strange. Either
ClockTime { ctPicoseconds :: Integer }

would seem to make more sense. I don't see that saving a
divide by 10^12 is a big win.  But being able to represent
times shorter than a picosecond would be.

or
ClockTime { ctSeconds :: Integer, ctPicoseconds:: real }
or, better
ClockTime { ctSeconds :: Ratio Integer }

>   deriving (Eq, Ord, Show, Read)
>
> -- | returns the current absolute time
> getClockTime :: IO ClockTime
>
> -- | Difference between two 'ClockTime's
> data TimeDiff
>   = TimeDiff { tdSeconds :: Integer,
>                tdPicoseconds :: Integer }

ditto. Maybe abstract over intervals so that the innards of
the two types are another type (after all, ClockTime is just
an interval after some instant).

>   deriving (Eq, Ord, Show, Read)
>
> -- | An empty 'TimeDiff'
> noTimeDiff :: TimeDiff
>
> -- | Returns the difference between two 'ClockTime's

> -- * CalendarTime
>
> data CalendarTime
>  = CalendarTime  {
>      ctYear    :: Int,
>      ctMonth   :: Month,
>      ctDay     :: Int,
>      ctHour    :: Int,
>      ctMin     :: Int,
>      ctSec     :: Int,
>      ctPicosec :: Integer,
>      ctTZ      :: Timezone
>  }

again query Integer for picoseconds -- some sort of
fractional value would be better.

> -- | Convert a 'CalendarTime' to a 'ClockTime'
> -- TODO: can this raise an exception if the CalendarTime does not
> -- represent a valid time?  Or should it return Maybe ClockTime?
> calendarTimeToClockTime :: CalendarTime -> ClockTime

I'd vote for Maybe since it's more "functional" than
exceptions.

Jón

--
Jón Fairbairn                                 Jon.Fairbairn@cl.cam.ac.uk