Commits

larskuhtz committed 963ab5a

Fix JSON instance for UTCTime to yield a valid ISO8601 string

The value truncated to milliseconds by rounding down

Comments (0)

Files changed (1)

Data/Aeson/Types/Instances.hs

     parseJSON v = typeMismatch "ZonedTime" v
 
 instance ToJSON UTCTime where
-    toJSON t = String (pack (str ++ z : "Z"))
-      where (str,(x:y:_)) = splitAt 22 $
-                            formatTime defaultTimeLocale "%FT%T.%q" t
-            z | y < '5'   = x
-              | otherwise = succ x
+    toJSON t = String (pack (take 23 str ++ "Z"))
+      where str = formatTime defaultTimeLocale "%FT%T.%q" t
     {-# INLINE toJSON #-}
 
 instance FromJSON UTCTime where