1 -- | Utilities for dealing with times and durations.
10 import Data
.Time
.Clock
(DiffTime
, secondsToDiffTime
)
11 import Data
.Time
.Clock
.System
(getSystemTime
, systemToTAITime
)
12 import Data
.Time
.Clock
.TAI
(AbsoluteTime
, diffAbsoluteTime
)
13 import Data
.Time
.Format
(defaultTimeLocale, formatTime
)
15 -- | Get the current time as an `AbsoluteTime`.
16 getAbsoluteTime
:: IO AbsoluteTime
17 getAbsoluteTime
= systemToTAITime
<$> getSystemTime
19 -- | Format a `DiffTime` nicely.
21 -- Short durations are formatted like @16.34s@, durations longer than a minute
22 -- are formatted like @22:34.68@, durations longer than an hour are formatted
24 formatDiffTime
:: DiffTime
-> String
25 formatDiffTime delta
=
26 let minute
= secondsToDiffTime
60
29 then formatTime
defaultTimeLocale "%h:%02M:%02ES" delta
32 then formatTime
defaultTimeLocale "%m:%2ES" delta
33 else formatTime
defaultTimeLocale "%2Ess" delta