{-# LANGUAGE OverloadedStrings #-}
module Mcmc.Monitor.Time
( renderDuration,
)
where
import qualified Data.Text.Lazy as T
import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy.Builder as T
import qualified Data.Text.Lazy.Builder.Int as T
import Data.Time.Clock
renderDuration :: NominalDiffTime -> Text
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 = T.justifyRight 2 '0' $ T.toLazyText $ T.decimal n