11{-# LANGUAGE DataKinds #-}
2+ {-# LANGUAGE DeriveAnyClass #-}
3+ {-# LANGUAGE DeriveGeneric #-}
24{-# LANGUAGE DerivingVia #-}
35
46module Ouroboros.Consensus.BlockchainTime.WallClock.Types
@@ -15,6 +17,10 @@ module Ouroboros.Consensus.BlockchainTime.WallClock.Types
1517 -- * Get current time (as 'RelativeTime')
1618 , SystemTime (.. )
1719
20+ -- * Attach an arrival time (as 'RelativeTime') to an object
21+ , WithArrivalTime (.. )
22+ , addArrivalTime
23+
1824 -- * Slot length
1925 , getSlotLength
2026 , mkSlotLength
@@ -31,6 +37,7 @@ module Ouroboros.Consensus.BlockchainTime.WallClock.Types
3137
3238import Cardano.Slotting.Time
3339import Data.Time.Clock (NominalDiffTime )
40+ import GHC.Generics (Generic )
3441import NoThunks.Class (NoThunks , OnlyCheckWhnfNamed (.. ))
3542
3643addRelTime :: NominalDiffTime -> RelativeTime -> RelativeTime
@@ -60,3 +67,22 @@ data SystemTime m = SystemTime
6067 -- to reach 'SystemStart'. In tests this does nothing.
6168 }
6269 deriving NoThunks via OnlyCheckWhnfNamed " SystemTime" (SystemTime m )
70+
71+ {- ------------------------------------------------------------------------------
72+ Attach an arrival time (as RelativeTime) to an object
73+ -------------------------------------------------------------------------------}
74+
75+ -- | WithArrivalTime
76+ data WithArrivalTime a = WithArrivalTime
77+ { getArrivalTime :: ! RelativeTime
78+ -- ^ The time at which the object arrived
79+ , forgetArrivalTime :: ! a
80+ -- ^ The object without its arrival time
81+ }
82+ deriving (Show , Eq , Ord , Generic , NoThunks )
83+
84+ -- | Add an arrival time to an object
85+ addArrivalTime :: Monad m => SystemTime m -> a -> m (WithArrivalTime a )
86+ addArrivalTime systemTime a = do
87+ t <- systemTimeCurrent systemTime
88+ return (WithArrivalTime t a)
0 commit comments