aboutsummaryrefslogtreecommitdiff
path: root/challenge-100/lance-wicks/elm/src/Fun.elm
blob: 2f9775c70be0d151fd3c4065dc61b26831cabc86 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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 ->
                ""