on master help sign in
Fix JSON instance for UTCTime

This fixes gh-158.

commitf06ed8988b516983cb63102342189d79dc130984 authorBryan O'Sullivan <bos@serpentine.com> dateMon 18 Nov 2013, 22:25 (13 years ago) parentbc91655
1 file changed+5−2
Data/Aeson/Types/Instances.hs+5−2
Data/Aeson/Types/Instances.hs+5−2
@@ -499,8 +499,11 @@ instance FromJSON ZonedTime where
499499 parseJSON v = typeMismatch "ZonedTime" v
500500
501501instance ToJSON UTCTime where
502− toJSON t = String (pack (take 23 str ++ "Z"))
503− where str = formatTime defaultTimeLocale "%FT%T%Q" t
502+ toJSON t = String (pack (str ++ z : "Z"))
503+ where (str,(x:y:_)) = splitAt 22 $
504+ formatTime defaultTimeLocale "%FT%T.%q" t
505+ z | y < '5' = x
506+ | otherwise = succ x
504507 {-# INLINE toJSON #-}
505508
506509instance FromJSON UTCTime where