Commits

Liyang HU  committed 56e6c01

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.

  • Participants
  • Parent commits 84414f7

Comments (0)

Files changed (1)

File Data/Aeson/Types/Instances.hs

     parseJSON v = typeMismatch "ZonedTime" v
 
 instance ToJSON UTCTime where
-    toJSON t = String (pack (take 23 str ++ "Z"))
-      where str = formatTime defaultTimeLocale "%FT%T.%q" t
+    toJSON t = String $ pack $ formatTime defaultTimeLocale format t
+      where
+        format = "%FT%T." ++ formatMillis t ++ "Z"
     {-# INLINE toJSON #-}
 
 instance FromJSON UTCTime where