aboutsummaryrefslogtreecommitdiff
path: root/src/Update/UpdateTimer.elm
blob: e4671d9efa29480c4ca9012049081866f7785970 (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
module Update.UpdateTimer
  ( TimerAction(..)
  , updateTimer
  ) where

import Time (Time)

import Model.Timer (..)
import Model.Id (..)

type TimerAction =
  Restart
  | Pause
  | ToggleRunning
  | Stop
  | SetTime Time

updateTimer : TimerAction -> Timer -> Timer
updateTimer action timer =
  case action of
    Restart ->
      { timer
      | isRunning <- True
      , currentTime <- initTime timer.initialTime
      }
    Pause ->
      { timer
      | isRunning <- False
      }
    ToggleRunning ->
      { timer | isRunning <- timer.currentTime > 0.0 && not timer.isRunning }
    Stop ->
      { timer
      | isRunning <- False
      , currentTime <- initTime timer.initialTime
      }
    SetTime time ->
      let augmentedTime = time + 999
      in  { timer
          | initialTime <- augmentedTime
          , currentTime <- augmentedTime
          }