@@ -1,4 +1,4 @@
1−{-# LANGUAGE CPP #-}
1+{-# LANGUAGE CPP, ScopedTypeVariables #-}
22
33module Data.Aeson.Parser.Time
44 (
@@ -13,6 +13,8 @@ import Control.Applicative ((<$>), (<|>), empty)
1313import Control.Monad (when, void)
1414import qualified Data.Aeson.Types.Internal as Aeson
1515import Data.Attoparsec.Text as A
16+import Data.Char (isDigit)
17+import Data.Fixed (Pico)
1618import Data.Text (Text)
1719import Data.Time.Calendar (Day, fromGregorianValid)
1820import Data.Time.Clock (UTCTime)
@@ -41,6 +43,19 @@ timeOfDay = do
4143 s <- (fromRational . toRational) <$> double
4244 maybe (fail "invalid time") return (Local.makeTimeOfDayValid h m s)
4345
46+pico :: A.Parser Pico
47+pico = do
48+ (w :: Int) <- decimal
49+ mc <- peekChar
50+ case mc of
51+ Just '.' -> do
52+ fs <- A.takeWhile isDigit
53+ let e = negate (T.length (T.takeWhile (=='0') fs)) - 1
54+ case T.decimal fs of
55+ Right (f :: Int, _) -> return (fromIntegral w + fromIntegral f * 10 ^ e)
56+ _ -> fail "invalid number"
57+ _ -> fail "invalid number"
58+
4459timeZone :: A.Parser Local.TimeZone
4560timeZone = do
4661 skipSpace