blob: c147d236fd8c62d0badbdb7be535654a5bf77ce9 (
plain)
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
|
module Update.UpdateTimer
( TimerAction(..)
, updateTimer
) where
import Time (Time)
import Model.Timer (..)
import Model.TimerState (..)
import Model.Id (..)
type TimerAction =
Restart
| Pause
| ToggleRunning
| Stop
| SetTime Time
updateTimer : TimerAction -> Timer -> Timer
updateTimer action timer =
case action of
Restart ->
{ timer
| currentTime <- initTime timer.initialTime
, state <- Running
}
Pause ->
{ timer | state <- Idle }
ToggleRunning ->
{ timer
| state <-
if timer.currentTime > 0 && timer.state == Idle
then Running
else Idle
}
Stop ->
{ timer
| currentTime <- initTime timer.initialTime
, state <- Idle
}
SetTime time ->
let augmentedTime = time + 999
in { timer
| initialTime <- augmentedTime
, currentTime <- augmentedTime
}
|