module Ouroboros.Consensus.Util.Time (
    multipleNominalDelay
  , nominalDelay
  , secondsToNominalDiffTime
  ) where

import           Data.Time (DiffTime, NominalDiffTime)

{-------------------------------------------------------------------------------
  Operations
-------------------------------------------------------------------------------}

-- | Multiply a 'NominalDiffTime' by an integer
--
-- The right conversions to use are somewhat tricky. The key fact is that
-- 'fromIntegral' interprets its argument as seconds.
multipleNominalDelay :: Integral a => NominalDiffTime -> a -> NominalDiffTime
multipleNominalDelay :: forall a. Integral a => NominalDiffTime -> a -> NominalDiffTime
multipleNominalDelay NominalDiffTime
dur a
i = NominalDiffTime
dur NominalDiffTime -> NominalDiffTime -> NominalDiffTime
forall a. Num a => a -> a -> a
* a -> NominalDiffTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
i

{-------------------------------------------------------------------------------
  Conversions
-------------------------------------------------------------------------------}

nominalDelay :: NominalDiffTime -> DiffTime
nominalDelay :: NominalDiffTime -> DiffTime
nominalDelay = NominalDiffTime -> DiffTime
forall a b. (Real a, Fractional b) => a -> b
realToFrac

secondsToNominalDiffTime :: Double -> NominalDiffTime
secondsToNominalDiffTime :: Double -> NominalDiffTime
secondsToNominalDiffTime = Double -> NominalDiffTime
forall a b. (Real a, Fractional b) => a -> b
realToFrac