{-# LANGUAGE OverloadedStrings #-}
module Mcmc.Monitor.Time
( renderDuration,
renderDurationS,
)
where
import qualified Data.ByteString.Builder as BB
import qualified Data.ByteString.Lazy.Char8 as BL
import Mcmc.Internal.ByteString
import Data.Time.Clock
renderDuration :: NominalDiffTime -> BL.ByteString
renderDuration dt = hTxt <> mTxt <> sTxt
where
hTxt = renderDecimal h <> ":"
mTxt = renderDecimal m <> ":"
sTxt = renderDecimal s
(h, hRem) = ts `quotRem` 3600
(m, s) = hRem `quotRem` 60
ts :: Int
ts = round dt
renderDecimal n = alignRightWith '0' 2 $ BB.toLazyByteString $ BB.intDec n
renderDurationS :: NominalDiffTime -> BL.ByteString
renderDurationS dt = BB.toLazyByteString $ BB.intDec ts
where
ts :: Int
ts = round dt