on master help sign in
Support time zones of the form +HH, with minutes omitted
cb78f1eBryan O'Sullivan
Data/Aeson/Parser/Time.hs+6−2
@@ -99,7 +99,11 @@ timeZone = do
99 then return Nothing
99 then return Nothing
100 else do
100 else do
101 h <- twoDigits
101 h <- twoDigits
102+ mm <- peekChar
103+ m <- case mm of
102− m <- maybeSkip ':' *> twoDigits
104+ Just ':' -> anyChar *> twoDigits
105+ Just d | isDigit d -> twoDigits
106+ _ -> return 0
103 let off | ch == '-' = negate off0
107 let off | ch == '-' = negate off0
104 | otherwise = off0
108 | otherwise = off0
105 off0 = h * 60 + m
109 off0 = h * 60 + m
@@ -138,7 +142,7 @@ utcTime = do
138-- optional. The @Z@ represents UTC. The @Z@ may be replaced with a
142-- optional. The @Z@ represents UTC. The @Z@ may be replaced with a
139-- time zone offset of the form @+0000@ or @-08:00@, where the first
143-- time zone offset of the form @+0000@ or @-08:00@, where the first
140-- two digits are hours, the @:@ is optional and the second two digits
144-- two digits are hours, the @:@ is optional and the second two digits
141−-- are minutes.
145+-- (also optional) are minutes.
142zonedTime :: Parser Local.ZonedTime
146zonedTime :: Parser Local.ZonedTime
143zonedTime = Local.ZonedTime <$> localTime <*> (fromMaybe utc <$> timeZone)
147zonedTime = Local.ZonedTime <$> localTime <*> (fromMaybe utc <$> timeZone)
144
148
tests/UnitTests.hs+5−4
@@ -102,11 +102,12 @@ utcTimeGood = do
102 assertEqual "utctime" (parseWithRead "%FT%T%QZ" ts2) t2
102 assertEqual "utctime" (parseWithRead "%FT%T%QZ" ts2) t2
103 assertEqual "utctime" (parseWithRead "%F %T%QZ" ts3) t3
103 assertEqual "utctime" (parseWithRead "%F %T%QZ" ts3) t3
104 assertEqual "utctime" (parseWithRead "%F %T%QZ" ts4) t4
104 assertEqual "utctime" (parseWithRead "%F %T%QZ" ts4) t4
105− -- timezones. Both +HHMM and +HH:MM are allowed for timezone offset
105+ -- Time zones. Both +HHMM and +HH:MM are allowed for timezone
106+ -- offset, and MM may be omitted.
106− let ts5 = "2015-01-01T12:30:00.00+0000" :: LT.Text
107+ let ts5 = "2015-01-01T12:30:00.00+00" :: LT.Text
107 let ts6 = "2015-01-01T12:30:00.00+01:15" :: LT.Text
108 let ts6 = "2015-01-01T12:30:00.00+01:15" :: LT.Text
108− let ts7 = "2015-01-01T12:30:00.00-0200" :: LT.Text
109+ let ts7 = "2015-01-01T12:30:00.00-02" :: LT.Text
109− let ts8 = "2015-01-01T22:00:00.00-03:00" :: LT.Text
110+ let ts8 = "2015-01-01T22:00:00.00-03" :: LT.Text
110 let ts9 = "2015-01-01T22:00:00.00-04:30" :: LT.Text
111 let ts9 = "2015-01-01T22:00:00.00-04:30" :: LT.Text
111 let (Just (t5 :: UTCTime)) = parseWithAeson ts5
112 let (Just (t5 :: UTCTime)) = parseWithAeson ts5
112 let (Just (t6 :: UTCTime)) = parseWithAeson ts6
113 let (Just (t6 :: UTCTime)) = parseWithAeson ts6