@@ -63,34 +63,132 @@ define( [
63
63
} ,
64
64
65
65
/**
66
- * Tests the effect of the private pad() function, relevant in getSortKey () and toJSON ().
66
+ * Tests the effect of the private pad() function, relevant in toJSON () and getSortKey ().
67
67
*
68
68
* @since 0.7
69
69
*
70
70
* @param {QUnit } assert
71
71
*/
72
72
testPad : function ( assert ) {
73
73
var testCases = {
74
- '-123456789012-00-00T00:00:00Z' : '-123456789012-00-00T00:00:00Z' ,
75
- '-12345678901-00-00T00:00:00Z' : '-12345678901-00-00T00:00:00Z' ,
76
- '-1-1-1T01:01:01Z' : '-00000000001-01-01T01:01:01Z' ,
77
- '1-1-1T01:01:01Z' : '+00000000001-01-01T01:01:01Z' ,
78
- '12-00-00T00:00:00Z' : '+00000000012-00-00T00:00:00Z' ,
79
- '1234567890-00-00T00:00:00Z' : '+01234567890-00-00T00:00:00Z' ,
80
- '12345678901-00-00T00:00:00Z' : '+12345678901-00-00T00:00:00Z' ,
81
- '123456789012-00-00T00:00:00Z' : '+123456789012-00-00T00:00:00Z' ,
82
- '1234567890123456-00-00T00:00:00Z' : '+1234567890123456-00-00T00:00:00Z'
74
+ // Without leading zeros
75
+ '-9000000000000000-12-31T23:59:59Z' : [
76
+ '-9000000000000000-12-31T23:59:59Z' ,
77
+ '-9000000000000000-12-31T23:59:59Z'
78
+ ] ,
79
+ '-123456789012-00-00T00:00:00Z' : [
80
+ '-123456789012-00-00T00:00:00Z' ,
81
+ '-0000123456789012-00-00T00:00:00Z'
82
+ ] ,
83
+ '-12345678901-00-00T00:00:00Z' : [
84
+ '-12345678901-00-00T00:00:00Z' ,
85
+ '-0000012345678901-00-00T00:00:00Z'
86
+ ] ,
87
+ '-1234-1-1T01:01:01Z' : [
88
+ '-1234-01-01T01:01:01Z' ,
89
+ '-0000000000001234-01-01T01:01:01Z'
90
+ ] ,
91
+ '-123-1-1T01:01:01Z' : [
92
+ '-0123-01-01T01:01:01Z' ,
93
+ '-0000000000000123-01-01T01:01:01Z'
94
+ ] ,
95
+ '-12-1-1T01:01:01Z' : [
96
+ '-0012-01-01T01:01:01Z' ,
97
+ '-0000000000000012-01-01T01:01:01Z'
98
+ ] ,
99
+ '-1-1-1T01:01:01Z' : [
100
+ '-0001-01-01T01:01:01Z' ,
101
+ '-0000000000000001-01-01T01:01:01Z'
102
+ ] ,
103
+ '0-1-1T01:01:01Z' : [
104
+ '+0000-01-01T01:01:01Z' ,
105
+ '+0000000000000000-01-01T01:01:01Z'
106
+ ] ,
107
+ '1-1-1T01:01:01Z' : [
108
+ '+0001-01-01T01:01:01Z' ,
109
+ '+0000000000000001-01-01T01:01:01Z'
110
+ ] ,
111
+ '12-00-00T00:00:00Z' : [
112
+ '+0012-00-00T00:00:00Z' ,
113
+ '+0000000000000012-00-00T00:00:00Z'
114
+ ] ,
115
+ '123-00-00T00:00:00Z' : [
116
+ '+0123-00-00T00:00:00Z' ,
117
+ '+0000000000000123-00-00T00:00:00Z'
118
+ ] ,
119
+ '1234-00-00T00:00:00Z' : [
120
+ '+1234-00-00T00:00:00Z' ,
121
+ '+0000000000001234-00-00T00:00:00Z'
122
+ ] ,
123
+ '1234567890-00-00T00:00:00Z' : [
124
+ '+1234567890-00-00T00:00:00Z' ,
125
+ '+0000001234567890-00-00T00:00:00Z'
126
+ ] ,
127
+ '12345678901-00-00T00:00:00Z' : [
128
+ '+12345678901-00-00T00:00:00Z' ,
129
+ '+0000012345678901-00-00T00:00:00Z'
130
+ ] ,
131
+ '123456789012-00-00T00:00:00Z' : [
132
+ '+123456789012-00-00T00:00:00Z' ,
133
+ '+0000123456789012-00-00T00:00:00Z'
134
+ ] ,
135
+ '1234567890123456-00-00T00:00:00Z' : [
136
+ '+1234567890123456-00-00T00:00:00Z' ,
137
+ '+1234567890123456-00-00T00:00:00Z'
138
+ ] ,
139
+ '9000000000000000-12-31T23:59:59Z' : [
140
+ '+9000000000000000-12-31T23:59:59Z' ,
141
+ '+9000000000000000-12-31T23:59:59Z'
142
+ ] ,
143
+
144
+ // With leading zeros
145
+ '-0900000000000000-12-31T23:59:59Z' : [
146
+ '-900000000000000-12-31T23:59:59Z' ,
147
+ '-0900000000000000-12-31T23:59:59Z'
148
+ ] ,
149
+ '-0000000000000123-01-01T01:01:01Z' : [
150
+ '-0123-01-01T01:01:01Z' ,
151
+ '-0000000000000123-01-01T01:01:01Z'
152
+ ] ,
153
+ '+0000000000000000-01-01T01:01:01Z' : [
154
+ '+0000-01-01T01:01:01Z' ,
155
+ '+0000000000000000-01-01T01:01:01Z'
156
+ ] ,
157
+ '+0000000000000001-01-01T01:01:01Z' : [
158
+ '+0001-01-01T01:01:01Z' ,
159
+ '+0000000000000001-01-01T01:01:01Z'
160
+ ] ,
161
+ '+0900000000000000-12-31T23:59:59Z' : [
162
+ '+900000000000000-12-31T23:59:59Z' ,
163
+ '+0900000000000000-12-31T23:59:59Z'
164
+ ] ,
165
+
166
+ // Year would become 10000000000000000 when parsed as a number
167
+ '-9999999999999999-12-31T23:59:59Z' : [
168
+ '-9999999999999999-12-31T23:59:59Z' ,
169
+ '-9999999999999999-12-31T23:59:59Z'
170
+ ] ,
171
+ '9999999999999999-12-31T23:59:59Z' : [
172
+ '+9999999999999999-12-31T23:59:59Z' ,
173
+ '+9999999999999999-12-31T23:59:59Z'
174
+ ]
83
175
} ;
84
176
85
- for ( var iso8601 in testCases ) {
86
- var expected = testCases [ iso8601 ] ,
87
- actual = new dv . TimeValue ( iso8601 ) . getSortKey ( ) ;
177
+ for ( var timestamp in testCases ) {
178
+ var timeValue = new dv . TimeValue ( timestamp ) ,
179
+ json = timeValue . toJSON ( ) . time ,
180
+ sortKey = timeValue . getSortKey ( ) ,
181
+ expectedJSON = testCases [ timestamp ] [ 0 ] ,
182
+ expectedSortKey = testCases [ timestamp ] [ 1 ] ;
88
183
89
184
assert . ok (
90
- expected === actual ,
91
- 'Expected getSortKey() to return "' + expected + '", got "' + actual + '"'
185
+ json === expectedJSON ,
186
+ 'Expected toJSON().time to return "' + expectedJSON + '", got "' + json + '"'
187
+ ) ;
188
+ assert . ok (
189
+ sortKey === expectedSortKey ,
190
+ 'Expected getSortKey() to return "' + expectedSortKey + '", got "' + sortKey + '"'
92
191
) ;
93
-
94
192
}
95
193
}
96
194
0 commit comments