-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Type-safe time library. -- -- See README.md for details. @package o-clock @version 0.0.0 -- | This module introduces Rat kind and all necessary functional. module Time.Rational -- | Data structure represents the rational number. Rational number can be -- represented as a pair of natural numbers n and m -- where m is nor equal to zero. data Rat (::%) :: Nat -> Nat -> Rat -- | More convenient name for promoted constructor of Rat. type :% = '(::%) -- | The result kind of overloaded multiplication. -- | The result kind of overloaded division. -- | Rational numbers, with numerator and denominator of Natural -- type. type RatioNat = Ratio Natural -- | This class gives the integer associated with a type-level rational. class KnownRat (r :: Rat) ratVal :: KnownRat r => RatioNat -- | Constraint alias for DivRat units. type KnownDivRat a b = (KnownRat a, KnownRat b) instance (GHC.TypeNats.KnownNat a, GHC.TypeNats.KnownNat b) => Time.Rational.KnownRat (a Time.Rational.:% b) -- | This module contains time unit data structures and functions to work -- with time. module Time.Units -- | Time unit is represented as type level rational multiplier with kind -- Rat. newtype Time (rat :: Rat) Time :: RatioNat -> Time [unTime] :: Time -> RatioNat type Second = 1 :% 1 type Millisecond = 1 :% 1000 type Microsecond = 1 :% 1000000 type Nanosecond = 1 :% 1000000000 type Picosecond = 1 :% 1000000000000 type Minute = 60 :% 1 type Hour = 3600 :% 1 type Day = 86400 :% 1 type Week = 604800 :% 1 type Fortnight = 1209600 :% 1 -- | Type-level list that consist of all times. type AllTimes = '[Fortnight, Week, Day, Hour, Minute, Second, Millisecond, Microsecond, Nanosecond, Picosecond] -- | Type family for prettier show of time units. -- | Constraint alias for KnownSymbol UnitName. type KnownUnitName unit = KnownSymbol (UnitName unit) -- | Constraint alias for KnownUnitName and KnownRat for time -- unit. type KnownRatName unit = (KnownUnitName unit, KnownRat unit) -- | Returns type-level Symbol of the time unit converted to -- String. unitNameVal :: forall (unit :: Rat). (KnownUnitName unit) => String -- | Creates Time of some type from given Natural. time :: Natural -> Time unit -- | Similar to floor, but works with Time units. -- --
-- >>> floorUnit @Day (Time $ 5 % 2) -- 2d ---- --
-- >>> floorUnit (Time @Second $ 2 % 3) -- 0s ---- --
-- >>> floorUnit $ ps 42 -- 42ps --floorUnit :: forall (unit :: Rat). Time unit -> Time unit -- | Creates Second from given Natural. -- --
-- >>> sec 42 -- 42s :: Time Second --sec :: Natural -> Time Second -- | Creates Millisecond from given Natural. -- --
-- >>> ms 42 -- 42ms :: Time Millisecond --ms :: Natural -> Time Millisecond -- | Creates Microsecond from given Natural. -- --
-- >>> mcs 42 -- 42mcs :: Time Microsecond --mcs :: Natural -> Time Microsecond -- | Creates Nanosecond from given Natural. -- --
-- >>> ns 42 -- 42ns :: Time Nanosecond --ns :: Natural -> Time Nanosecond -- | Creates Picosecond from given Natural. -- --
-- >>> ps 42 -- 42ps :: Time Picosecond --ps :: Natural -> Time Picosecond -- | Creates Minute from given Natural. -- --
-- >>> minute 42 -- 42m :: Time Minute --minute :: Natural -> Time Minute -- | Creates Hour from given Natural. -- --
-- >>> hour 42 -- 42h :: Time Hour --hour :: Natural -> Time Hour -- | Creates Day from given Natural. -- --
-- >>> day 42 -- 42d :: Time Day --day :: Natural -> Time Day -- | Creates Week from given Natural. -- --
-- >>> sec 42 -- 42w :: Time Week --week :: Natural -> Time Week -- | Creates Fortnight from given Natural. -- --
-- >>> fortnight 42 -- 42fn :: Time Fortnight --fortnight :: Natural -> Time Fortnight -- | Sums times of different units. -- --
-- >>> minute 1 +: sec 1 -- 61s --(+:) :: forall (unitResult :: Rat) (unitLeft :: Rat). KnownDivRat unitLeft unitResult => Time unitLeft -> Time unitResult -> Time unitResult -- | Converts from one time unit to another time unit. -- --
-- >>> toUnit @Hour (120 :: Time Minute) -- 2h ---- --
-- >>> toUnit @Second (ms 7) -- 7/1000s ---- --
-- >>> toUnit @Week (Time @Day 45) -- 45/7w ---- --
-- >>> toUnit @Second @Minute 3 -- 180s ---- --
-- >>> toUnit (day 42000000) :: Time Second -- 3628800000000s --toUnit :: forall (unitTo :: Rat) (unitFrom :: Rat). KnownDivRat unitFrom unitTo => Time unitFrom -> Time unitTo -- | Convenient version of threadDelay which takes any time-unit and -- operates in any MonadIO. -- --
-- >>> threadDelay $ sec 2 -- -- >>> threadDelay (2 :: Time Second) -- -- >>> threadDelay @Second 2 --threadDelay :: forall (unit :: Rat) m. (KnownDivRat unit Microsecond, MonadIO m) => Time unit -> m () -- | Similar to getCPUTime but returns the CPU time used by the -- current program in the given time unit. The precision of this result -- is implementation-dependent. -- --
-- >>> getCPUTime @Second -- 1064046949/1000000000s --getCPUTime :: forall (unit :: Rat) m. (KnownDivRat Picosecond unit, MonadIO m) => m (Time unit) -- | Similar to timeout but receiving any time unit instead of -- number of microseconds. -- --
-- >>> timeout (sec 1) (putStrLn "Hello O'Clock") -- Hello O'Clock -- Just () ---- --
-- >>> timeout (ps 1) (putStrLn "Hello O'Clock") -- Nothing ---- --
-- >>> timeout (mcs 1) (putStrLn "Hello O'Clock") -- HellNothing --timeout :: forall (unit :: Rat) m a. (MonadIO m, KnownDivRat unit Microsecond) => Time unit -> IO a -> m (Maybe a) instance GHC.Generics.Generic (Time.Units.Time rat) instance GHC.Real.RealFrac (Time.Units.Time rat) instance GHC.Real.Real (Time.Units.Time rat) instance GHC.Enum.Enum (Time.Units.Time rat) instance GHC.Classes.Ord (Time.Units.Time rat) instance GHC.Classes.Eq (Time.Units.Time rat) instance Time.Units.KnownUnitName unit => GHC.Show.Show (Time.Units.Time unit) instance Time.Units.KnownUnitName unit => GHC.Read.Read (Time.Units.Time unit) instance GHC.Num.Num (Time.Units.Time unit) instance GHC.Real.Fractional (Time.Units.Time unit) -- | This module introduces TimeStamp data type and corresponding -- functions for operations with time. module Time.TimeStamp -- | Similar to Time but has no units and can be negative. newtype TimeStamp TimeStamp :: Rational -> TimeStamp -- | Returns the result of comparison of two Timestamps and the -- Time of that difference of given time unit. timeDiff :: forall (unit :: Rat). KnownRat unit => TimeStamp -> TimeStamp -> (Ordering, Time unit) -- | Returns the result of addition of two Time elements. timeAdd :: forall (unit :: Rat). KnownRat unit => Time unit -> Time unit -> Time unit -- | Returns the result of multiplication of two Time elements. timeMul :: forall (unit :: Rat). KnownRat unit => RatioNat -> Time unit -> Time unit -- | Returns the result of division of two Time elements. timeDiv :: forall (unit :: Rat). KnownRat unit => Time unit -> Time unit -> RatioNat instance GHC.Real.RealFrac Time.TimeStamp.TimeStamp instance GHC.Real.Real Time.TimeStamp.TimeStamp instance GHC.Real.Fractional Time.TimeStamp.TimeStamp instance GHC.Enum.Enum Time.TimeStamp.TimeStamp instance GHC.Classes.Ord Time.TimeStamp.TimeStamp instance GHC.Classes.Eq Time.TimeStamp.TimeStamp instance GHC.Num.Num Time.TimeStamp.TimeStamp instance GHC.Read.Read Time.TimeStamp.TimeStamp instance GHC.Show.Show Time.TimeStamp.TimeStamp -- | This module introduces function to format time in desired way. -- -- Examples -- --
-- >>> seriesF @'[Day, Hour, Minute, Second] (minute 4000) -- "2d18h40m" ---- --
-- >>> seriesF @'[Day, Minute, Second] (minute 4000) -- "2d1120m" ---- --
-- >>> seriesF @'[Hour, Minute, Second] (sec 3601) -- "1h1s" ---- --
-- >>> seriesF @'[Hour, Second, Millisecond] (Time @Minute $ 3 % 2) -- "90s" --module Time.Formatting -- | Class for time formatting. class Series (units :: [Rat]) seriesF :: forall (someUnit :: Rat). (Series units, KnownRatName someUnit) => Time someUnit -> String -- | Similar to seriesF, but formats using all time units of the -- library. -- --
-- >>> unitsF $ fortnight 5 -- "5fn" ---- --
-- >>> unitsF $ minute 4000 -- "2d18h40m" --unitsF :: forall unit. KnownRatName unit => Time unit -> String instance Time.Formatting.Series '[] instance (Time.Units.KnownRatName unit, Time.Formatting.Series units) => Time.Formatting.Series (unit : units) -- | This module reexports main functionality. -- -- More information about O'Clock features can be found here: -- https://github.com/serokell/o-clock#readme module Time