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
|
/*
Unit test for dates
*/
assert = chai.assert;
// Tests private Modules.ISODate object
// Modules.ISODate is unit tested as it has an interface access by other modules
describe('Modules.ISODates', function() {
it('constructor', function(){
assert.equal( new Modules.ISODate().toString('auto'), '' );
assert.equal( new Modules.ISODate('2015-01-23T05:34:00', 'html5').toString('html5'), '2015-01-23 05:34:00' );
assert.equal( new Modules.ISODate('2015-01-23T05:34:00', 'w3c').toString('w3c'), '2015-01-23T05:34:00' );
assert.equal( new Modules.ISODate('2015-01-23T05:34:00', 'html5').toString('rfc3339'), '20150123T053400' );
assert.equal( new Modules.ISODate('2015-01-23T05:34:00', 'auto').toString('auto'), '2015-01-23T05:34:00' );
});
it('parse', function(){
assert.equal( new Modules.ISODate().parse('2015-01-23T05:34:00', 'html5').toString('html5'), '2015-01-23 05:34:00' );
assert.equal( new Modules.ISODate().parse('2015-01-23T05:34:00', 'auto').toString('auto'), '2015-01-23T05:34:00' );
assert.equal( new Modules.ISODate().parse('2015-01-23t05:34:00', 'auto').toString('auto'), '2015-01-23t05:34:00' );
assert.equal( new Modules.ISODate().parse('2015-01-23t05:34:00Z', 'auto').toString('auto'), '2015-01-23t05:34:00Z' );
assert.equal( new Modules.ISODate().parse('2015-01-23t05:34:00z', 'auto').toString('auto'), '2015-01-23t05:34:00z' );
assert.equal( new Modules.ISODate().parse('2015-01-23 05:34:00Z', 'auto').toString('auto'), '2015-01-23 05:34:00Z' );
assert.equal( new Modules.ISODate().parse('2015-01-23 05:34', 'auto').toString('auto'), '2015-01-23 05:34' );
assert.equal( new Modules.ISODate().parse('2015-01-23 05', 'auto').toString('auto'), '2015-01-23 05' );
assert.equal( new Modules.ISODate().parse('2015-01-23 05:34+01:00', 'auto').toString('auto'), '2015-01-23 05:34+01:00' );
assert.equal( new Modules.ISODate().parse('2015-01-23 05:34-01:00', 'auto').toString('auto'), '2015-01-23 05:34-01:00' );
assert.equal( new Modules.ISODate().parse('2015-01-23 05:34-01', 'auto').toString('auto'), '2015-01-23 05:34-01' );
assert.equal( new Modules.ISODate().parse('2015-01-23', 'auto').toString('auto'), '2015-01-23' );
// TODO support for importing rfc3339 profile dates
// assert.equal( new Modules.ISODate().parse('20150123t0534', 'auto').toString('auto'), '2015-01-23 05:34' );
});
it('parseDate', function(){
assert.equal( new Modules.ISODate().parseDate('2015-01-23T05:34:00', 'html5'), '2015-01-23' );
assert.equal( new Modules.ISODate().parseDate('2015-01-23', 'auto'), '2015-01-23' );
assert.equal( new Modules.ISODate().parseDate('2015-01', 'auto'), '2015-01' );
assert.equal( new Modules.ISODate().parseDate('2015', 'auto'), '2015' );
assert.equal( new Modules.ISODate().parseDate('2015-134', 'auto'), '2015-134' );
});
it('parseTime', function(){
assert.equal( new Modules.ISODate().parseTime('05:34:00.1267', 'html5'), '05:34:00.1267' );
assert.equal( new Modules.ISODate().parseTime('05:34:00', 'html5'), '05:34:00' );
assert.equal( new Modules.ISODate().parseTime('05:34', 'html5'), '05:34' );
assert.equal( new Modules.ISODate().parseTime('05', 'html5'), '05' );
});
it('parseTimeZone', function(){
var date = new Modules.ISODate();
date.parseTime('14:00');
assert.equal( date.parseTimeZone('-01:00', 'auto'), '14:00-01:00' );
date.clear();
date.parseTime('14:00');
assert.equal( date.parseTimeZone('-01', 'auto'), '14:00-01' );
date.clear();
date.parseTime('14:00');
assert.equal( date.parseTimeZone('+01:00', 'auto').toString('auto'), '14:00+01:00' );
date.clear();
date.parseTime('15:00');
assert.equal( date.parseTimeZone('Z', 'auto').toString('auto'), '15:00Z' );
date.clear();
date.parseTime('16:00');
assert.equal( date.parseTimeZone('z', 'auto'), '16:00z' );
});
it('toString', function(){
var date = new Modules.ISODate();
date.parseTime('05:34:00.1267');
assert.equal( date.toString('html5'), '05:34:00.1267' );
});
it('toTimeString', function(){
var date = new Modules.ISODate();
date.parseTime('05:34:00.1267');
assert.equal( date.toTimeString('html5'), '05:34:00.1267' );
});
it('hasFullDate', function(){
var dateEmpty = new Modules.ISODate(),
date = new Modules.ISODate('2015-01-23T05:34:00');
assert.isFalse( dateEmpty.hasFullDate() );
assert.isTrue( date.hasFullDate() );
});
it('hasDate', function(){
var dateEmpty = new Modules.ISODate(),
date = new Modules.ISODate('2015-01-23');
assert.isFalse( dateEmpty.hasDate() );
assert.isTrue( date.hasDate() );
});
it('hasTime', function(){
var dateEmpty = new Modules.ISODate(),
date = new Modules.ISODate();
date.parseTime('12:34');
assert.isFalse( dateEmpty.hasTime() );
assert.isTrue( date.hasTime() );
});
it('hasTimeZone', function(){
var dateEmpty = new Modules.ISODate(),
date = new Modules.ISODate();
date.parseTime('12:34'),
date.parseTimeZone('-01:00');
assert.isFalse( dateEmpty.hasTimeZone() );
assert.isTrue( date.hasTimeZone() );
});
});
|