on master help sign in
"Fix" time truncation in a not-too-heinous way
11b83edBryan O'Sullivan
Data/Aeson/Encode/Builder.hs+6−3
@@ -192,9 +192,12 @@ timeOfDay64 (TOD h m s0)
192 !(T mh ml) = twoDigits m
192 !(T mh ml) = twoDigits m
193 !(T sh sl) = twoDigits (fromIntegral real)
193 !(T sh sl) = twoDigits (fromIntegral real)
194 (real,frac) = s `quotRem` pico
194 (real,frac) = s `quotRem` pico
195− -- Round up picoseconds so that milliseconds >= 0.5 render correctly.
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
196− s | s0 `rem` mu < nu = s0
199+ | s0 `rem` mu < nu = s0
197− | otherwise = s0 + mu
200+ | otherwise = s0 + mu
198 tenths = fromIntegral (frac `quot` mu)
201 tenths = fromIntegral (frac `quot` mu)
199 pico = 1000000000000 -- 1 second in picoseconds
202 pico = 1000000000000 -- 1 second in picoseconds
200 mu = 1000000000 -- 100 microseconds
203 mu = 1000000000 -- 100 microseconds