-
Notifications
You must be signed in to change notification settings - Fork 15
/
test.js
109 lines (88 loc) · 2 KB
/
test.js
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
104
105
106
107
108
109
'use strict'
const test = require('tape')
const parse = require('./')
test('date parser', function (t) {
t.equal(parse('garbage'), null)
t.equal(
parse('2010-12-11 09:09:04').toString(),
new Date('2010-12-11 09:09:04').toString()
)
t.equal(
parse('2011-12-11 09:09:04 BC').toString(),
new Date('-002010-12-11T09:09:04').toString()
)
t.equal(
parse('0001-12-11 09:09:04 BC').toString(),
new Date('0000-12-11T09:09:04').toString()
)
t.equal(
parse('0001-12-11 BC').getFullYear(),
0
)
t.equal(
parse('0013-06-01').getFullYear(),
13
)
t.equal(
parse('1800-06-01').getFullYear(),
1800
)
function ms (string) {
const base = '2010-01-01 01:01:01'
return parse(base + string).getMilliseconds()
}
t.equal(ms('.1'), 100)
t.equal(ms('.01'), 10)
t.equal(ms('.74'), 740)
function iso (string) {
return parse(string).toISOString()
}
t.equal(
iso('2010-12-11 09:09:04.1'),
new Date(2010, 11, 11, 9, 9, 4, 100).toISOString(),
'no timezones'
)
t.equal(
iso('2011-01-23 22:15:51.280843-06'),
'2011-01-24T04:15:51.280Z',
'huge ms value'
)
t.equal(
iso('2011-01-23 22:15:51Z'),
'2011-01-23T22:15:51.000Z',
'zulu time offset'
)
t.equal(
iso('2011-01-23 10:15:51-04'),
'2011-01-23T14:15:51.000Z',
'negative hour offset'
)
t.equal(
iso('2011-01-23 10:15:51+06:10'),
'2011-01-23T04:05:51.000Z',
'positive HH:mm offset'
)
t.equal(
iso('2011-01-23 10:15:51-06:10'),
'2011-01-23T16:25:51.000Z',
'negative HH:mm offset'
)
t.equal(
iso('0005-02-03 10:53:28+01:53:28'),
'0005-02-03T09:00:00.000Z',
'positive HH:mm:ss offset'
)
t.equal(
iso('0005-02-03 09:58:45-02:01:15'),
'0005-02-03T12:00:00.000Z',
'negative HH:mm:ss offset'
)
t.equal(
iso('0076-01-01 01:30:15+12'),
'0075-12-31T13:30:15.000Z',
'0 to 99 year boundary'
)
t.equal(parse('infinity'), Infinity)
t.equal(parse('-infinity'), -Infinity)
t.end()
})