module Model.Timer ( Timer , initialTimer , substractTimerTime , initTime ) where import List import Time (Time) import Model.TimerState (..) type alias Timer = { creationTime : Time , name : String , initialTime : Time , currentTime : Time , state : TimerState } initialTimer : Time -> String -> Timer initialTimer creationTime name = let initialTime = 5 * 60 * 1000 in { creationTime = creationTime , name = name , initialTime = initialTime , currentTime = initTime initialTime , state = Idle } substractTimerTime : Time -> Timer -> Timer substractTimerTime time timer = 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 initTime : Time -> Time initTime t = t + 999