git.iko.soy/typeable/postgresql-simple
on master help sign in
Time Parser Tweaks
commit81bf589a0f7de6e4d518f7c73a6ee3fecef24839 authorLeon P Smith <leon@melding-monads.com> dateThu 17 Sep 2015, 22:44 (11 years ago) parent50e5bd6
1 file changed+6−9
src/Database/PostgreSQL/Simple/Time/Parser.hs+6−9
src/Database/PostgreSQL/Simple/Time/Parser.hs+6−9
@@ -63,8 +63,6 @@ timeOfDay = do
6363 then return (Local.TimeOfDay h m s)
6464 else fail "invalid time"
6565
66−data T = T {-# UNPACK #-} !Int {-# UNPACK #-} !Int64
67−
6866-- | Parse a count of seconds, with the integer part being two digits
6967-- long.
7068seconds :: Parser Pico
@@ -78,16 +76,15 @@ seconds = do
7876 _ -> return $! fromIntegral real
7977 where
8078 parsePicos a0 t = toPico (fromIntegral (t' * 10^n))
81− where T n t' = B8.foldl' step (T 12 (fromIntegral a0)) t
82− step ma@(T m a) c
83− | m <= 0 = ma
84− | otherwise = T (m-1) (10 * a + fromIntegral (ord c) .&. 15)
79+ where n = 12 - B8.length t
80+ t' = B8.foldl' (\a c -> 10 * a + fromIntegral (ord c) .&. 15) a0
81+ (B8.take 12 t)
8582
8683-- | Parse a time zone, and return 'Nothing' if the offset from UTC is
8784-- zero. (This makes some speedups possible.)
8885timeZone :: Parser (Maybe Local.TimeZone)
8986timeZone = do
90− ch <- satisfy $ \c -> c == 'Z' || c == '+' || c == '-'
87+ ch <- satisfy $ \c -> c == '+' || c == '-' || c == 'Z'
9188 if ch == 'Z'
9289 then return Nothing
9390 else do
@@ -114,7 +111,7 @@ data UTCOffsetHMS = UTCOffsetHMS {-# UNPACK #-} !Int {-# UNPACK #-} !Int {-# UNP
114111-- zero. (This makes some speedups possible.)
115112timeZoneHMS :: Parser (Maybe UTCOffsetHMS)
116113timeZoneHMS = do
117− ch <- satisfy $ \c -> c == 'Z' || c == '+' || c == '-'
114+ ch <- satisfy $ \c -> c == '+' || c == '-' || c == 'Z'
118115 if ch == 'Z'
119116 then return Nothing
120117 else do
@@ -163,7 +160,7 @@ localToUTCTimeOfDayHMS (UTCOffsetHMS dh dm ds) (Local.TimeOfDay h m s) =
163160-- followed by a fractional component.
164161localTime :: Parser Local.LocalTime
165162localTime = Local.LocalTime <$> day <* daySep <*> timeOfDay
166− where daySep = satisfy (\c -> c == 'T' || c == ' ')
163+ where daySep = satisfy (\c -> c == ' ' || c == 'T')
167164
168165-- | Behaves as 'zonedTime', but converts any time zone offset into a
169166-- UTC time.