graphql-engine-1.0.0: GraphQL API over Postgres
Safe HaskellNone
LanguageHaskell2010

Data.Time.Clock.Units

Description

Types for time intervals of various units. Each newtype wraps DiffTime, but they have different Num instances. The intent is to use the record selectors to write literals with particular units, like this:

>>> milliseconds 500
0.5s
>>> hours 3
10800s
>>> minutes 1.5 + seconds 30
120s

You can also go the other way using the constructors rather than the selectors:

>>> toRational $ Minutes (seconds 17)
17 % 60
>>> realToFrac (Days (hours 12)) :: Double
0.5

NOTE: the Real and Fractional instances just essentially add or strip the unit label (as above), so you can't use realToFrac to convert between the units types here. Instead try convertDuration which is less of a foot-gun.

The Read instances for these types mirror the behavior of the RealFrac instance wrt numeric literals for convenient serialization (e.g. when working with env vars):

>>> read "1.2" :: Milliseconds
Milliseconds {milliseconds = 0.0012s}

Generally, if you need to pass around a duration between functions you should use DiffTime directly. However if storing a duration in a type that will be serialized, e.g. one having a ToJSON instance, it is better to use one of these explicit wrapper types so that it's obvious what units will be used.

Synopsis

Documentation

newtype Seconds Source #

Constructors

Seconds 

Fields

Instances

Instances details
Eq Seconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

(==) :: Seconds -> Seconds -> Bool #

(/=) :: Seconds -> Seconds -> Bool #

Fractional Seconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Num Seconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Ord Seconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Read Seconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Real Seconds Source # 
Instance details

Defined in Data.Time.Clock.Units

RealFrac Seconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

properFraction :: Integral b => Seconds -> (b, Seconds) #

truncate :: Integral b => Seconds -> b #

round :: Integral b => Seconds -> b #

ceiling :: Integral b => Seconds -> b #

floor :: Integral b => Seconds -> b #

Show Seconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Hashable Seconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

hashWithSalt :: Int -> Seconds -> Int

hash :: Seconds -> Int

FromJSON Seconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

parseJSON :: Value -> Parser Seconds

parseJSONList :: Value -> Parser [Seconds]

ToJSON Seconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

toJSON :: Seconds -> Value

toEncoding :: Seconds -> Encoding

toJSONList :: [Seconds] -> Value

toEncodingList :: [Seconds] -> Encoding

Duration Seconds Source # 
Instance details

Defined in Data.Time.Clock.Units

FromEnv Seconds Source # 
Instance details

Defined in Hasura.Server.Init.Env

newtype Days Source #

Constructors

Days 

Fields

Instances

Instances details
Eq Days Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

(==) :: Days -> Days -> Bool #

(/=) :: Days -> Days -> Bool #

Fractional Days Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

(/) :: Days -> Days -> Days #

recip :: Days -> Days #

fromRational :: Rational -> Days #

Num Days Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

(+) :: Days -> Days -> Days #

(-) :: Days -> Days -> Days #

(*) :: Days -> Days -> Days #

negate :: Days -> Days #

abs :: Days -> Days #

signum :: Days -> Days #

fromInteger :: Integer -> Days #

Ord Days Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

compare :: Days -> Days -> Ordering #

(<) :: Days -> Days -> Bool #

(<=) :: Days -> Days -> Bool #

(>) :: Days -> Days -> Bool #

(>=) :: Days -> Days -> Bool #

max :: Days -> Days -> Days #

min :: Days -> Days -> Days #

Read Days Source # 
Instance details

Defined in Data.Time.Clock.Units

Real Days Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

toRational :: Days -> Rational #

RealFrac Days Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

properFraction :: Integral b => Days -> (b, Days) #

truncate :: Integral b => Days -> b #

round :: Integral b => Days -> b #

ceiling :: Integral b => Days -> b #

floor :: Integral b => Days -> b #

Show Days Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

showsPrec :: Int -> Days -> ShowS #

show :: Days -> String #

showList :: [Days] -> ShowS #

Hashable Days Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

hashWithSalt :: Int -> Days -> Int

hash :: Days -> Int

Duration Days Source # 
Instance details

Defined in Data.Time.Clock.Units

newtype Hours Source #

Constructors

Hours 

Fields

Instances

Instances details
Eq Hours Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

(==) :: Hours -> Hours -> Bool #

(/=) :: Hours -> Hours -> Bool #

Fractional Hours Source # 
Instance details

Defined in Data.Time.Clock.Units

Num Hours Source # 
Instance details

Defined in Data.Time.Clock.Units

Ord Hours Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

compare :: Hours -> Hours -> Ordering #

(<) :: Hours -> Hours -> Bool #

(<=) :: Hours -> Hours -> Bool #

(>) :: Hours -> Hours -> Bool #

(>=) :: Hours -> Hours -> Bool #

max :: Hours -> Hours -> Hours #

min :: Hours -> Hours -> Hours #

Read Hours Source # 
Instance details

Defined in Data.Time.Clock.Units

Real Hours Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

toRational :: Hours -> Rational #

RealFrac Hours Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

properFraction :: Integral b => Hours -> (b, Hours) #

truncate :: Integral b => Hours -> b #

round :: Integral b => Hours -> b #

ceiling :: Integral b => Hours -> b #

floor :: Integral b => Hours -> b #

Show Hours Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

showsPrec :: Int -> Hours -> ShowS #

show :: Hours -> String #

showList :: [Hours] -> ShowS #

Hashable Hours Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

hashWithSalt :: Int -> Hours -> Int

hash :: Hours -> Int

Duration Hours Source # 
Instance details

Defined in Data.Time.Clock.Units

newtype Minutes Source #

Constructors

Minutes 

Fields

Instances

Instances details
Eq Minutes Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

(==) :: Minutes -> Minutes -> Bool #

(/=) :: Minutes -> Minutes -> Bool #

Fractional Minutes Source # 
Instance details

Defined in Data.Time.Clock.Units

Num Minutes Source # 
Instance details

Defined in Data.Time.Clock.Units

Ord Minutes Source # 
Instance details

Defined in Data.Time.Clock.Units

Read Minutes Source # 
Instance details

Defined in Data.Time.Clock.Units

Real Minutes Source # 
Instance details

Defined in Data.Time.Clock.Units

RealFrac Minutes Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

properFraction :: Integral b => Minutes -> (b, Minutes) #

truncate :: Integral b => Minutes -> b #

round :: Integral b => Minutes -> b #

ceiling :: Integral b => Minutes -> b #

floor :: Integral b => Minutes -> b #

Show Minutes Source # 
Instance details

Defined in Data.Time.Clock.Units

Hashable Minutes Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

hashWithSalt :: Int -> Minutes -> Int

hash :: Minutes -> Int

Duration Minutes Source # 
Instance details

Defined in Data.Time.Clock.Units

newtype Milliseconds Source #

Constructors

Milliseconds 

Instances

Instances details
Eq Milliseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Fractional Milliseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Num Milliseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Ord Milliseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Read Milliseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Real Milliseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

RealFrac Milliseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Show Milliseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Hashable Milliseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

FromJSON Milliseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

parseJSON :: Value -> Parser Milliseconds

parseJSONList :: Value -> Parser [Milliseconds]

ToJSON Milliseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Methods

toJSON :: Milliseconds -> Value

toEncoding :: Milliseconds -> Encoding

toJSONList :: [Milliseconds] -> Value

toEncodingList :: [Milliseconds] -> Encoding

Duration Milliseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

FromEnv Milliseconds Source # 
Instance details

Defined in Hasura.Server.Init.Env

newtype Microseconds Source #

Constructors

Microseconds 

Instances

Instances details
Eq Microseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Fractional Microseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Num Microseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Ord Microseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Read Microseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Real Microseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

RealFrac Microseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Show Microseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Hashable Microseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Duration Microseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

newtype Nanoseconds Source #

Constructors

Nanoseconds 

Instances

Instances details
Eq Nanoseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Fractional Nanoseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Num Nanoseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Ord Nanoseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Read Nanoseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Real Nanoseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

RealFrac Nanoseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Show Nanoseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Hashable Nanoseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Duration Nanoseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

newtype TimeUnit (picosPerUnit :: Nat) Source #

Constructors

TimeUnit DiffTime 

type SecondsP n = n * 1000000000000 Source #

natNum :: forall n a. (KnownNat n, Num a) => a Source #

class Duration d where Source #

Duration types isomorphic to DiffTime, powering convertDuration.

Instances

Instances details
Duration NominalDiffTime Source # 
Instance details

Defined in Data.Time.Clock.Units

Duration DiffTime Source # 
Instance details

Defined in Data.Time.Clock.Units

Duration Nanoseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Duration Microseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Duration Milliseconds Source # 
Instance details

Defined in Data.Time.Clock.Units

Duration Minutes Source # 
Instance details

Defined in Data.Time.Clock.Units

Duration Hours Source # 
Instance details

Defined in Data.Time.Clock.Units

Duration Days Source # 
Instance details

Defined in Data.Time.Clock.Units

Duration Seconds Source # 
Instance details

Defined in Data.Time.Clock.Units

convertDuration :: (Duration x, Duration y) => x -> y Source #

Safe conversion between duration units.