module Data.HodaTime.Duration
(
Duration
,fromStandardWeeks
,fromStandardDays
,fromHours
,fromMinutes
,fromSeconds
,fromMilliseconds
,fromMicroseconds
,fromNanoseconds
,add
,minus
)
where
import Data.HodaTime.Duration.Internal
import Data.HodaTime.Instant.Internal (Instant(..))
import Data.HodaTime.Instant (difference)
import qualified Data.HodaTime.Instant as I (add)
import Data.HodaTime.Constants (secondsPerHour)
fromStandardWeeks :: Int -> Duration
fromStandardWeeks :: Int -> Duration
fromStandardWeeks Int
w = Int -> Duration
fromStandardDays (Int -> Duration) -> Int -> Duration
forall a b. (a -> b) -> a -> b
$ Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
7
fromStandardDays :: Int -> Duration
fromStandardDays :: Int -> Duration
fromStandardDays Int
d = Instant -> Duration
Duration (Instant -> Duration) -> Instant -> Duration
forall a b. (a -> b) -> a -> b
$ Int32 -> Word32 -> Word32 -> Instant
Instant (Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
d) Word32
0 Word32
0
fromHours :: Int -> Duration
fromHours :: Int -> Duration
fromHours = Int -> Duration
fromSeconds (Int -> Duration) -> (Int -> Int) -> Int -> Duration
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
forall a. Num a => a
secondsPerHour)
fromMinutes :: Int -> Duration
fromMinutes :: Int -> Duration
fromMinutes = Int -> Duration
fromSeconds (Int -> Duration) -> (Int -> Int) -> Int -> Duration
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
60)
fromMilliseconds :: Int -> Duration
fromMilliseconds :: Int -> Duration
fromMilliseconds = Int -> Duration
fromNanoseconds (Int -> Duration) -> (Int -> Int) -> Int -> Duration
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1000000)
fromMicroseconds :: Int -> Duration
fromMicroseconds :: Int -> Duration
fromMicroseconds = Int -> Duration
fromNanoseconds (Int -> Duration) -> (Int -> Int) -> Int -> Duration
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1000)
add :: Duration -> Duration -> Duration
add :: Duration -> Duration -> Duration
add (Duration Instant
instant) = Instant -> Duration
Duration (Instant -> Duration)
-> (Duration -> Instant) -> Duration -> Duration
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Instant -> Duration -> Instant
I.add Instant
instant
minus :: Duration -> Duration -> Duration
minus :: Duration -> Duration -> Duration
minus (Duration Instant
linstant) (Duration Instant
rinstant) = Instant -> Instant -> Duration
difference Instant
linstant Instant
rinstant