on master help sign in
Support time zones of the form +HH, with minutes omitted

This finishes off the cherry-picking of gh-270. I think.

commitcb78f1e89f440938fd63943119de8f491e1edcd4 authorBryan O'Sullivan <bos@serpentine.com> dateTue 21 Jul 2015, 00:23 (11 years ago) parenta9dd446
2 files changed+11−6
Data/Aeson/Parser/Time.hs+6−2 tests/UnitTests.hs+5−4
Data/Aeson/Parser/Time.hs+6−2
@@ -99,7 +99,11 @@ timeZone = do
9999 then return Nothing
100100 else do
101101 h <- twoDigits
102− m <- maybeSkip ':' *> twoDigits
102+ mm <- peekChar
103+ m <- case mm of
104+ Just ':' -> anyChar *> twoDigits
105+ Just d | isDigit d -> twoDigits
106+ _ -> return 0
103107 let off | ch == '-' = negate off0
104108 | otherwise = off0
105109 off0 = h * 60 + m
@@ -138,7 +142,7 @@ utcTime = do
138142-- optional. The @Z@ represents UTC. The @Z@ may be replaced with a
139143-- time zone offset of the form @+0000@ or @-08:00@, where the first
140144-- two digits are hours, the @:@ is optional and the second two digits
141−-- are minutes.
145+-- (also optional) are minutes.
142146zonedTime :: Parser Local.ZonedTime
143147zonedTime = Local.ZonedTime <$> localTime <*> (fromMaybe utc <$> timeZone)
144148
tests/UnitTests.hs+5−4
@@ -102,11 +102,12 @@ utcTimeGood = do
102102 assertEqual "utctime" (parseWithRead "%FT%T%QZ" ts2) t2
103103 assertEqual "utctime" (parseWithRead "%F %T%QZ" ts3) t3
104104 assertEqual "utctime" (parseWithRead "%F %T%QZ" ts4) t4
105− -- timezones. Both +HHMM and +HH:MM are allowed for timezone offset
106− let ts5 = "2015-01-01T12:30:00.00+0000" :: LT.Text
105+ -- Time zones. Both +HHMM and +HH:MM are allowed for timezone
106+ -- offset, and MM may be omitted.
107+ let ts5 = "2015-01-01T12:30:00.00+00" :: LT.Text
107108 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 ts8 = "2015-01-01T22:00:00.00-03:00" :: LT.Text
109+ let ts7 = "2015-01-01T12:30:00.00-02" :: LT.Text
110+ let ts8 = "2015-01-01T22:00:00.00-03" :: LT.Text
110111 let ts9 = "2015-01-01T22:00:00.00-04:30" :: LT.Text
111112 let (Just (t5 :: UTCTime)) = parseWithAeson ts5
112113 let (Just (t6 :: UTCTime)) = parseWithAeson ts6