chore(status): improve readability of time spans

This commit is contained in:
Steffen Jost 2024-08-28 10:45:11 +02:00
parent 40dadd5876
commit 81721b0794

View File

@ -6,6 +6,7 @@ module Handler.Health where
import Import import Import
import Data.Time.Format.ISO8601 (iso8601Show)
import Handler.Utils.DateTime (formatTimeW) import Handler.Utils.DateTime (formatTimeW)
import qualified Data.Aeson.Encode.Pretty as Aeson import qualified Data.Aeson.Encode.Pretty as Aeson
@ -115,6 +116,8 @@ getStatusR = do
starttime <- getsYesod appStartTime starttime <- getsYesod appStartTime
(currtime, env_version) <- liftIO $ (,) <$> getCurrentTime <*> lookupEnv "VERSION_NR" (currtime, env_version) <- liftIO $ (,) <$> getCurrentTime <*> lookupEnv "VERSION_NR"
-- ft <- formatTime' "%Y-%m-%d %H:%M:%S" currtime -- ft <- formatTime' "%Y-%m-%d %H:%M:%S" currtime
let diffTime :: UTCTime -> Text
diffTime = pack . iso8601Show . calendarTimeTime . fromIntegral . truncate . diffUTCTime currtime
withUrlRenderer withUrlRenderer
[hamlet| [hamlet|
$doctype 5 $doctype 5
@ -131,16 +134,13 @@ getStatusR = do
<p> <p>
Instance Start <br> Instance Start <br>
#{show starttime} # #{show starttime} #
Uptime: #{show $ ddays starttime currtime} days. Uptime: #{diffTime starttime}
<p> <p>
Compile Time <br> Compile Time <br>
#{show cTime} # #{show cTime} #
Build age: #{show $ ddays cTime currtime} days. Build age: #{diffTime cTime}
|] |]
where where
-- vnr_full :: Text = $(embedStringFile "nix/docker/version.json") -- nix/ files not accessible during container construction -- vnr_full :: Text = $(embedStringFile "nix/docker/version.json") -- nix/ files not accessible during container construction
cTime :: UTCTime cTime :: UTCTime
cTime = $compileTime cTime = $compileTime
ddays :: UTCTime -> UTCTime -> Double
ddays tstart tstop = (/100) $ fromIntegral $ round $ diffUTCTime tstop tstart / (36 * 24)