Commits

Bryan O'Sullivan committed fe5c7f8

Fix JSON instance for UTCTime

This fixes gh-158.

  • Participants
  • Parent commits e846250

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 (str ++ z : "Z"))
+      where (str,(x:y:_)) = splitAt 22 $
+                            formatTime defaultTimeLocale "%FT%T.%q" t
+            z | y < '5'   = x
+              | otherwise = succ x
     {-# INLINE toJSON #-}
 
 instance FromJSON UTCTime where