| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Time.Timestamp
Contents
Description
This module introduces Timestamp data type
and corresponding functions for operations with time.
- newtype Timestamp = Timestamp Rational
- fromUnixTime :: Real a => a -> Timestamp
- timeDiff :: forall (unit :: Rat). KnownDivRat Second unit => Timestamp -> Timestamp -> (Ordering, Time unit)
- timeAdd :: forall (unit :: Rat). KnownDivRat unit Second => Time unit -> Timestamp -> Timestamp
- timeMul :: forall (unit :: Rat). KnownRat unit => RatioNat -> Time unit -> Time unit
- (*:*) :: forall (unit :: Rat). KnownRat unit => RatioNat -> Time unit -> Time unit
- timeDiv :: forall (unit :: Rat). KnownRat unit => Time unit -> Time unit -> RatioNat
- (/:/) :: forall (unit :: Rat). KnownRat unit => Time unit -> Time unit -> RatioNat
- (+:+) :: forall (unitResult :: Rat) (unitLeft :: Rat). KnownDivRat unitLeft unitResult => Time unitLeft -> Time unitResult -> Time unitResult
- (-:-) :: forall (unitResult :: Rat) (unitLeft :: Rat). KnownDivRat unitLeft unitResult => Time unitLeft -> Time unitResult -> Time unitResult
- (-%-) :: forall (unitResult :: Rat) (unitLeft :: Rat). KnownDivRat unitLeft unitResult => Time unitLeft -> Time unitResult -> (Ordering, Time unitResult)
Documentation
Similar to Time but has no units and can be negative.
timeDiff :: forall (unit :: Rat). KnownDivRat Second unit => Timestamp -> Timestamp -> (Ordering, Time unit) Source #
Returns the result of comparison of two Timestamps and
the Time of that difference of given time unit.
>>>timeDiff @Second (Timestamp 4) (Timestamp 2)(GT,2s)
>>>timeDiff @Minute (Timestamp 4) (Timestamp 2)(GT,1/30m)
>>>timeDiff @Second (Timestamp 2) (Timestamp 4)(LT,2s)
>>>timeDiff @Minute (Timestamp 2) (Timestamp 4)(LT,1/30m)
timeAdd :: forall (unit :: Rat). KnownDivRat unit Second => Time unit -> Timestamp -> Timestamp Source #
timeMul :: forall (unit :: Rat). KnownRat unit => RatioNat -> Time unit -> Time unit Source #
Returns the result of multiplication of two Time elements.
(*:*) :: forall (unit :: Rat). KnownRat unit => RatioNat -> Time unit -> Time unit infixr 7 Source #
Operator version of timeMul.
>>>3 *:* sec 515s
>>>2 *:* 3 *:* sec 530s
>>>3 *:* 5 *:* sec 7105s
>>>ms 2000 +:+ 2 *:* sec 38s
timeDiv :: forall (unit :: Rat). KnownRat unit => Time unit -> Time unit -> RatioNat Source #
Returns the result of division of two Time elements.
(/:/) :: forall (unit :: Rat). KnownRat unit => Time unit -> Time unit -> RatioNat infix 7 Source #
Operator version of timeDiv.
>>>sec 15 /:/ sec 35 % 1
Other operators
(+:+) :: forall (unitResult :: Rat) (unitLeft :: Rat). KnownDivRat unitLeft unitResult => Time unitLeft -> Time unitResult -> Time unitResult infixl 6 Source #
Sums times of different units.
>>>minute 1 +:+ sec 161s
(-:-) :: forall (unitResult :: Rat) (unitLeft :: Rat). KnownDivRat unitLeft unitResult => Time unitLeft -> Time unitResult -> Time unitResult infixl 6 Source #
Substracts time amounts of different units. When the minuend is smaller
than the subtrahend, this function will throw Underflow :: ArithException.
>>>minute 1 -:- sec 159s
(-%-) :: forall (unitResult :: Rat) (unitLeft :: Rat). KnownDivRat unitLeft unitResult => Time unitLeft -> Time unitResult -> (Ordering, Time unitResult) infix 6 Source #
Compute the difference between two amounts of time. The result is returned
in two components: the ordering (which input is larger) and the numeric
difference (how much larger). Unlike -:-, does not throw ArithException.
>>>sec 5 -%- sec 3(GT,2s)
>>>sec 5 -%- sec 6(LT,1s)