From 5c8b2e135c8277921894b74ef754a20e76bd0fde Mon Sep 17 00:00:00 2001 From: Olavi Haapala Date: Sat, 12 Jan 2019 01:22:26 +0200 Subject: [PATCH] Add zero-padding to the output human time Fixes and closes #130 --- examples/08-time.elm | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/08-time.elm b/examples/08-time.elm index 9f6ed6b..2959562 100644 --- a/examples/08-time.elm +++ b/examples/08-time.elm @@ -73,9 +73,14 @@ subscriptions model = view : Model -> Html Msg view model = - let - hour = String.fromInt (Time.toHour model.zone model.time) - minute = String.fromInt (Time.toMinute model.zone model.time) - second = String.fromInt (Time.toSecond model.zone model.time) - in - h1 [] [ text (hour ++ ":" ++ minute ++ ":" ++ second) ] \ No newline at end of file + let + hour = + String.padLeft 2 '0' (String.fromInt (Time.toHour model.zone model.time)) + + minute = + String.padLeft 2 '0' (String.fromInt (Time.toMinute model.zone model.time)) + + second = + String.padLeft 2 '0' (String.fromInt (Time.toSecond model.zone model.time)) + in + h1 [] [ text (hour ++ ":" ++ minute ++ ":" ++ second) ]