From 973a039b54327df74396605410ea9abe19c8a4e7 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 4 Sep 2016 21:21:11 +0200 Subject: Upgrade to elm 0.17.1 --- src/Edition/Model/Name.elm | 19 +++++++++++++++++ src/Edition/Model/Time.elm | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/Edition/Model/Name.elm create mode 100644 src/Edition/Model/Time.elm (limited to 'src/Edition/Model') diff --git a/src/Edition/Model/Name.elm b/src/Edition/Model/Name.elm new file mode 100644 index 0000000..19f4c04 --- /dev/null +++ b/src/Edition/Model/Name.elm @@ -0,0 +1,19 @@ +module Edition.Model.Name exposing + ( keyCodeToChar + , renderNameEdition + ) + +import Char +import String +import List + +import Model.Keyboard exposing (KeyCode) + +keyCodeToChar : KeyCode -> Maybe Char +keyCodeToChar = Just << Char.fromCode + +renderNameEdition : List Char -> String +renderNameEdition chars = + chars + |> List.reverse + |> String.fromList diff --git a/src/Edition/Model/Time.elm b/src/Edition/Model/Time.elm new file mode 100644 index 0000000..35971c3 --- /dev/null +++ b/src/Edition/Model/Time.elm @@ -0,0 +1,52 @@ +module Edition.Model.Time exposing + ( keyCodeToChar + , toTime + , toMinutesAndSeconds + ) + +import Time exposing (Time) +import List +import Array +import String +import Char + +import Model.Keyboard exposing (KeyCode) +import Utils.List exposing (..) +import Utils.Maybe exposing (..) + +keyCodeToChar : KeyCode -> Maybe Char +keyCodeToChar code = + let char = Char.fromCode code + in if Char.isDigit char + then Just char + else Nothing + +toTime : List Char -> Time +toTime numbers = + numbers + |> toMinutesAndSeconds + |> \(a, b) -> (stringToInt a, stringToInt b) + |> \(minutes, seconds) -> (toFloat minutes) * 60 * 1000 + (toFloat seconds) * 1000 + +toMinutesAndSeconds : List Char -> (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 -- cgit v1.2.3