module Time.Compat
( dateFromPOSIXEpoch
, dateFromTAIEpoch
, diffTimeToTimeOfDay
) where
import Data.Hourglass
dateFromPOSIXEpoch :: Integer
-> Date
dateFromPOSIXEpoch :: Integer -> Date
dateFromPOSIXEpoch Integer
day = do
let sec :: Elapsed
sec = Seconds -> Elapsed
Elapsed (Seconds -> Elapsed) -> Seconds -> Elapsed
forall a b. (a -> b) -> a -> b
$ Integer -> Seconds
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> Seconds) -> Integer -> Seconds
forall a b. (a -> b) -> a -> b
$ Integer
day Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
86400
Elapsed -> Date
forall t1 t2. (Timeable t1, Time t2) => t1 -> t2
timeConvert Elapsed
sec
daysTAItoPOSIX :: Integer
daysTAItoPOSIX :: Integer
daysTAItoPOSIX = Integer
40587
dateFromTAIEpoch :: Integer
-> Date
dateFromTAIEpoch :: Integer -> Date
dateFromTAIEpoch Integer
dtai =
Integer -> Date
dateFromPOSIXEpoch (Integer
dtai Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
- Integer
daysTAItoPOSIX)
diffTimeToTimeOfDay :: Real t
=> t
-> TimeOfDay
diffTimeToTimeOfDay :: forall t. Real t => t -> TimeOfDay
diffTimeToTimeOfDay t
dt = do
TimeOfDay
{ todHour :: Hours
todHour = Integer -> Hours
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
hours
, todMin :: Minutes
todMin = Integer -> Minutes
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
minutes
, todSec :: Seconds
todSec = Integer -> Seconds
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
seconds
, todNSec :: NanoSeconds
todNSec = Integer -> NanoSeconds
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
nsecs
}
where
r :: Rational
r :: Rational
r = t -> Rational
forall a. Real a => a -> Rational
toRational t
dt
(Integer
secs, Rational
nR) = Rational -> (Integer, Rational)
forall b. Integral b => Rational -> (b, Rational)
forall a b. (RealFrac a, Integral b) => a -> (b, a)
properFraction Rational
r :: (Integer, Rational)
nsecs :: Integer
nsecs :: Integer
nsecs = Rational -> Integer
forall b. Integral b => Rational -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (Rational
nR Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
* Rational
1000000000)
(Integer
minsofday, Integer
seconds) = Integer
secs Integer -> Integer -> (Integer, Integer)
forall a. Integral a => a -> a -> (a, a)
`divMod` Integer
60 :: (Integer, Integer)
(Integer
hours, Integer
minutes) = Integer
minsofday Integer -> Integer -> (Integer, Integer)
forall a. Integral a => a -> a -> (a, a)
`divMod` Integer
60 :: (Integer, Integer)