-
Notifications
You must be signed in to change notification settings - Fork 13
/
test.js
167 lines (161 loc) · 6.3 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
var hdate = require('./humandate.js')
var assert = require('assert')
describe('relativeTime', function () {
describe('future', function () {
it('should work with an integer', function () {
assert.equal(hdate.relativeTime(122158874), '3 years from now')
})
it('should work with an very small integer', function () {
assert.equal(hdate.relativeTime(5), '5 seconds from now')
})
it('should work with a string', function () {
assert.equal(typeof hdate.relativeTime('8-16-2020'), 'string')
})
it('should work with a date object', function () {
assert.equal(typeof hdate.relativeTime(new Date('8-16-2020')), 'string')
})
})
describe('past', function () {
it('should work with an integer', function () {
assert.equal(hdate.relativeTime(-122158874), '3 years ago')
})
it('should work with a string', function () {
assert.equal(typeof hdate.relativeTime('8-16-1987'), 'string')
})
it('should work with a date object', function () {
assert.equal(typeof hdate.relativeTime(new Date('8-16-1987')), 'string')
})
})
describe('present', function () {
it('should work with an integer', function () {
assert.equal(hdate.relativeTime(0), 'now')
})
it('should work with a date object', function () {
assert.equal(hdate.relativeTime(new Date()), 'now')
})
it('should work with a string', function () {
assert.equal(hdate.relativeTime(new Date().toString()), 'now');
});
})
describe('options', function () {
it('should work with an optional future suffix', function () {
assert.equal(hdate.relativeTime(4, { futureSuffix: 'in the future' }), '4 seconds in the future')
})
it('should work with an optional past suffix', function () {
assert.equal(hdate.relativeTime(-4, { pastSuffix: 'in the past' }), '4 seconds in the past')
})
it('should work with an optional present text', function () {
assert.equal(hdate.relativeTime(0, { presentText: 'a moment ago' }), 'a moment ago')
})
it('should work returning an object', function () {
assert.equal(typeof hdate.relativeTime(-4, { returnObject: true }), 'object')
})
it('should work with all units option', function () {
assert.equal(hdate.relativeTime(75, { allUnits: true }), '1 minute, 15 seconds from now')
})
})
})
describe('prettyPrint', function () {
describe('future', function () {
it('should work with no input', function () {
assert.equal(typeof hdate.prettyPrint(), 'string')
})
it('should work with a number', function () {
assert.equal(typeof hdate.prettyPrint(7862), 'string')
})
it('should work with a string', function () {
assert.equal(hdate.prettyPrint('8-16-2020'), 'August 16th, 2020')
})
it('should work with a date object', function () {
assert.equal(hdate.prettyPrint(new Date('8-16-2020')), 'August 16th, 2020')
})
})
describe('past', function () {
it('should work with a string', function () {
assert.equal(hdate.prettyPrint('8-16-1987'), 'August 16th, 1987')
})
it('should work with a date object', function () {
assert.equal(hdate.prettyPrint(new Date('8-16-1987')), 'August 16th, 1987')
})
})
describe('options', function () {
it('should work when showing time', function () {
var timestamp = hdate.toUTC(new Date(1416448704578))
assert.equal(hdate.prettyPrint(timestamp, { showTime: true }), 'November 20th, 2014 at 1:58 am')
})
it('should abbreviate month when specififed', function() {
var timestamp = hdate.toUTC(new Date(1416448704578))
assert.equal(hdate.prettyPrint(timestamp, { showTime: true, monthAbbreviated: true }), 'Nov 20th, 2014 at 1:58 am')
})
})
describe('suffixes', function () {
it('should work with st', function () {
assert.equal(hdate.prettyPrint(new Date('8-1-1987')), 'August 1st, 1987')
})
it('should work with nd', function () {
assert.equal(hdate.prettyPrint(new Date('8-2-1987')), 'August 2nd, 1987')
})
it('should work with rd', function () {
assert.equal(hdate.prettyPrint(new Date('8-3-1987')), 'August 3rd, 1987')
})
it('should work with th', function () {
assert.equal(hdate.prettyPrint(new Date('8-30-1987')), 'August 30th, 1987')
})
})
})
describe('monthName', function () {
it('should work with an integer', function () {
assert.equal(hdate.monthName(8), 'August')
})
it('should work with a string', function () {
assert.equal(hdate.monthName('5-22-2012'), 'May')
})
it('should work with a date object', function () {
assert.equal(hdate.monthName(new Date('7-4-2012')), 'July')
})
it('should abbreviate with an integer', function() {
assert.equal(hdate.monthName(10, true), 'Oct')
})
it('should abbreviate with a string', function() {
assert.equal(hdate.monthName('1-01-2012', true), 'Jan')
})
it('should abbreviate with a date object', function() {
assert.equal(hdate.monthName(new Date('11-11-2011'),true), 'Nov')
})
})
describe('toUTC', function () {
it('should work with nothing', function () {
assert.equal(Object.prototype.toString.call(hdate.toUTC()), '[object Date]')
})
it('should work with a string', function () {
assert.equal(Object.prototype.toString.call(hdate.toUTC('5-22-2012')), '[object Date]')
})
it('should work with a date object', function () {
assert.equal(Object.prototype.toString.call(hdate.toUTC(new Date('7-4-2012'))), '[object Date]')
})
it('should work with a timestamp', function () {
assert.equal(Object.prototype.toString.call(hdate.toUTC(1000000000000)), '[object Date]')
})
})
describe('monthName', function () {
it('should work with an integer', function () {
assert.equal(hdate.monthName(8), 'August')
})
it('should work with a string', function () {
assert.equal(hdate.monthName('5-22-2012'), 'May')
})
it('should work with a date object', function () {
assert.equal(hdate.monthName(new Date('7-4-2012')), 'July')
})
})
describe('validDate', function () {
it('should work with an integer', function () {
assert.equal(hdate.monthName(8), 'August')
})
it('should work with a string', function () {
assert.equal(hdate.monthName('5-22-2012'), 'May')
})
it('should work with a date object', function () {
assert.equal(hdate.monthName(new Date('7-4-2012')), 'July')
})
})