diff options
Diffstat (limited to 'src/Model')
-rw-r--r-- | src/Model/Id.elm | 5 | ||||
-rw-r--r-- | src/Model/IdGenerator.elm | 21 | ||||
-rw-r--r-- | src/Model/Model.elm | 32 | ||||
-rw-r--r-- | src/Model/Timer.elm | 40 |
4 files changed, 98 insertions, 0 deletions
diff --git a/src/Model/Id.elm b/src/Model/Id.elm new file mode 100644 index 0000000..c416804 --- /dev/null +++ b/src/Model/Id.elm @@ -0,0 +1,5 @@ +module Model.Id + ( Id + ) where + +type alias Id = Int diff --git a/src/Model/IdGenerator.elm b/src/Model/IdGenerator.elm new file mode 100644 index 0000000..8bce44f --- /dev/null +++ b/src/Model/IdGenerator.elm @@ -0,0 +1,21 @@ +module Model.IdGenerator + ( IdGenerator + , initialIdGenerator + , getId + ) where + +import Model.Id (..) + +type alias IdGenerator = + { counter : Id + } + +initialIdGenerator = + { counter = 0 + } + +getId : IdGenerator -> (Id, IdGenerator) +getId idGenerator = + ( idGenerator.counter + , { idGenerator | counter <- idGenerator.counter + 1 } + ) diff --git a/src/Model/Model.elm b/src/Model/Model.elm new file mode 100644 index 0000000..fa97d7b --- /dev/null +++ b/src/Model/Model.elm @@ -0,0 +1,32 @@ +module Model.Model + ( Model + , initialModel + , substractTimersTime + ) where + +import Dict (Dict) +import Dict +import Time (Time) + +import Model.Timer (..) +import Model.Id (..) +import Model.IdGenerator (..) + +type alias Model = + { currentTime : Time + , newTimerName : String + , timers : Dict Id Timer + , timerIdGenerator : IdGenerator + } + +initialModel : Time -> Model +initialModel initialTime = + { currentTime = initialTime + , newTimerName = "" + , timers = Dict.empty + , timerIdGenerator = initialIdGenerator + } + +substractTimersTime : Time -> Dict Id Timer -> Dict Id Timer +substractTimersTime t timers = + Dict.map (\id timer -> substractTimerTime t timer) timers diff --git a/src/Model/Timer.elm b/src/Model/Timer.elm new file mode 100644 index 0000000..ddbe97b --- /dev/null +++ b/src/Model/Timer.elm @@ -0,0 +1,40 @@ +module Model.Timer + ( Timer + , initialTimer + , substractTimerTime + ) where + +import List +import Time (Time) + +type alias Timer = + { creationTime : Time + , name : String + , time : Time + , isRunning : Bool + } + +initialTimer : Time -> String -> Timer +initialTimer creationTime name = + { creationTime = creationTime + , name = name + , time = 5 * 60 * 1000 + , isRunning = True + } + +substractTimerTime : Time -> Timer -> Timer +substractTimerTime time timer = + if timer.isRunning + then + if timer.time - time <= 0.0 + then + { timer + | time <- 0.0 + , isRunning <- False + } + else + { timer + | time <- timer.time - time + } + else + timer |