{-# LANGUAGE OverloadedStrings #-}
module Mcmc.Monitor.Time
( renderDuration,
renderDurationS,
renderTime,
)
where
import qualified Data.ByteString.Builder as BB
import qualified Data.ByteString.Lazy.Char8 as BL
import Data.Time
import Mcmc.Internal.ByteString
renderDuration :: NominalDiffTime -> BL.ByteString
renderDuration :: NominalDiffTime -> ByteString
renderDuration NominalDiffTime
dt = ByteString
hTxt forall a. Semigroup a => a -> a -> a
<> ByteString
mTxt forall a. Semigroup a => a -> a -> a
<> ByteString
sTxt
where
hTxt :: ByteString
hTxt = Int -> ByteString
renderDecimal Int
h forall a. Semigroup a => a -> a -> a
<> ByteString
":"
mTxt :: ByteString
mTxt = Int -> ByteString
renderDecimal Int
m forall a. Semigroup a => a -> a -> a
<> ByteString
":"
sTxt :: ByteString
sTxt = Int -> ByteString
renderDecimal Int
s
(Int
h, Int
hRem) = Int
ts forall a. Integral a => a -> a -> (a, a)
`quotRem` Int
3600
(Int
m, Int
s) = Int
hRem forall a. Integral a => a -> a -> (a, a)
`quotRem` Int
60
ts :: Int
ts :: Int
ts = forall a b. (RealFrac a, Integral b) => a -> b
round NominalDiffTime
dt
renderDecimal :: Int -> ByteString
renderDecimal Int
n = Char -> Int -> ByteString -> ByteString
alignRightWithNoTrim Char
'0' Int
2 forall a b. (a -> b) -> a -> b
$ Builder -> ByteString
BB.toLazyByteString forall a b. (a -> b) -> a -> b
$ Int -> Builder
BB.intDec Int
n
renderDurationS :: NominalDiffTime -> BL.ByteString
renderDurationS :: NominalDiffTime -> ByteString
renderDurationS NominalDiffTime
dt = Builder -> ByteString
BB.toLazyByteString forall a b. (a -> b) -> a -> b
$ Int -> Builder
BB.intDec Int
ts
where
ts :: Int
ts :: Int
ts = forall a b. (RealFrac a, Integral b) => a -> b
round NominalDiffTime
dt
renderTime :: FormatTime t => t -> String
renderTime :: forall t. FormatTime t => t -> String
renderTime = forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale String
"%B %-e, %Y, at %H:%M %P, %Z."