Skip to content

Commit

Permalink
Add zero-padding to the output human time
Browse files Browse the repository at this point in the history
Fixes and closes evancz#130
  • Loading branch information
olpeh committed Jan 11, 2019
1 parent 4803e86 commit 5c8b2e1
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions examples/08-time.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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) ]
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) ]

0 comments on commit 5c8b2e1

Please sign in to comment.