[Haskell-cafe] Serializing UTCTimes

Bas van Dijk v.dijk.bas at gmail.com
Sat Jan 21 23:08:45 CET 2012

Thanks Ertugrul and Yitzchak. I failed to notice the Real and
Fractional instances for DiffTime. Thanks very much for pointing me to
it. I dropped the dependency on datetime and implemented your


On 21 January 2012 22:29, Yitzchak Gale <gale at sefer.org> wrote:
> Bas van Dijk wrote:
>> What's the recommended way for serializing (with the cereal package) an UTCTime?
> Serialize the Day part as an Integer using
> toModifiedJulianDay/ModifiedJulianDay,
> (Note that Day is not a constructor, it's just the name of
> the type.)
> Serialize the DiffTime as a Rational, as Ertugrul said.
>> I'm now using the datetime package
> Why? It just obscures the time library.
>> But I will have to look at the code of datetime to see if I'm not
>> losing precision.
> You are losing precision. If you only care
> about time to the nearest second, you can truncate
> the Rational of the DiffTime (don't round, because
> this may be the last second of a day) and then
> use fromIntegral to deserialize.
> Regards,
> Yitz

More information about the Haskell-Cafe mailing list