-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormatTimeTest.elm
68 lines (60 loc) · 1.75 KB
/
FormatTimeTest.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
module FormatTimeTest exposing (asRFC3339Test, formatTest, zeroPadIntTest)
import Expect
import FormatTime exposing (format, zeroPadInt)
import RFC3339 exposing (zulu)
import Test exposing (Test, describe, test)
import Time
formatTest : Test
formatTest =
test "format date"
(\_ ->
case
RFC3339.toPosix
{ date =
{ day = 18
, month = 3
, year = 2005
}
, time =
{ hours = 1
, minutes = 58
, seconds = 31
}
, offset = zulu
}
of
Just posix ->
format "%DD.%MM.%YYYY" Time.utc posix
|> Expect.equal (Ok "18.03.2005")
Nothing ->
Expect.fail "failed to get posix time"
)
zeroPadIntTest : Test
zeroPadIntTest =
describe "0 pad ints"
[ test "pad once"
(\_ ->
zeroPadInt 2 1
|> Expect.equal "01"
)
, test "pad to three digits"
(\_ ->
zeroPadInt 3 1
|> Expect.equal "001"
)
, test "no padding needed"
(\_ ->
zeroPadInt 4 1234
|> Expect.equal "1234"
)
]
asRFC3339Test : Test
asRFC3339Test =
describe "test RFC3339 formatting"
[ test "no offset"
(\_ ->
Time.millisToPosix 0
|> FormatTime.asRFC3339 Time.utc
|> Expect.equal (Ok "1970-01-01T00:00:00+00:00")
)
]