on master help sign in
Handle leap seconds correctly
commitfe58d1d2fe04cd509f4b70f9726fc365c92937cb authorAdam Schønemann <adamschoenemann@gmail.com> dateTue 11 Sep 2018, 14:08 (8 years ago) parentd0d0c5b
1 file changed+9−4
attoparsec-iso8601/Data/Attoparsec/Time/Internal.hs+9−4
attoparsec-iso8601/Data/Attoparsec/Time/Internal.hs+9−4
@@ -50,11 +50,16 @@ data TimeOfDay64 = TOD {-# UNPACK #-} !Int
5050 {-# UNPACK #-} !Int
5151 {-# UNPACK #-} !Int64
5252
53+posixDayLength :: DiffTime
54+posixDayLength = fromInteger 86400
55+
5356diffTimeOfDay64 :: DiffTime -> TimeOfDay64
54−diffTimeOfDay64 t = TOD (fromIntegral h) (fromIntegral m) s
55− where (h,mp) = fromIntegral pico `quotRem` 3600000000000000
56− (m,s) = mp `quotRem` 60000000000000
57− pico = unsafeCoerce t :: Integer
57+diffTimeOfDay64 t
58+ | t >= posixDayLength = TOD 23 59 (60000000000000 + (unsafeCoerce (t - posixDayLength)))
59+ | otherwise = TOD (fromIntegral h) (fromIntegral m) s
60+ where (h,mp) = fromIntegral pico `quotRem` 3600000000000000
61+ (m,s) = mp `quotRem` 60000000000000
62+ pico = unsafeCoerce t :: Integer
5863
5964toTimeOfDay64 :: TimeOfDay -> TimeOfDay64
6065toTimeOfDay64 (TimeOfDay h m s) = TOD h m (fromIntegral (fromPico s))