From d0b454b1075e59f76df010f7559c3165abaabc2b Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 30 Jul 2020 07:22:33 +0000 Subject: [PATCH] Add function `nominalDiffTimeToMicroseconds`. --- lib/core/src/Data/Time/Utils.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/core/src/Data/Time/Utils.hs b/lib/core/src/Data/Time/Utils.hs index 9b65f1e6eeb..4ec4a4b7ce1 100644 --- a/lib/core/src/Data/Time/Utils.hs +++ b/lib/core/src/Data/Time/Utils.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE NumericUnderscores #-} + -- | -- Copyright: © 2018-2020 IOHK -- License: Apache-2.0 @@ -5,14 +7,21 @@ -- Utility functions for manipulating time values. module Data.Time.Utils - ( utcTimePred + ( nominalDiffTimeToMicroseconds + , utcTimePred , utcTimeSucc ) where import Prelude import Data.Time - ( UTCTime, addUTCTime ) + ( NominalDiffTime, UTCTime, addUTCTime ) + +-- | Converts the specified time difference into an integral number of +-- microseconds. +-- +nominalDiffTimeToMicroseconds :: Integral i => NominalDiffTime -> i +nominalDiffTimeToMicroseconds = ceiling . (* 1_000_000) . toRational -- | For a given time 't0', get the closest representable time 't1' to 't0' -- for which 't0 < t1'.