blob: ad1e9da34e7eeb52ef063a33410fdd7e9c9154b8 (
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
|
module Model.Model
( Model
, initialModel
, substractTimersTime
, numberOfTimers
) where
import Dict (Dict)
import Dict
import Time (Time)
import List
import Model.Timer (..)
import Model.TimerEdition (..)
import Model.Id (..)
import Model.IdGenerator (..)
type alias Model =
{ currentTime : Time
, timers : Dict Id Timer
, timerIdGenerator : IdGenerator
, timerEdition : Maybe TimerEdition
}
initialModel : Time -> Model
initialModel initialTime =
let (id, idGenerator) = getId initialIdGenerator
timerName = "Timer " ++ (toString id)
in { currentTime = initialTime
, timers = Dict.insert id (initialTimer initialTime timerName) Dict.empty
, timerIdGenerator = idGenerator
, timerEdition = Nothing
}
substractTimersTime : Time -> Dict Id Timer -> Dict Id Timer
substractTimersTime t timers =
Dict.map (\id timer -> substractTimerTime t timer) timers
numberOfTimers : Model -> Int
numberOfTimers = List.length << Dict.toList << .timers
|