forked from elm-community/elm-time
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInternal.elm
72 lines (51 loc) · 1.13 KB
/
Internal.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
module Time.Internal exposing (DateTimeData, TimeData, dayMs, hourMs, minuteMs, offsetFromTimeData, padded, padded3, secondMs, zero)
type alias DateTimeData =
{ year : Int
, month : Int
, day : Int
, hour : Int
, minute : Int
, second : Int
, millisecond : Int
}
type alias TimeData d =
{ d
| hour : Int
, minute : Int
, second : Int
, millisecond : Int
}
offsetFromTimeData : TimeData d -> Int
offsetFromTimeData { hour, minute, second, millisecond } =
clamp 0 23 hour * hourMs + clamp 0 59 minute * minuteMs + clamp 0 59 second * secondMs + clamp 0 999 millisecond
zero : DateTimeData
zero =
{ year = 0
, month = 1
, day = 1
, hour = 0
, minute = 0
, second = 0
, millisecond = 0
}
padded : Int -> String
padded n =
if n < 10 then
"0" ++ String.fromInt n
else
String.fromInt n
padded3 : Int -> String
padded3 n =
String.padLeft 3 '0' (String.fromInt n)
dayMs : number
dayMs =
86400000
hourMs : number
hourMs =
3600000
minuteMs : number
minuteMs =
60000
secondMs : number
secondMs =
1000