git.iko.soy/typeable/postgresql-simple
on master help sign in
Fix NominalDiffTime on negative values
91f5883Leon P Smith
src/Database/PostgreSQL/Simple/Time/Implementation.hs+5−5
@@ -231,14 +231,14 @@ dateToBuilder = unboundedToBuilder dayToBuilder
231
231
232nominalDiffTimeToBuilder :: NominalDiffTime -> Builder
232nominalDiffTimeToBuilder :: NominalDiffTime -> Builder
233nominalDiffTimeToBuilder xyz
233nominalDiffTimeToBuilder xyz
234− | yz == 0 = integral x
234+ | yz < 500000 = sign ++ integral x
235− | z == 0 = integral x ++ fromChar '.' ++ showD6 y
236− | otherwise = integral x ++ fromChar '.' ++ pad6 y ++ showD6 z
235+ | otherwise = sign ++ integral x ++ fromChar '.' ++ showD6 y
237 where
236 where
238 -- A kludge to work around the fact that Data.Fixed isn't very fast and
237 -- A kludge to work around the fact that Data.Fixed isn't very fast and
239 -- doesn't give me access to the MkFixed constructor.
238 -- doesn't give me access to the MkFixed constructor.
239+ sign = if xyz >= 0 then mempty else fromChar '-'
240− (x,yz) = (unsafeCoerce xyz :: Integer) `quotRem` 1000000000000
240+ (x,yz) = ((unsafeCoerce (abs xyz) :: Integer) + 500000) `quotRem` 1000000000000
241− (fromIntegral -> y, fromIntegral -> z) = yz `quotRem` 1000000
241+ (fromIntegral -> y, _z) = yz `quotRem` 1000000
242
242
243showSeconds :: Pico -> Builder
243showSeconds :: Pico -> Builder
244showSeconds xyz
244showSeconds xyz