on master help sign in
Merge pull request #506 from parsonsmatt/matt/0.11.2.1-backport

Backport BCE day encoding fix to 0.11.x

commitb821862b56bab0269c7139f21e3a790f325f9c9b authorAdam Bergmark <adam@bergmark.nl> dateTue 24 Jan 2017, 18:06 (10 years ago) parent4ac64725d584ea
1 file changed+7−6
Data/Aeson/Encode/Builder.hs+7−6
Data/Aeson/Encode/Builder.hs+7−6
@@ -181,12 +181,13 @@ day dd = encodeYear yr <>
181181 !(T dh dl) = twoDigits d
182182 encodeYear y
183183 | y >= 1000 = B.integerDec y
184− | y > 0 =
185− let (ab,c) = fromIntegral y `quotRem` 10
186− (a,b) = ab `quotRem` 10
187− in BP.primBounded (ascii4 ('0',(digit a,(digit b,digit c)))) ()
188− | otherwise =
189− error "Data.Aeson.Encode.Builder.day: years BCE not supported"
184+ | y >= 0 = BP.primBounded (ascii4 (padYear y)) ()
185+ | y >= -999 = BP.primBounded (ascii5 ('-',padYear (- y))) ()
186+ | otherwise = B.integerDec y
187+ padYear y =
188+ let (ab,c) = fromIntegral y `quotRem` 10
189+ (a,b) = ab `quotRem` 10
190+ in ('0',(digit a,(digit b,digit c)))
190191{-# INLINE day #-}
191192
192193timeOfDay :: TimeOfDay -> Builder