-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01_Clock.elm
52 lines (37 loc) · 833 Bytes
/
01_Clock.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
module Main exposing (..)
import Html
import Html.App
import Time
import Date
import Date.Format
main : Program Never
main =
Html.App.program
{ init = init
, update = update
, view = view
, subscriptions = subscriptions
}
type alias Model =
Time.Time
init : ( Model, Cmd Msg )
init =
( 0, Cmd.none )
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Tick newTime ->
( newTime, Cmd.none )
type Msg
= Tick Time.Time
subscriptions : Model -> Sub Msg
subscriptions model =
Time.every Time.second Tick
view : Model -> Html.Html Msg
view model =
let
time =
Date.fromTime model
|> Date.Format.format "%H:%M:%S"
in
Html.h1 [] [ Html.text ("The time is " ++ time) ]