on master help sign in
Add BCE day support
commit553bb7b2107caf399a65d28b2a377278596ed7b4 authorMatt Parsons <parsonsmatt@gmail.com> dateSun 11 Dec 2016, 12:17 (10 years ago) parentc149038
1 file changed+7−6
Data/Aeson/Encoding/Builder.hs+7−6
Data/Aeson/Encoding/Builder.hs+7−6
@@ -193,12 +193,13 @@ day dd = encodeYear yr <>
193193 !(T dh dl) = twoDigits d
194194 encodeYear y
195195 | y >= 1000 = B.integerDec y
196− | y > 0 =
197− let (ab,c) = fromIntegral y `quotRem` 10
198− (a,b) = ab `quotRem` 10
199− in BP.primBounded (ascii4 ('0',(digit a,(digit b,digit c)))) ()
200− | otherwise =
201− error "Data.Aeson.Encode.Builder.day: years BCE not supported"
196+ | y >= 0 = BP.primBounded (ascii4 (padYear y)) ()
197+ | y >= -999 = BP.primBounded (ascii5 ('-',padYear y)) ()
198+ | otherwise = B.integerDec y
199+ padYear y =
200+ let (ab,c) = fromIntegral y `quotRem` 10
201+ (a,b) = ab `quotRem` 10
202+ in ('0',(digit a,(digit b,digit c)))
202203{-# INLINE day #-}
203204
204205timeOfDay :: TimeOfDay -> Builder