on master help sign in
"Fix" time truncation in a not-too-heinous way
commit11b83ed483b4d4b427412dfe8a6ec7b3f9c69dbb authorBryan O'Sullivan <bos@serpentine.com> dateTue 21 Jul 2015, 20:31 (11 years ago) parentf412275
1 file changed+6−3
Data/Aeson/Encode/Builder.hs+6−3
Data/Aeson/Encode/Builder.hs+6−3
@@ -192,9 +192,12 @@ timeOfDay64 (TOD h m s0)
192192 !(T mh ml) = twoDigits m
193193 !(T sh sl) = twoDigits (fromIntegral real)
194194 (real,frac) = s `quotRem` pico
195− -- Round up picoseconds so that milliseconds >= 0.5 render correctly.
196− s | s0 `rem` mu < nu = s0
197− | otherwise = s0 + mu
195+ -- Round fractional milliseconds to render more accurately. We
196+ -- give up when there are leap seconds in play or there might be a
197+ -- need for carry propagation.
198+ s | s0 >= 59999000000000 = s0
199+ | s0 `rem` mu < nu = s0
200+ | otherwise = s0 + mu
198201 tenths = fromIntegral (frac `quot` mu)
199202 pico = 1000000000000 -- 1 second in picoseconds
200203 mu = 1000000000 -- 100 microseconds