[Haskell-cafe] Can't do basic time operations with System.Time

Simon Marlow simonmar at microsoft.com
Fri Jan 21 09:55:31 EST 2005

On 21 January 2005 14:31, John Goerzen wrote:

> I checked the following code into MissingH.  I would be pleased if you
> could take it for fptools.  I should note that I am using an Integer
> rather than an Int to represent seconds, since I think that is proper
> given the size of values we might be encountering.  If you do take it
> for fptools, you could probably rewrite normalizeTimeDiff to use the
> very similar code in timeDiffToSecs (shameless almost-stealing here
> <g>)

Have you seen this, BTW:


and a prototype implemention here:


Everything to do with TimeDiff in the current library is generally
acknowledged to be broken, so I don't think we'll be doing anything with
that, short of completely replacing it.  See previous discussions (if
you have a lot of free time...).

> timelocal :: CalendarTime -> IO Integer
> timelocal ct =
>     do guessct <- toCalendarTime guesscl
>        let newct = ct {ctTZ = ctTZ guessct}
>        return $ timegm newct
>     where guesscl = toClockTime ct

This looks useful, given that it was what you wanted and it isn't
already provided.  I'd prefer to drop it into the existing library, and
have it return a ClockTime, though.  Perhaps:

  -- | converts the given CalendarTime into a ClockTime,
  -- ignoring the ctTZ field of CalendarTime and instead 
  -- using the prevailing local timezone (including daylight
  -- savings adjustments) at the given time.
  localTimeToClockTime :: CalendarTime -> IO ClockTime

that's more or less a direct interface to mktime().


More information about the Haskell-Cafe mailing list