factor out Utility.MonotonicClock

This commit is contained in:
Joey Hess 2024-07-03 17:54:01 -04:00
parent 543c610a31
commit 5b6150e5d5
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 30 additions and 15 deletions

24
Utility/MonotonicClock.hs Normal file
View file

@ -0,0 +1,24 @@
{- Monotonic clocks
-
- Copyright 2024 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
{-# LANGUAGE CPP #-}
module Utility.MonotonicClock where
#if MIN_VERSION_clock(0,3,0)
import qualified System.Clock as Clock
#else
import qualified System.Posix.Clock as Clock
#endif
newtype MonotonicTimestamp = MonotonicTimestamp Integer
deriving (Show, Eq, Ord)
currentMonotonicTimestamp :: IO MonotonicTimestamp
currentMonotonicTimestamp =
(MonotonicTimestamp . fromIntegral . Clock.sec)
<$> Clock.getTime Clock.Monotonic