module Postgres.Time
( Interval,
fromMicroseconds,
fromMilliseconds,
fromSeconds,
microseconds,
milliseconds,
seconds,
)
where
newtype Interval = Interval
{
Interval -> Int
microseconds :: Int
}
deriving (Interval -> Interval -> Bool
(Interval -> Interval -> Bool)
-> (Interval -> Interval -> Bool) -> Eq Interval
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Interval -> Interval -> Bool
$c/= :: Interval -> Interval -> Bool
== :: Interval -> Interval -> Bool
$c== :: Interval -> Interval -> Bool
Eq, Int -> Interval -> ShowS
[Interval] -> ShowS
Interval -> String
(Int -> Interval -> ShowS)
-> (Interval -> String) -> ([Interval] -> ShowS) -> Show Interval
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Interval] -> ShowS
$cshowList :: [Interval] -> ShowS
show :: Interval -> String
$cshow :: Interval -> String
showsPrec :: Int -> Interval -> ShowS
$cshowsPrec :: Int -> Interval -> ShowS
Show)
fromMicroseconds :: Int -> Interval
fromMicroseconds :: Int -> Interval
fromMicroseconds = Int -> Interval
Interval
seconds :: Interval -> Float
seconds :: Interval -> Float
seconds Interval
interval = Float
1e-6 Float -> Float -> Float
forall number. Num number => number -> number -> number
* Int -> Float
toFloat (Interval -> Int
microseconds Interval
interval)
fromSeconds :: Float -> Interval
fromSeconds :: Float -> Interval
fromSeconds Float
duration = Int -> Interval
fromMicroseconds (Float -> Int
round (Float
1e6 Float -> Float -> Float
forall number. Num number => number -> number -> number
* Float
duration))
milliseconds :: Interval -> Float
milliseconds :: Interval -> Float
milliseconds Interval
interval = Float
1e-3 Float -> Float -> Float
forall number. Num number => number -> number -> number
* Int -> Float
toFloat (Interval -> Int
microseconds Interval
interval)
fromMilliseconds :: Float -> Interval
fromMilliseconds :: Float -> Interval
fromMilliseconds Float
duration = Int -> Interval
fromMicroseconds (Float -> Int
round (Float
1e3 Float -> Float -> Float
forall number. Num number => number -> number -> number
* Float
duration))