-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHost.elm
103 lines (73 loc) · 1.65 KB
/
Host.elm
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
module Host exposing
( Appointment
, apptToJson
, HostId
, Hosts
, readApointmentsResponse
, readHostResponse
)
import Dict exposing (..)
import Json.Decode as D
import Json.Encode as E
import Time exposing (..)
type alias HostId =
String
type alias Name =
String
type alias Hosts =
Dict HostId Name
type alias Appointment =
{ hostId : HostId
, start : Int
, duration : Int
}
readAppointment : D.Decoder Appointment
readAppointment =
D.map3 Appointment
(D.field "hostId" D.string)
(D.field "start" D.int)
(D.field "duration" D.int)
apptToJson : Appointment -> D.Value
apptToJson appt = E.object
[ ("hostId", E.string appt.hostId)
, ("start", E.int appt.start)
, ("duration", E.int appt.duration)
]
readApointmentsResponse : D.Decoder (List Appointment)
readApointmentsResponse =
D.list readAppointment
readHostResponse : D.Decoder Hosts
readHostResponse =
D.dict D.string
millsSinceMonday : Zone -> Posix -> Int
millsSinceMonday z t =
case toWeekday z t of
Mon ->
0
Tue ->
1
Wed ->
2
Thu ->
3
Fri ->
4
Sat ->
5
Sun ->
6
startOfMonday : Zone -> Posix -> Posix
startOfMonday z t =
let
hs =
1000 * 60 * 60 * toHour z t
m =
1000 * 60 * toMinute z t
s =
1000 * toSecond z t
ms =
toMillis z t
offset =
86400000 * millsSinceMonday z t
in
millisToPosix <| posixToMillis t - (hs + m + s + ms + offset)