Data.Aeson.Types.Instances: fix UTCTime for years outside of [0, 9999]
∙ "take 23" is a dubious way to truncate to millisecond accuracy.
∙ instance ToJSON ZonedTime had it right, so copypasta from it.
commita6e8a3ab4328bb28267fc0e22dbc3a48bbdcad6f
authorLiyang HU <git@liyang.hu>
dateFri 2 May 2014, 10:11 (12 years ago)
parent04ac06c
Data/Aeson/Types/Instances.hs+3−2
@@ -493,8 +493,9 @@ instance FromJSON ZonedTime where
493493 parseJSON v = typeMismatch "ZonedTime" v
494494
495495instance ToJSON UTCTime where
496− toJSON t = String (pack (take 23 str ++ "Z"))
497− where str = formatTime defaultTimeLocale "%FT%T.%q" t
496+ toJSON t = String $ pack $ formatTime defaultTimeLocale format t
497+ where
498+ format = "%FT%T." ++ formatMillis t ++ "Z"
498499 {-# INLINE toJSON #-}
499500
500501instance FromJSON UTCTime where