on master help sign in
Handle leap seconds correctly
fe58d1dAdam Schønemann
attoparsec-iso8601/Data/Attoparsec/Time/Internal.hs+9−4
@@ -50,11 +50,16 @@ data TimeOfDay64 = TOD {-# UNPACK #-} !Int
50 {-# UNPACK #-} !Int
50 {-# UNPACK #-} !Int
51 {-# UNPACK #-} !Int64
51 {-# UNPACK #-} !Int64
52
52
53+posixDayLength :: DiffTime
54+posixDayLength = fromInteger 86400
55+
53diffTimeOfDay64 :: DiffTime -> TimeOfDay64
56diffTimeOfDay64 :: DiffTime -> TimeOfDay64
57+diffTimeOfDay64 t
58+ | t >= posixDayLength = TOD 23 59 (60000000000000 + (unsafeCoerce (t - posixDayLength)))
54−diffTimeOfDay64 t = TOD (fromIntegral h) (fromIntegral m) s
59+ | otherwise = TOD (fromIntegral h) (fromIntegral m) s
55− where (h,mp) = fromIntegral pico `quotRem` 3600000000000000
60+ where (h,mp) = fromIntegral pico `quotRem` 3600000000000000
56− (m,s) = mp `quotRem` 60000000000000
61+ (m,s) = mp `quotRem` 60000000000000
57− pico = unsafeCoerce t :: Integer
62+ pico = unsafeCoerce t :: Integer
58
63
59toTimeOfDay64 :: TimeOfDay -> TimeOfDay64
64toTimeOfDay64 :: TimeOfDay -> TimeOfDay64
60toTimeOfDay64 (TimeOfDay h m s) = TOD h m (fromIntegral (fromPico s))
65toTimeOfDay64 (TimeOfDay h m s) = TOD h m (fromIntegral (fromPico s))