aboutsummaryrefslogtreecommitdiff
path: root/src/Timer/Update.elm
blob: 31e8a432cc1f0d76f7d7a76152fdd5db11e7ddde (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
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