1module Time.Ext exposing (decoder, default, encode, monthName, monthNumber)
2
3import Json.Decode as Decode exposing (Decoder)
4import Json.Encode as Json
5import Time exposing (Month(..))
6
7
8
9-- 🔱
10
11
12decoder : Decoder Time.Posix
13decoder =
14 Decode.map Time.millisToPosix Decode.int
15
16
17default : Time.Posix
18default =
19 Time.millisToPosix 0
20
21
22encode : Time.Posix -> Json.Value
23encode time =
24 Json.int (Time.posixToMillis time)
25
26
27monthName : Time.Month -> String
28monthName month =
29 case month of
30 Jan ->
31 "January"
32
33 Feb ->
34 "February"
35
36 Mar ->
37 "March"
38
39 Apr ->
40 "April"
41
42 May ->
43 "May"
44
45 Jun ->
46 "June"
47
48 Jul ->
49 "July"
50
51 Aug ->
52 "August"
53
54 Sep ->
55 "September"
56
57 Oct ->
58 "October"
59
60 Nov ->
61 "November"
62
63 Dec ->
64 "December"
65
66
67monthNumber : Time.Month -> Int
68monthNumber month =
69 case month of
70 Jan ->
71 1
72
73 Feb ->
74 2
75
76 Mar ->
77 3
78
79 Apr ->
80 4
81
82 May ->
83 5
84
85 Jun ->
86 6
87
88 Jul ->
89 7
90
91 Aug ->
92 8
93
94 Sep ->
95 9
96
97 Oct ->
98 10
99
100 Nov ->
101 11
102
103 Dec ->
104 12