module Update.UpdateTimer ( TimerAction(..) , updateTimer ) where import Time exposing (Time) import Model.Timer exposing (..) import Model.TimerState exposing (..) import Model.Id exposing (..) 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 -> { timer | state <- if timer.currentTime > 0 && timer.state == Idle then Running else Idle } Stop -> { timer | currentTime <- timer.initialTime , state <- Idle } SetTime time -> { timer | initialTime <- time , currentTime <- time } 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