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