git.iko.soy/typeable/postgresql-simple
on master help sign in
Fix NominalDiffTime on negative values

Also, round to the nearest microsecond

commit91f5883822b1945483d4d7b6b67dbf2ffe624267 authorLeon P Smith <leon@melding-monads.com> dateTue 7 Oct 2014, 19:52 (12 years ago) parent46a6b3a
1 file changed+5−5
src/Database/PostgreSQL/Simple/Time/Implementation.hs+5−5
src/Database/PostgreSQL/Simple/Time/Implementation.hs+5−5
@@ -231,14 +231,14 @@ dateToBuilder = unboundedToBuilder dayToBuilder
231231
232232nominalDiffTimeToBuilder :: NominalDiffTime -> Builder
233233nominalDiffTimeToBuilder xyz
234− | yz == 0 = integral x
235− | z == 0 = integral x ++ fromChar '.' ++ showD6 y
236− | otherwise = integral x ++ fromChar '.' ++ pad6 y ++ showD6 z
234+ | yz < 500000 = sign ++ integral x
235+ | otherwise = sign ++ integral x ++ fromChar '.' ++ showD6 y
237236 where
238237 -- A kludge to work around the fact that Data.Fixed isn't very fast and
239238 -- doesn't give me access to the MkFixed constructor.
240− (x,yz) = (unsafeCoerce xyz :: Integer) `quotRem` 1000000000000
241− (fromIntegral -> y, fromIntegral -> z) = yz `quotRem` 1000000
239+ sign = if xyz >= 0 then mempty else fromChar '-'
240+ (x,yz) = ((unsafeCoerce (abs xyz) :: Integer) + 500000) `quotRem` 1000000000000
241+ (fromIntegral -> y, _z) = yz `quotRem` 1000000
242242
243243showSeconds :: Pico -> Builder
244244showSeconds xyz