Skip to content

Show instance for Time #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions io-classes/si-timers/src/Control/Monad/Class/MonadTime/SI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,27 @@ import Control.Monad.Class.MonadTime qualified as MonadTime

import NoThunks.Class (NoThunks (..))

import Data.Fixed (Pico, showFixed)
import Data.Time.Clock (DiffTime)
import Data.Time.Clock qualified as Time
import Data.Word (Word64)
import GHC.Generics (Generic (..))


-- | A point in time in a monotonic clock.
-- | A point in time in a monotonic clock counted in seconds.
--
-- The epoch for this clock is arbitrary and does not correspond to any wall
-- clock or calendar, and is /not guaranteed/ to be the same epoch across
-- program runs. It is represented as the 'DiffTime' from this arbitrary epoch.
--
newtype Time = Time DiffTime
deriving stock (Eq, Ord, Show, Generic)
deriving stock (Eq, Ord, Generic)
deriving newtype NFData
deriving anyclass NoThunks

instance Show Time where
show (Time t) = "Time " ++ showFixed True (realToFrac t :: Pico)

-- | The time duration between two points in time (positive or negative).
diffTime :: Time -> Time -> DiffTime
diffTime (Time t) (Time t') = t - t'
Expand Down
Loading