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 -> 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