module Data.Time.Clock.DiffTime
  ( DiffTime,
    secondsToDiffTime,
    millisecondsToDiffTime,
    picosecondsToDiffTime,
    diffTimeToFullMicroseconds,
    diffTimeToPicoseconds,
  )
where

import Data.Time
import Imports

-- FUTUREWORK: we really should be doing all this with https://hackage.haskell.org/package/units...
millisecondsToDiffTime :: Integer -> DiffTime
millisecondsToDiffTime :: Integer -> DiffTime
millisecondsToDiffTime = Integer -> DiffTime
picosecondsToDiffTime (Integer -> DiffTime)
-> (Integer -> Integer) -> Integer -> DiffTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Integer
e9 *)

-- | Rounds down. Useful for 'threadDelay', 'timeout', etc.
diffTimeToFullMicroseconds :: DiffTime -> Int
diffTimeToFullMicroseconds :: DiffTime -> Int
diffTimeToFullMicroseconds = Integer -> Int
forall a. Num a => Integer -> a
fromInteger (Integer -> Int) -> (DiffTime -> Integer) -> DiffTime -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Integer -> Integer -> Integer
forall a. Integral a => a -> a -> a
`div` Integer
e6) (Integer -> Integer)
-> (DiffTime -> Integer) -> DiffTime -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiffTime -> Integer
diffTimeToPicoseconds

e6, e9 :: Integer
e6 :: Integer
e6 = Integer
1_000_000
e9 :: Integer
e9 = Integer
1_000_000_000