aboutsummaryrefslogtreecommitdiff
path: root/src/Timer/Update.elm
diff options
context:
space:
mode:
authorJoris2016-09-04 21:21:11 +0200
committerJoris2016-09-04 21:21:31 +0200
commit973a039b54327df74396605410ea9abe19c8a4e7 (patch)
treec702564d17e0a490d56845027238eb4f231be785 /src/Timer/Update.elm
parent62fee9133f36f655c1ed83e0c2e85394f9948bf5 (diff)
Upgrade to elm 0.17.1
Diffstat (limited to 'src/Timer/Update.elm')
-rw-r--r--src/Timer/Update.elm56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/Timer/Update.elm b/src/Timer/Update.elm
new file mode 100644
index 0000000..31e8a43
--- /dev/null
+++ b/src/Timer/Update.elm
@@ -0,0 +1,56 @@
+module Timer.Update exposing
+ ( updateTimer
+ )
+
+import Time exposing (Time)
+
+import Model.Id exposing (..)
+
+import Timer.Model exposing (..)
+import Timer.Model.State exposing (..)
+import Timer.Msg exposing (..)
+
+updateTimer : Msg -> Timer -> Timer
+updateTimer msg timer =
+ case msg of
+
+ Rename name ->
+ { timer | name = Just name }
+
+ Pause ->
+ { timer | state = Idle }
+
+ ToggleRunning ->
+ { timer
+ | state =
+ if timer.time > 0 && timer.state == Idle
+ then Running
+ else Idle
+ }
+
+ Stop ->
+ { timer
+ | time = timer.initialTime
+ , state = Idle
+ }
+
+ SetTime time ->
+ { timer
+ | initialTime = time
+ , time = time
+ }
+
+ SubstractTime time ->
+ if timer.state == Running
+ then
+ let newTime = timer.time - time
+ in if newTime <= 0.0
+ then
+ { timer
+ | time = 0.0
+ , state = Ringing
+ }
+ else
+ { timer | time = newTime }
+ else
+ timer