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

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: http://www.haskell.org/~simonmar/time/NewTime.html and a prototype implemention here: http://www.haskell.org/~simonmar/time/NewTime.hsc 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(). Cheers, Simon

On Fri, Jan 21, 2005 at 02:55:31PM -0000, Simon Marlow wrote:
Have you seen this, BTW:
Ah. I think I found several discussions in reply to that but never did actually track down that URL. I'll take a look.
timelocal :: CalendarTime -> IO Integer
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:
I did it as it was because the standard defined ClockTime to be opaque. Obviously it's not in fptools, so your way is fine there. But the method of getting seconds out of it should be documented, or a simple function could be added: -- | Convert a ClockTime to a POSIX seconds-since-epoch representation. clockTimeToEpochTime :: ClockTime -> Integer clockTimeToEpochTime (TOD x _) = x
-- | 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().
That would be fine too (you might also note that ctIsDST is ignored). -- John
participants (2)
-
John Goerzen
-
Simon Marlow