on master help sign in
A few minor cleanups
ed30f97Bryan O'Sullivan
Data/Aeson/Parser/Time.hs+16−12
@@ -34,16 +34,21 @@ import Data.Time.Clock (UTCTime(..))
34import qualified Data.Aeson.Types.Internal as Aeson
34import qualified Data.Aeson.Types.Internal as Aeson
35import qualified Data.Text as T
35import qualified Data.Text as T
36import qualified Data.Time.LocalTime as Local
36import qualified Data.Time.LocalTime as Local
37−#if !MIN_VERSION_base(4,7,0)
38−import Unsafe.Coerce
39
37
40−mkPico :: Integer -> Pico
38+#if MIN_VERSION_base(4,7,0)
41−mkPico = unsafeCoerce
39+
42−#else
43import Data.Fixed (Fixed(MkFixed))
40import Data.Fixed (Fixed(MkFixed))
44
41
45mkPico :: Integer -> Pico
42mkPico :: Integer -> Pico
46mkPico = MkFixed
43mkPico = MkFixed
44+
45+#else
46+
47+import Unsafe.Coerce
48+
49+mkPico :: Integer -> Pico
50+mkPico = unsafeCoerce
51+
47#endif
52#endif
48
53
49-- | Run an attoparsec parser as an aeson parser.
54-- | Run an attoparsec parser as an aeson parser.
@@ -91,13 +96,12 @@ seconds = do
91 t <- anyChar *> takeWhile1 isDigit
96 t <- anyChar *> takeWhile1 isDigit
92 return $! parsePicos real t
97 return $! parsePicos real t
93 _ -> return $! fromIntegral real
98 _ -> return $! fromIntegral real
94−
99+ where
95−parsePicos :: Int -> T.Text -> Pico
96−parsePicos a0 t = mkPico (fromIntegral (t' * 10^n))
100+ parsePicos a0 t = mkPico (fromIntegral (t' * 10^n))
97− where T n t' = T.foldl' step (T 12 (fromIntegral a0)) t
101+ where T n t' = T.foldl' step (T 12 (fromIntegral a0)) t
98− step ma@(T m a) c
102+ step ma@(T m a) c
99− | m <= 0 = ma
103+ | m <= 0 = ma
100− | otherwise = T (m-1) (10 * a + fromIntegral (ord c) .&. 15)
104+ | otherwise = T (m-1) (10 * a + fromIntegral (ord c) .&. 15)
101
105
102-- | Parse a time zone, and return 'Nothing' if the offset from UTC is
106-- | Parse a time zone, and return 'Nothing' if the offset from UTC is
103-- zero. (This makes some speedups possible.)
107-- zero. (This makes some speedups possible.)