-- |
-- Copyright: © 2018-2020 IOHK
-- License: Apache-2.0
--
-- Utility functions for manipulating time values.

module Data.Time.Utils
    ( utcTimePred
    , utcTimeSucc
    ) where

import Prelude

import Data.Time
    ( UTCTime, addUTCTime )

-- | For a given time 't0', get the closest representable time 't1' to 't0'
--   for which 't0 < t1'.
utcTimeSucc :: UTCTime -> UTCTime
utcTimeSucc :: UTCTime -> UTCTime
utcTimeSucc = NominalDiffTime -> UTCTime -> UTCTime
addUTCTime (NominalDiffTime -> UTCTime -> UTCTime)
-> NominalDiffTime -> UTCTime -> UTCTime
forall a b. (a -> b) -> a -> b
$ NominalDiffTime -> NominalDiffTime
forall a. Enum a => a -> a
succ NominalDiffTime
0

-- | For a given time 't0', get the closest representable time 't1' to 't0'
--   for which 't1 < t0'.
utcTimePred :: UTCTime -> UTCTime
utcTimePred :: UTCTime -> UTCTime
utcTimePred = NominalDiffTime -> UTCTime -> UTCTime
addUTCTime (NominalDiffTime -> UTCTime -> UTCTime)
-> NominalDiffTime -> UTCTime -> UTCTime
forall a b. (a -> b) -> a -> b
$ NominalDiffTime -> NominalDiffTime
forall a. Enum a => a -> a
pred NominalDiffTime
0