[Haskell-cafe] Re: TimeDiff to Int?

Lyle Kopnicky lists at qseep.net
Thu Nov 13 21:17:57 EST 2008


Thanks, but that doesn't seem to work. I got an answer of -3. I tried it
again a minute later and it was still -3. I tried again a minute later and
it was -1. It's just after 9am here, so I have no idea what to make of those
numbers.

I have settled on this code:

secondsSinceMidnight :: IO Int
secondsSinceMidnight = do
  zonedTime <- getZonedTime
  return $ floor $ toRational $ timeOfDayToTime $ localTimeOfDay $
zonedTimeToLocalTime zonedTime

On Thu, Nov 13, 2008 at 2:29 AM, Jon Fairbairn
<jon.fairbairn at cl.cam.ac.uk>wrote:

> "Lyle Kopnicky" <lists at qseep.net> writes:
>
> > I had some code using the oldtime package, and want to convert it to use
> > the time package.
> > One of the things I need to do is calculate the number of seconds since
> > midnight. The easy part is getting a TimeDiff result:
>
> You mean DiffTime?
>
> > utc <- getCurrentTime
> > tz <- getCurrentTimeZone
> > let td = timeOfDayToTime $ localTimeOfDay $ utcToLocalTime tz utc
> > Now td is a TimeDiff representation of the number of seconds since
> > midnight. It prints nicely, but I'm having a heck of a time figuring out
> > how to truncate it to an Int.
>
> You could do something like
> fromEnum td `div` fromEnum (secondsToDiffTime 1)
> which says that you are computing a whole number of seconds.
>
> --
> Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk
> http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html  (updated 2008-04-26)
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20081113/0e8fa61b/attachment.htm


More information about the Haskell-Cafe mailing list