Commits

Anonymous committed 381a4e1

toJSON for ZonedTime limits the milliseconds to three digits

  • Participants
  • Parent commits d007962

Comments (0)

Files changed (1)

File Data/Aeson/Types/Class.hs

 deriving instance Eq ZonedTime
 
 instance ToJSON ZonedTime where
-  toJSON t = String $ pack $ formattedTime
+  toJSON t = String $ pack $ formatTime defaultTimeLocale format t
     where
-      formattedTime
-        | 0 == timeZoneMinutes (zonedTimeZone t) =
-          formatTime defaultTimeLocale "%FT%T%QZ" t
-        | otherwise =
-          formatTime defaultTimeLocale "%FT%T%Q%z" t
+      format = "%FT%T" ++ milliseconds ++ tzFormat
+      milliseconds = take 4 $ formatTime defaultTimeLocale "%Q" t
+      tzFormat
+        | 0 == timeZoneMinutes (zonedTimeZone t) = "Z"
+        | otherwise = "%z"
 
 instance FromJSON ZonedTime where
   parseJSON (String t) =