[Haskell-cafe] Serializing UTCTimes
Yitzchak Gale
gale at sefer.org
Sat Jan 21 22:29:09 CET 2012
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