diff options
| author | Lance Wicks <lw@judocoach.com> | 2021-02-16 22:39:44 +0000 |
|---|---|---|
| committer | Lance Wicks <lw@judocoach.com> | 2021-02-16 22:39:44 +0000 |
| commit | 57946966fba6bceb8806cbc02990bfefce5e5655 (patch) | |
| tree | c46c9449c2b133a3a63596c63adec7086ab1a76a | |
| parent | 57de16724cb81ee354f2fe81d633c9122259ef4a (diff) | |
| download | perlweeklychallenge-club-57946966fba6bceb8806cbc02990bfefce5e5655.tar.gz perlweeklychallenge-club-57946966fba6bceb8806cbc02990bfefce5e5655.tar.bz2 perlweeklychallenge-club-57946966fba6bceb8806cbc02990bfefce5e5655.zip | |
Adding an (ugly) elm implementation
| -rw-r--r-- | challenge-100/lance-wicks/elm/elm.json | 28 | ||||
| -rw-r--r-- | challenge-100/lance-wicks/elm/src/Fun.elm | 69 | ||||
| -rw-r--r-- | challenge-100/lance-wicks/elm/tests/Example.elm | 40 |
3 files changed, 137 insertions, 0 deletions
diff --git a/challenge-100/lance-wicks/elm/elm.json b/challenge-100/lance-wicks/elm/elm.json new file mode 100644 index 0000000000..7468f5e5cd --- /dev/null +++ b/challenge-100/lance-wicks/elm/elm.json @@ -0,0 +1,28 @@ +{ + "type": "application", + "source-directories": [ + "src" + ], + "elm-version": "0.19.1", + "dependencies": { + "direct": { + "elm/browser": "1.0.2", + "elm/core": "1.0.5", + "elm/html": "1.0.0" + }, + "indirect": { + "elm/json": "1.1.3", + "elm/time": "1.0.0", + "elm/url": "1.0.0", + "elm/virtual-dom": "1.0.2" + } + }, + "test-dependencies": { + "direct": { + "elm-explorations/test": "1.2.2" + }, + "indirect": { + "elm/random": "1.0.0" + } + } +} diff --git a/challenge-100/lance-wicks/elm/src/Fun.elm b/challenge-100/lance-wicks/elm/src/Fun.elm new file mode 100644 index 0000000000..2f9775c70b --- /dev/null +++ b/challenge-100/lance-wicks/elm/src/Fun.elm @@ -0,0 +1,69 @@ +module Fun exposing (convert) + + +convert : String -> String +convert time = + if String.contains "am" time then + String.slice 0 5 time + + else if String.contains "pm" time then + let + hourMin = + String.split ":" time + in + case List.head hourMin of + Just a -> + let + hour = + String.toInt a + in + case hour of + Just h -> + let + hx = + h + 12 + in + String.fromInt hx ++ String.slice 2 5 time + + Nothing -> + "" + + Nothing -> + "" + + else + let + hourMin = + String.split ":" time + in + case List.head hourMin of + Just a -> + let + hour = + String.toInt a + in + case hour of + Just h -> + if h > 12 then + let + hx = + h - 12 + in + let + hourStr = + String.fromInt hx + in + if String.length hourStr > 1 then + hourStr ++ String.slice 2 5 time ++ "pm" + + else + "0" ++ hourStr ++ String.slice 2 5 time ++ "pm" + + else + String.slice 0 5 time ++ "am" + + Nothing -> + "" + + Nothing -> + "" diff --git a/challenge-100/lance-wicks/elm/tests/Example.elm b/challenge-100/lance-wicks/elm/tests/Example.elm new file mode 100644 index 0000000000..64c70d1337 --- /dev/null +++ b/challenge-100/lance-wicks/elm/tests/Example.elm @@ -0,0 +1,40 @@ +module Example exposing (..) + +import Expect exposing (Expectation) +import Fun exposing (convert) +import Fuzz exposing (Fuzzer, int, list, string) +import Test exposing (..) + + +suite : Test +suite = + describe "Fun" + [ test "convert 07:15" <| + \_ -> + let + got = + convert "07:15" + in + Expect.equal got "07:15am" + , test "convert 05:15pm" <| + \_ -> + let + got = + convert "05:15 pm" + in + Expect.equal got "17:15" + , test "convert 19:15" <| + \_ -> + let + got = + convert "19:15" + in + Expect.equal got "07:15pm" + , test "convert 09:15" <| + \_ -> + let + got = + convert "09:15 am" + in + Expect.equal got "09:15" + ] |
