@@ -23,10 +23,31 @@ import Data.Int (Int64)
23import Data.Time
23import Data.Time
24import Unsafe.Coerce (unsafeCoerce)
24import Unsafe.Coerce (unsafeCoerce)
26+#if MIN_VERSION_time(1,6,0)
28+import Data.Time.Clock (diffTimeToPicoseconds)
26#if MIN_VERSION_base(4,7,0)
32#if MIN_VERSION_base(4,7,0)
28import Data.Fixed (Pico, Fixed(MkFixed))
34import Data.Fixed (Pico, Fixed(MkFixed))
38+import Data.Fixed (Pico)
42+#if !MIN_VERSION_time(1,6,0)
44+diffTimeToPicoseconds :: DiffTime -> Integer
45+diffTimeToPicoseconds = unsafeCoerce
49+#if MIN_VERSION_base(4,7,0)
30toPico :: Integer -> Pico
51toPico :: Integer -> Pico
31toPico = MkFixed
52toPico = MkFixed
@@ -35,8 +56,6 @@ fromPico (MkFixed i) = i
38−import Data.Fixed (Pico)
40toPico :: Integer -> Pico
59toPico :: Integer -> Pico
41toPico = unsafeCoerce
60toPico = unsafeCoerce
@@ -50,11 +69,16 @@ data TimeOfDay64 = TOD {-# UNPACK #-} !Int
50 {-# UNPACK #-} !Int
69 {-# UNPACK #-} !Int
51 {-# UNPACK #-} !Int64
70 {-# UNPACK #-} !Int64
72+posixDayLength :: DiffTime
73+posixDayLength = 86400
53diffTimeOfDay64 :: DiffTime -> TimeOfDay64
75diffTimeOfDay64 :: DiffTime -> TimeOfDay64
77+ | t >= posixDayLength = TOD 23 59 (60000000000000 + pico (t - posixDayLength))
54−diffTimeOfDay64 t = TOD (fromIntegral h) (fromIntegral m) s
78+ | otherwise = TOD (fromIntegral h) (fromIntegral m) s
55− where (h,mp) = fromIntegral pico `quotRem` 3600000000000000
79+ where (h,mp) = pico t `quotRem` 3600000000000000
56− (m,s) = mp `quotRem` 60000000000000
80+ (m,s) = mp `quotRem` 60000000000000
57− pico = unsafeCoerce t :: Integer
81+ pico = fromIntegral . diffTimeToPicoseconds
59toTimeOfDay64 :: TimeOfDay -> TimeOfDay64
83toTimeOfDay64 :: TimeOfDay -> TimeOfDay64
60toTimeOfDay64 (TimeOfDay h m s) = TOD h m (fromIntegral (fromPico s))
84toTimeOfDay64 (TimeOfDay h m s) = TOD h m (fromIntegral (fromPico s))