aboutsummaryrefslogtreecommitdiff
path: root/src/Timer/Update.elm
diff options
context:
space:
mode:
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