diff options
author | Joris Guyonvarch | 2015-03-22 12:53:55 +0100 |
---|---|---|
committer | Joris Guyonvarch | 2015-03-22 12:53:55 +0100 |
commit | 2abb8ffa46cbe86deedb9ddcbb9b042b51285feb (patch) | |
tree | 3756c16ccdf8b61000767637db0807f3d40e12cc /src/Model/TimerEdition.elm | |
parent | ce4580451def7e86d0f67d2c353ac65239e17fd1 (diff) |
Editing name first draft
Diffstat (limited to 'src/Model/TimerEdition.elm')
-rw-r--r-- | src/Model/TimerEdition.elm | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/src/Model/TimerEdition.elm b/src/Model/TimerEdition.elm deleted file mode 100644 index 2ec98b7..0000000 --- a/src/Model/TimerEdition.elm +++ /dev/null @@ -1,77 +0,0 @@ -module Model.TimerEdition - ( TimerEdition - , Numbers - , newTimerEdition - , keyCodeToNumberChar - , toTime - , toMinutesAndSeconds - ) where - -import Time (Time) -import List -import Array -import String -import Keyboard (KeyCode) - -import Model.Id (..) - -import Utils.List (..) -import Utils.Maybe (..) - -type alias TimerEdition = - { id : Id - , numbers : Numbers - } - -type alias Numbers = List Char - -newTimerEdition id = - { id = id - , numbers = [] - } - -keyCodeToNumberChar : KeyCode -> Maybe Char -keyCodeToNumberChar code = - List.map (flip keyCodeToCharFromZero code) zeroKeyCodes - |> List.foldl orElse Nothing - -zeroKeyCodes = [48, 96] - -keyCodeToCharFromZero : KeyCode -> KeyCode -> Maybe Char -keyCodeToCharFromZero zero code = - let nine = zero + 9 - in if code >= zero && code <= nine - then ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] - |> Array.fromList - |> Array.get (code - zero) - else Nothing - -toTime : Numbers -> Time -toTime numbers = - numbers - |> toMinutesAndSeconds - |> \(a, b) -> (stringToInt a, stringToInt b) - |> \(minutes, seconds) -> (toFloat minutes) * 60 * 1000 + (toFloat seconds) * 1000 - -toMinutesAndSeconds : Numbers -> (String, String) -toMinutesAndSeconds numbers = - numbers - |> List.take 4 - |> List.reverse - |> completeBegin '0' 4 - |> splitAt 2 - |> \(a, b) -> (String.fromList a, String.fromList b) - -completeBegin : a -> Int -> List a -> List a -completeBegin x count xs = - let length = List.length xs - in List.append (repeat (count - length) x) xs - -stringToInt : String -> Int -stringToInt str = - str - |> String.toInt - |> \res -> - case res of - Ok n -> n - Err _ -> 0 |