blob: 30603cd194fd191d72d5391b6fe1120205aa9a62 (
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
module Update.UpdateTimer
( TimerAction(..)
, updateTimer
) where
import Time (Time)
import Model.Timer (..)
import Model.TimerState (..)
import Model.Id (..)
type TimerAction =
Rename String
| Pause
| ToggleRunning
| Stop
| SetTime Time
| SubstractTime Time
updateTimer : TimerAction -> Timer -> Timer
updateTimer action timer =
case action of
Rename name ->
{ timer | name <- Just name }
Pause ->
{ timer | state <- Idle }
ToggleRunning ->
if timer.state == Ringing
then
{ timer
| currentTime <- initTime timer.initialTime
, state <- Running
}
else
{ 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 <- time
, currentTime <- augmentedTime
}
SubstractTime time ->
if timer.state == Running
then
let newTime = timer.currentTime - time
in if newTime <= 0.0
then
{ timer
| currentTime <- 0.0
, state <- Ringing
}
else
{ timer | currentTime <- newTime }
else
timer
|