]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | describe("Ext.Date", function() {\r |
2 | describe('Elapsed time between dates', function () {\r | |
3 | var dateValue = 0,\r | |
4 | increment = 3,\r | |
5 | OriginalDate = Date,\r | |
6 | originalNow = Ext.Date.now,\r | |
7 | PredictableDate = function() {\r | |
8 | return {\r | |
9 | getTime: function() {\r | |
10 | },\r | |
11 | valueOf: function() {\r | |
12 | return PredictableDate.now();\r | |
13 | }\r | |
14 | };\r | |
15 | };\r | |
16 | \r | |
17 | function mockDate() {\r | |
18 | Date = PredictableDate;\r | |
19 | }\r | |
20 | \r | |
21 | beforeEach(function () {\r | |
22 | Ext.Date.now = PredictableDate.now = function () {\r | |
23 | dateValue = dateValue + increment;\r | |
24 | return dateValue;\r | |
25 | };\r | |
26 | });\r | |
27 | \r | |
28 | afterEach(function() {\r | |
29 | Ext.Date.now = originalNow;\r | |
30 | Date = OriginalDate;\r | |
31 | increment += 16;\r | |
32 | });\r | |
33 | \r | |
34 | it("should get time elapsed in millisecond between date instantiation", function () {\r | |
35 | mockDate();\r | |
36 | var dateA = new PredictableDate();\r | |
37 | expect(Ext.Date.getElapsed(dateA)).toEqual(3);\r | |
38 | });\r | |
39 | \r | |
40 | it("should get time elapsed in millisecond between two dates", function () {\r | |
41 | mockDate();\r | |
42 | var dateA = new PredictableDate(),\r | |
43 | dateB = new PredictableDate();\r | |
44 | \r | |
45 | expect(Ext.Date.getElapsed(dateA, dateB)).toEqual(19);\r | |
46 | });\r | |
47 | });\r | |
48 | \r | |
49 | describe("now", function() {\r | |
50 | it("should return the current timestamp", function() {\r | |
51 | var millisBeforeCall = +new Date(),\r | |
52 | millisAtCall = Ext.Date.now(),\r | |
53 | millisAfterCall = +new Date();\r | |
54 | \r | |
55 | expect(millisAtCall).not.toBeLessThan(millisBeforeCall);\r | |
56 | expect(millisAtCall).not.toBeGreaterThan(millisAfterCall);\r | |
57 | });\r | |
58 | });\r | |
59 | \r | |
60 | describe("getShortMonthName", function() {\r | |
61 | it("should return 3 letter abbreviation for the corresponding month [0-11]", function() {\r | |
62 | expect(Ext.Date.getShortMonthName(0)).toBe("Jan");\r | |
63 | expect(Ext.Date.getShortMonthName(1)).toBe("Feb");\r | |
64 | expect(Ext.Date.getShortMonthName(2)).toBe("Mar");\r | |
65 | expect(Ext.Date.getShortMonthName(3)).toBe("Apr");\r | |
66 | expect(Ext.Date.getShortMonthName(4)).toBe("May");\r | |
67 | expect(Ext.Date.getShortMonthName(5)).toBe("Jun");\r | |
68 | expect(Ext.Date.getShortMonthName(6)).toBe("Jul");\r | |
69 | expect(Ext.Date.getShortMonthName(7)).toBe("Aug");\r | |
70 | expect(Ext.Date.getShortMonthName(8)).toBe("Sep");\r | |
71 | expect(Ext.Date.getShortMonthName(9)).toBe("Oct");\r | |
72 | expect(Ext.Date.getShortMonthName(10)).toBe("Nov");\r | |
73 | expect(Ext.Date.getShortMonthName(11)).toBe("Dec");\r | |
74 | });\r | |
75 | });\r | |
76 | \r | |
77 | describe("getShortDayName", function() {\r | |
78 | it("should return 3 letter abbreviation for the corresponding weekday [0-6]", function() {\r | |
79 | expect(Ext.Date.getShortDayName(0)).toBe("Sun");\r | |
80 | expect(Ext.Date.getShortDayName(1)).toBe("Mon");\r | |
81 | expect(Ext.Date.getShortDayName(2)).toBe("Tue");\r | |
82 | expect(Ext.Date.getShortDayName(3)).toBe("Wed");\r | |
83 | expect(Ext.Date.getShortDayName(4)).toBe("Thu");\r | |
84 | expect(Ext.Date.getShortDayName(5)).toBe("Fri");\r | |
85 | expect(Ext.Date.getShortDayName(6)).toBe("Sat");\r | |
86 | \r | |
87 | });\r | |
88 | });\r | |
89 | \r | |
90 | describe("getMonthNumber", function() {\r | |
91 | it("should return the month number [0-11] for the corresponding short month name", function() {\r | |
92 | var names = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', \r | |
93 | 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];\r | |
94 | \r | |
95 | Ext.Array.forEach(names, function(name, idx) {\r | |
96 | expect(Ext.Date.getMonthNumber(name)).toBe(idx);\r | |
97 | expect(Ext.Date.getMonthNumber(name.toUpperCase())).toBe(idx);\r | |
98 | expect(Ext.Date.getMonthNumber(Ext.String.capitalize(name))).toBe(idx);\r | |
99 | });\r | |
100 | });\r | |
101 | \r | |
102 | it("should return the month number [0-11] for the corresponding full month name", function() {\r | |
103 | var names = ['january', \r | |
104 | 'february', \r | |
105 | 'march', \r | |
106 | 'april', \r | |
107 | 'may', \r | |
108 | 'june', \r | |
109 | 'july', \r | |
110 | 'august', \r | |
111 | 'september', \r | |
112 | 'october', \r | |
113 | 'november', \r | |
114 | 'december'];\r | |
115 | \r | |
116 | Ext.Array.forEach(names, function(name, idx) {\r | |
117 | expect(Ext.Date.getMonthNumber(name)).toBe(idx);\r | |
118 | expect(Ext.Date.getMonthNumber(name.toUpperCase())).toBe(idx);\r | |
119 | expect(Ext.Date.getMonthNumber(Ext.String.capitalize(name))).toBe(idx);\r | |
120 | });\r | |
121 | });\r | |
122 | });\r | |
123 | \r | |
124 | describe("formatContainsHourInfo", function() {\r | |
125 | it("should return true when format contains hour info", function() {\r | |
126 | expect(Ext.Date.formatContainsHourInfo("d/m/Y H:i:s")).toBeTruthy();\r | |
127 | });\r | |
128 | it("should return false when format doesn't contains hour info", function() {\r | |
129 | expect(Ext.Date.formatContainsHourInfo("d/m/Y")).toBeFalsy();\r | |
130 | });\r | |
131 | });\r | |
132 | \r | |
133 | describe("formatContainsDateInfo", function() {\r | |
134 | it("should return true when format contains date info", function() {\r | |
135 | expect(Ext.Date.formatContainsDateInfo("d/m/Y H:i:s")).toBeTruthy();\r | |
136 | });\r | |
137 | it("should return false when format doesn't contains date info", function() {\r | |
138 | expect(Ext.Date.formatContainsDateInfo("H:i:s")).toBeFalsy();\r | |
139 | });\r | |
140 | });\r | |
141 | \r | |
142 | describe("isValid", function() {\r | |
143 | it("should return true for valid dates", function() {\r | |
144 | expect(Ext.Date.isValid(1981, 10, 15, 16, 30, 1, 2)).toBeTruthy();\r | |
145 | });\r | |
146 | it("should return false for invalid dates", function() {\r | |
147 | expect(Ext.Date.isValid(999999, 10, 15, 16, 30, 1, 2)).toBeFalsy();\r | |
148 | expect(Ext.Date.isValid(1981, 13, 15, 16, 30, 1, 2)).toBeFalsy();\r | |
149 | expect(Ext.Date.isValid(1981, 10, 32, 16, 30, 1, 2)).toBeFalsy();\r | |
150 | expect(Ext.Date.isValid(1981, 10, 15, 25, 30, 1, 2)).toBeFalsy();\r | |
151 | expect(Ext.Date.isValid(1981, 10, 15, 16, 60, 1, 2)).toBeFalsy();\r | |
152 | expect(Ext.Date.isValid(1981, 10, 15, 16, 30, 60, 2)).toBeFalsy();\r | |
153 | expect(Ext.Date.isValid(1981, 10, 15, 16, 30, 1, 100000)).toBeFalsy();\r | |
154 | });\r | |
155 | });\r | |
156 | \r | |
157 | describe("parse", function() {\r | |
158 | it("should parse year-only", function() {\r | |
159 | var date = Ext.Date.parse("2011", "Y"),\r | |
160 | expectedDate = new Date();\r | |
161 | expectedDate.setFullYear(2011);\r | |
162 | expectedDate.setHours(0);\r | |
163 | expectedDate.setMinutes(0);\r | |
164 | expectedDate.setSeconds(0);\r | |
165 | expectedDate.setMilliseconds(0);\r | |
166 | expect(date).toEqual(expectedDate);\r | |
167 | });\r | |
168 | \r | |
169 | it("should parse year-month-date", function() {\r | |
170 | var date = Ext.Date.parse("2011-01-20", "Y-m-d"),\r | |
171 | expectedDate = new Date();\r | |
172 | expectedDate.setFullYear(2011);\r | |
173 | expectedDate.setMonth(0);\r | |
174 | expectedDate.setDate(20);\r | |
175 | expectedDate.setHours(0);\r | |
176 | expectedDate.setMinutes(0);\r | |
177 | expectedDate.setSeconds(0);\r | |
178 | expectedDate.setMilliseconds(0);\r | |
179 | expect(date).toEqual(expectedDate);\r | |
180 | });\r | |
181 | \r | |
182 | describe('y (year parse code)', function () {\r | |
183 | var d;\r | |
184 | \r | |
185 | afterEach(function () {\r | |
186 | d = null;\r | |
187 | });\r | |
188 | \r | |
189 | it('should parse a 2-digit year', function () {\r | |
190 | d = Ext.Date.parse('09', 'y');\r | |
191 | expect(d.getFullYear()).toBe(2009);\r | |
192 | });\r | |
193 | \r | |
194 | it('should parse a 2-digit year as part of a larger format string', function () {\r | |
195 | d = Ext.Date.parse('720122', 'ymd');\r | |
196 | expect(d.getFullYear()).toBe(1972);\r | |
197 | });\r | |
198 | \r | |
199 | it('should not parse a 1-digit year', function () {\r | |
200 | expect(Ext.Date.parse('1', 'y')).toBe(null);\r | |
201 | });\r | |
202 | \r | |
203 | it('should not parse a 1-digit year as part of a larger format string', function () {\r | |
204 | expect(Ext.Date.parse('10122', 'ymd')).toBe(null);\r | |
205 | });\r | |
206 | });\r | |
207 | \r | |
208 | it("should parse year-month-date hour:minute:second am/pm", function() {\r | |
209 | var date = Ext.Date.parse("2011-01-20 6:28:33 PM", "Y-m-d g:i:s A"),\r | |
210 | expectedDate = new Date();\r | |
211 | expectedDate.setFullYear(2011);\r | |
212 | expectedDate.setMonth(0);\r | |
213 | expectedDate.setDate(20);\r | |
214 | expectedDate.setHours(18);\r | |
215 | expectedDate.setMinutes(28);\r | |
216 | expectedDate.setSeconds(33);\r | |
217 | expectedDate.setMilliseconds(0);\r | |
218 | expect(date).toEqual(expectedDate);\r | |
219 | });\r | |
220 | \r | |
221 | it("should return null when parsing an invalid date like Feb 31st in strict mode", function() {\r | |
222 | expect(Ext.Date.parse("2011-02-31", "Y-m-d", true)).toBeNull();\r | |
223 | });\r | |
224 | \r | |
225 | it("should read am/pm", function() {\r | |
226 | var date = Ext.Date.parse('2010/01/01 12:45 am', 'Y/m/d G:i a'),\r | |
227 | expectedDate = new Date();\r | |
228 | \r | |
229 | expectedDate.setFullYear(2010);\r | |
230 | expectedDate.setMonth(0);\r | |
231 | expectedDate.setDate(1);\r | |
232 | expectedDate.setHours(0);\r | |
233 | expectedDate.setMinutes(45);\r | |
234 | expectedDate.setSeconds(0);\r | |
235 | expectedDate.setMilliseconds(0);\r | |
236 | expect(date).toEqual(expectedDate);\r | |
237 | });\r | |
238 | \r | |
239 | it("should allow am/pm before minutes", function() {\r | |
240 | var date = Ext.Date.parse('2010/01/01 am 12:45', 'Y/m/d a G:i'),\r | |
241 | expectedDate = new Date();\r | |
242 | \r | |
243 | expectedDate.setFullYear(2010);\r | |
244 | expectedDate.setMonth(0);\r | |
245 | expectedDate.setDate(1);\r | |
246 | expectedDate.setHours(0);\r | |
247 | expectedDate.setMinutes(45);\r | |
248 | expectedDate.setSeconds(0);\r | |
249 | expectedDate.setMilliseconds(0);\r | |
250 | expect(date).toEqual(expectedDate);\r | |
251 | });\r | |
252 | \r | |
253 | it("should parse time format", function(){\r | |
254 | // Can't use a static date because the timezone of the\r | |
255 | // local machine will change the result\r | |
256 | var expectedDate = new Date(2010, 0, 1, 13, 45, 32, 4),\r | |
257 | date = Ext.Date.parse(expectedDate.getTime().toString(), 'time');\r | |
258 | \r | |
259 | expect(date).toEqual(expectedDate);\r | |
260 | });\r | |
261 | \r | |
262 | it("should parse timestamp format", function(){\r | |
263 | // Can't use a static date because the timezone of the\r | |
264 | // local machine will change the result\r | |
265 | // Drop the ms since we don't go to that resolution\r | |
266 | var expectedDate = new Date(2010, 0, 1, 13, 45, 32, 0),\r | |
267 | stamp = Math.floor(expectedDate.getTime() / 1000),\r | |
268 | date = Ext.Date.parse(stamp.toString(), 'timestamp');\r | |
269 | \r | |
270 | expect(date).toEqual(expectedDate);\r | |
271 | });\r | |
272 | \r | |
273 | describe("using separators", function(){\r | |
274 | it("should work with hyphen separators", function() {\r | |
275 | var date = Ext.Date.parse('2010-03-04', 'Y-m-d'),\r | |
276 | expectedDate = new Date();\r | |
277 | \r | |
278 | expectedDate.setFullYear(2010);\r | |
279 | expectedDate.setMonth(2);\r | |
280 | expectedDate.setDate(4);\r | |
281 | expectedDate.setHours(0);\r | |
282 | expectedDate.setMinutes(0);\r | |
283 | expectedDate.setSeconds(0);\r | |
284 | expectedDate.setMilliseconds(0);\r | |
285 | expect(date).toEqual(expectedDate);\r | |
286 | \r | |
287 | });\r | |
288 | \r | |
289 | it("should work with slash separators", function() {\r | |
290 | var date = Ext.Date.parse('2010/03/04', 'Y/m/d'),\r | |
291 | expectedDate = new Date();\r | |
292 | \r | |
293 | expectedDate.setFullYear(2010);\r | |
294 | expectedDate.setMonth(2);\r | |
295 | expectedDate.setDate(4);\r | |
296 | expectedDate.setHours(0);\r | |
297 | expectedDate.setMinutes(0);\r | |
298 | expectedDate.setSeconds(0);\r | |
299 | expectedDate.setMilliseconds(0);\r | |
300 | expect(date).toEqual(expectedDate);\r | |
301 | \r | |
302 | });\r | |
303 | \r | |
304 | it("should work with space separators", function() {\r | |
305 | var date = Ext.Date.parse('2010 03 04', 'Y m d'),\r | |
306 | expectedDate = new Date();\r | |
307 | \r | |
308 | expectedDate.setFullYear(2010);\r | |
309 | expectedDate.setMonth(2);\r | |
310 | expectedDate.setDate(4);\r | |
311 | expectedDate.setHours(0);\r | |
312 | expectedDate.setMinutes(0);\r | |
313 | expectedDate.setSeconds(0);\r | |
314 | expectedDate.setMilliseconds(0);\r | |
315 | expect(date).toEqual(expectedDate);\r | |
316 | });\r | |
317 | });\r | |
318 | \r | |
319 | describe("week/year", function() {\r | |
320 | var d;\r | |
321 | function expectDate(year, month, day) {\r | |
322 | expect(d.getFullYear()).toBe(year);\r | |
323 | expect(d.getMonth()).toBe(month);\r | |
324 | expect(d.getDate()).toBe(day);\r | |
325 | }\r | |
326 | \r | |
327 | describe("first week of year", function() {\r | |
328 | it("should return the correct date for 2013", function() {\r | |
329 | d = Ext.Date.parse('01/2013', 'W/Y');\r | |
330 | expectDate(2012, 11, 31);\r | |
331 | });\r | |
332 | \r | |
333 | it("should return the correct date for 2014", function() {\r | |
334 | d = Ext.Date.parse('01/2014', 'W/Y');\r | |
335 | expectDate(2013, 11, 30);\r | |
336 | });\r | |
337 | \r | |
338 | it("should return the correct date for 2015", function() {\r | |
339 | d = Ext.Date.parse('01/2015', 'W/Y');\r | |
340 | expectDate(2014, 11, 29);\r | |
341 | });\r | |
342 | \r | |
343 | it("should return the correct date for 2016", function() {\r | |
344 | d = Ext.Date.parse('01/2016', 'W/Y');\r | |
345 | expectDate(2016, 0, 4);\r | |
346 | });\r | |
347 | });\r | |
348 | \r | |
349 | it("should always be a Monday", function() {\r | |
350 | var i, j;\r | |
351 | \r | |
352 | for (i = 2012; i <= 2020; ++i) {\r | |
353 | for (j = 1; j < 53; ++j) {\r | |
354 | expect(Ext.Date.parse(i + '-' + Ext.String.leftPad(j, 2, '0'), 'Y-W').getDay()).toBe(1);\r | |
355 | }\r | |
356 | } \r | |
357 | });\r | |
358 | });\r | |
359 | \r | |
360 | });\r | |
361 | \r | |
362 | describe("isEqual", function() {\r | |
363 | it("should return true if both dates are exactly the same", function() {\r | |
364 | var date1 = new Date(2011, 0, 20, 18, 37, 15, 0),\r | |
365 | date2 = new Date(2011, 0, 20, 18, 37, 15, 0);\r | |
366 | expect(Ext.Date.isEqual(date1, date2)).toBeTruthy();\r | |
367 | });\r | |
368 | it("should return true if there is at least 1 millisecond difference between both dates", function() {\r | |
369 | var date1 = new Date(2011, 0, 20, 18, 37, 15, 0),\r | |
370 | date2 = new Date(2011, 0, 20, 18, 37, 15, 1);\r | |
371 | expect(Ext.Date.isEqual(date1, date2)).toBeFalsy();\r | |
372 | });\r | |
373 | it("should return false if one one of the dates is null/undefined", function() {\r | |
374 | expect(Ext.Date.isEqual(new Date(), undefined)).toBeFalsy();\r | |
375 | expect(Ext.Date.isEqual(new Date(), null)).toBeFalsy();\r | |
376 | expect(Ext.Date.isEqual(undefined, new Date())).toBeFalsy();\r | |
377 | expect(Ext.Date.isEqual(null, new Date())).toBeFalsy();\r | |
378 | });\r | |
379 | it("should return true if both dates are null/undefined", function() {\r | |
380 | expect(Ext.Date.isEqual(null, null)).toBeTruthy();\r | |
381 | expect(Ext.Date.isEqual(null, undefined)).toBeTruthy();\r | |
382 | expect(Ext.Date.isEqual(undefined, null)).toBeTruthy();\r | |
383 | expect(Ext.Date.isEqual(undefined, undefined)).toBeTruthy();\r | |
384 | });\r | |
385 | });\r | |
386 | \r | |
387 | describe("getDayOfYear", function() {\r | |
388 | it("should return the day of year between 0 and 364 for non-leap years", function() {\r | |
389 | expect(Ext.Date.getDayOfYear(new Date(2001, 0, 1))).toBe(0);\r | |
390 | expect(Ext.Date.getDayOfYear(new Date(2001, 11, 31))).toBe(364);\r | |
391 | });\r | |
392 | it("should return the day of year between 0 and 365 for leap years", function() {\r | |
393 | expect(Ext.Date.getDayOfYear(new Date(2000, 0, 1))).toBe(0);\r | |
394 | expect(Ext.Date.getDayOfYear(new Date(2000, 11, 31))).toBe(365);\r | |
395 | });\r | |
396 | });\r | |
397 | \r | |
398 | describe("getFirstDayOfMonth", function() {\r | |
399 | it("should return the number [0-6] of the first day of month of the given date", function() {\r | |
400 | expect(Ext.Date.getFirstDayOfMonth(new Date(2007, 0, 1))).toBe(1);\r | |
401 | expect(Ext.Date.getFirstDayOfMonth(new Date(2000, 0, 2))).toBe(6);\r | |
402 | expect(Ext.Date.getFirstDayOfMonth(new Date(2011, 0, 3))).toBe(6);\r | |
403 | expect(Ext.Date.getFirstDayOfMonth(new Date(2011, 6, 4))).toBe(5);\r | |
404 | expect(Ext.Date.getFirstDayOfMonth(new Date(2011, 11, 5))).toBe(4);\r | |
405 | });\r | |
406 | });\r | |
407 | \r | |
408 | describe("getLastDayOfMonth", function() {\r | |
409 | it("should return the number [0-6] of the last day of month of the given date", function() {\r | |
410 | expect(Ext.Date.getLastDayOfMonth(new Date(2007, 0, 1))).toBe(3);\r | |
411 | expect(Ext.Date.getLastDayOfMonth(new Date(2000, 0, 2))).toBe(1);\r | |
412 | expect(Ext.Date.getLastDayOfMonth(new Date(2011, 0, 3))).toBe(1);\r | |
413 | expect(Ext.Date.getLastDayOfMonth(new Date(2011, 6, 4))).toBe(0);\r | |
414 | expect(Ext.Date.getLastDayOfMonth(new Date(2011, 11, 5))).toBe(6);\r | |
415 | });\r | |
416 | });\r | |
417 | \r | |
418 | describe("getFirstDateOfMonth", function() {\r | |
419 | it("should return the date corresponding to the first day of month of the given date", function() {\r | |
420 | expect(Ext.Date.getFirstDateOfMonth(new Date(2007, 0, 1))).toEqual(new Date(2007, 0, 1));\r | |
421 | expect(Ext.Date.getFirstDateOfMonth(new Date(2000, 0, 2))).toEqual(new Date(2000, 0, 1));\r | |
422 | expect(Ext.Date.getFirstDateOfMonth(new Date(2011, 0, 3))).toEqual(new Date(2011, 0, 1));\r | |
423 | expect(Ext.Date.getFirstDateOfMonth(new Date(2011, 6, 4))).toEqual(new Date(2011, 6, 1));\r | |
424 | expect(Ext.Date.getFirstDateOfMonth(new Date(2011, 11, 5))).toEqual(new Date(2011, 11, 1));\r | |
425 | });\r | |
426 | });\r | |
427 | \r | |
428 | describe("getLastDateOfMonth", function() {\r | |
429 | it("should return the date corresponding to the last day of month of the given date", function() {\r | |
430 | expect(Ext.Date.getLastDateOfMonth(new Date(2007, 1, 1))).toEqual(new Date(2007, 1, 28));\r | |
431 | expect(Ext.Date.getLastDateOfMonth(new Date(2000, 1, 2))).toEqual(new Date(2000, 1, 29));\r | |
432 | expect(Ext.Date.getLastDateOfMonth(new Date(2011, 0, 3))).toEqual(new Date(2011, 0, 31));\r | |
433 | expect(Ext.Date.getLastDateOfMonth(new Date(2011, 5, 4))).toEqual(new Date(2011, 5, 30));\r | |
434 | expect(Ext.Date.getLastDateOfMonth(new Date(2011, 11, 5))).toEqual(new Date(2011, 11, 31));\r | |
435 | });\r | |
436 | });\r | |
437 | \r | |
438 | describe("getSuffix", function() {\r | |
439 | it("should return st for 1, 21 and 31", function() {\r | |
440 | expect(Ext.Date.getSuffix(new Date(2011, 0, 1))).toBe("st");\r | |
441 | expect(Ext.Date.getSuffix(new Date(2011, 0, 21))).toBe("st");\r | |
442 | expect(Ext.Date.getSuffix(new Date(2011, 0, 31))).toBe("st");\r | |
443 | });\r | |
444 | it("should return nd for 2 and, 22", function() {\r | |
445 | expect(Ext.Date.getSuffix(new Date(2011, 0, 2))).toBe("nd");\r | |
446 | expect(Ext.Date.getSuffix(new Date(2011, 0, 22))).toBe("nd");\r | |
447 | });\r | |
448 | it("should return rd for 3 and, 23", function() {\r | |
449 | expect(Ext.Date.getSuffix(new Date(2011, 0, 3))).toBe("rd");\r | |
450 | expect(Ext.Date.getSuffix(new Date(2011, 0, 23))).toBe("rd");\r | |
451 | });\r | |
452 | it("should return th for days [11-13] and days ending in [4-0]", function() {\r | |
453 | expect(Ext.Date.getSuffix(new Date(2011, 0, 4))).toBe("th");\r | |
454 | expect(Ext.Date.getSuffix(new Date(2011, 0, 5))).toBe("th");\r | |
455 | expect(Ext.Date.getSuffix(new Date(2011, 0, 6))).toBe("th");\r | |
456 | expect(Ext.Date.getSuffix(new Date(2011, 0, 7))).toBe("th");\r | |
457 | expect(Ext.Date.getSuffix(new Date(2011, 0, 8))).toBe("th");\r | |
458 | expect(Ext.Date.getSuffix(new Date(2011, 0, 9))).toBe("th");\r | |
459 | expect(Ext.Date.getSuffix(new Date(2011, 0, 10))).toBe("th");\r | |
460 | expect(Ext.Date.getSuffix(new Date(2011, 0, 11))).toBe("th");\r | |
461 | expect(Ext.Date.getSuffix(new Date(2011, 0, 12))).toBe("th");\r | |
462 | expect(Ext.Date.getSuffix(new Date(2011, 0, 13))).toBe("th");\r | |
463 | expect(Ext.Date.getSuffix(new Date(2011, 0, 14))).toBe("th");\r | |
464 | expect(Ext.Date.getSuffix(new Date(2011, 0, 15))).toBe("th");\r | |
465 | expect(Ext.Date.getSuffix(new Date(2011, 0, 16))).toBe("th");\r | |
466 | expect(Ext.Date.getSuffix(new Date(2011, 0, 17))).toBe("th");\r | |
467 | expect(Ext.Date.getSuffix(new Date(2011, 0, 18))).toBe("th");\r | |
468 | expect(Ext.Date.getSuffix(new Date(2011, 0, 19))).toBe("th");\r | |
469 | expect(Ext.Date.getSuffix(new Date(2011, 0, 20))).toBe("th");\r | |
470 | expect(Ext.Date.getSuffix(new Date(2011, 0, 24))).toBe("th");\r | |
471 | expect(Ext.Date.getSuffix(new Date(2011, 0, 25))).toBe("th");\r | |
472 | expect(Ext.Date.getSuffix(new Date(2011, 0, 26))).toBe("th");\r | |
473 | expect(Ext.Date.getSuffix(new Date(2011, 0, 27))).toBe("th");\r | |
474 | expect(Ext.Date.getSuffix(new Date(2011, 0, 28))).toBe("th");\r | |
475 | expect(Ext.Date.getSuffix(new Date(2011, 0, 29))).toBe("th");\r | |
476 | expect(Ext.Date.getSuffix(new Date(2011, 0, 30))).toBe("th");\r | |
477 | });\r | |
478 | });\r | |
479 | \r | |
480 | describe("clone", function() {\r | |
481 | it("should return a copy of the given date", function() {\r | |
482 | var originalDate = new Date(),\r | |
483 | clonedDate;\r | |
484 | clonedDate = Ext.Date.clone(originalDate);\r | |
485 | expect(clonedDate).not.toBe(originalDate);\r | |
486 | expect(clonedDate).toEqual(originalDate);\r | |
487 | });\r | |
488 | });\r | |
489 | \r | |
490 | describe("isDST", function() {\r | |
491 | // DST detection relies on the locale of the browser running the test as different countries having different\r | |
492 | // versions of DST. Most countries don't observe it at all. Europe has standardized dates for switching times\r | |
493 | // but it differs from the dates used in the USA and Canada.\r | |
494 | //\r | |
495 | // These tests are quite loose but should pass in Europe and North America. Other countries may vary.\r | |
496 | //\r | |
497 | // Early March - USA & Canada enter DST\r | |
498 | // Late March - EU enters DST\r | |
499 | // Late October - EU leaves DST\r | |
500 | // Early November - USA & Canada leave DST\r | |
501 | \r | |
502 | // This test is disabled because it fails on the Eye but it should pass on most developer machines\r | |
503 | xit("should return true from the end of March till the middle of October", function() {\r | |
504 | expect(Ext.Date.isDST(new Date(2010, 2, 31))).toBeTruthy();\r | |
505 | expect(Ext.Date.isDST(new Date(2010, 3, 15))).toBeTruthy();\r | |
506 | expect(Ext.Date.isDST(new Date(2010, 4, 15))).toBeTruthy();\r | |
507 | expect(Ext.Date.isDST(new Date(2010, 5, 15))).toBeTruthy();\r | |
508 | expect(Ext.Date.isDST(new Date(2010, 6, 15))).toBeTruthy();\r | |
509 | expect(Ext.Date.isDST(new Date(2010, 7, 15))).toBeTruthy();\r | |
510 | expect(Ext.Date.isDST(new Date(2010, 8, 15))).toBeTruthy();\r | |
511 | expect(Ext.Date.isDST(new Date(2010, 9, 15))).toBeTruthy();\r | |
512 | });\r | |
513 | \r | |
514 | it("should return false from the middle of November till the start of March", function() {\r | |
515 | expect(Ext.Date.isDST(new Date(2010, 10, 15))).toBeFalsy();\r | |
516 | expect(Ext.Date.isDST(new Date(2010, 11, 15))).toBeFalsy();\r | |
517 | expect(Ext.Date.isDST(new Date(2010, 0, 15))).toBeFalsy();\r | |
518 | expect(Ext.Date.isDST(new Date(2010, 1, 15))).toBeFalsy();\r | |
519 | expect(Ext.Date.isDST(new Date(2010, 2, 1))).toBeFalsy();\r | |
520 | });\r | |
521 | });\r | |
522 | \r | |
523 | describe("clearTime", function() {\r | |
524 | it("should return 'Invalid Date' if the date is invalid", function() {\r | |
525 | var date = new Date('foo'),\r | |
526 | clearedTimeDate = Ext.Date.clearTime(date);\r | |
527 | expect(clearedTimeDate.getTime()).toBeNaN();\r | |
528 | });\r | |
529 | \r | |
530 | it("should reset hrs/mins/secs/millis to 0", function() {\r | |
531 | var date = new Date(2012, 11, 21, 21, 21, 21, 21);\r | |
532 | Ext.Date.clearTime(date);\r | |
533 | expect(date.getHours()).toBe(0);\r | |
534 | expect(date.getMinutes()).toBe(0);\r | |
535 | expect(date.getSeconds()).toBe(0);\r | |
536 | expect(date.getMilliseconds()).toBe(0);\r | |
537 | });\r | |
538 | it("should return a clone with hrs/mins/secs/millis reseted to 0 when clone option is selected", function() {\r | |
539 | var date = new Date(2012, 11, 21, 21, 21, 21, 21),\r | |
540 | clearedTimeDate;\r | |
541 | clearedTimeDate = Ext.Date.clearTime(date, true);\r | |
542 | expect(date.getHours()).toBe(21);\r | |
543 | expect(date.getMinutes()).toBe(21);\r | |
544 | expect(date.getSeconds()).toBe(21);\r | |
545 | expect(date.getMilliseconds()).toBe(21);\r | |
546 | expect(clearedTimeDate.getHours()).toBe(0);\r | |
547 | expect(clearedTimeDate.getMinutes()).toBe(0);\r | |
548 | expect(clearedTimeDate.getSeconds()).toBe(0);\r | |
549 | expect(clearedTimeDate.getMilliseconds()).toBe(0);\r | |
550 | });\r | |
551 | });\r | |
552 | \r | |
553 | describe("add", function() {\r | |
554 | var date = new Date(2000, 0, 1, 0, 0, 0, 0);\r | |
555 | it("should add milliseconds", function() {\r | |
556 | expect(Ext.Date.add(date, Ext.Date.MILLI, 1)).toEqual(new Date(2000, 0, 1, 0, 0, 0, 1));\r | |
557 | });\r | |
558 | it("should add seconds", function() {\r | |
559 | expect(Ext.Date.add(date, Ext.Date.SECOND, 1)).toEqual(new Date(2000, 0, 1, 0, 0, 1, 0));\r | |
560 | });\r | |
561 | it("should add minutes", function() {\r | |
562 | expect(Ext.Date.add(date, Ext.Date.MINUTE, 1)).toEqual(new Date(2000, 0, 1, 0, 1, 0, 0));\r | |
563 | });\r | |
564 | it("should add hours", function() {\r | |
565 | expect(Ext.Date.add(date, Ext.Date.HOUR, 1)).toEqual(new Date(2000, 0, 1, 1, 0, 0, 0));\r | |
566 | });\r | |
567 | it("should add days", function() {\r | |
568 | expect(Ext.Date.add(date, Ext.Date.DAY, 1)).toEqual(new Date(2000, 0, 2, 0, 0, 0, 0));\r | |
569 | });\r | |
570 | it("should add months", function() {\r | |
571 | expect(Ext.Date.add(date, Ext.Date.MONTH, 1)).toEqual(new Date(2000, 1, 1, 0, 0, 0, 0));\r | |
572 | });\r | |
573 | it("should add years", function() {\r | |
574 | expect(Ext.Date.add(date, Ext.Date.YEAR, 1)).toEqual(new Date(2001, 0, 1, 0, 0, 0, 0));\r | |
575 | });\r | |
576 | it("should consider last day of month when adding months", function() {\r | |
577 | expect(Ext.Date.add(new Date(2001, 0, 29), Ext.Date.MONTH, 1)).toEqual(new Date(2001, 1, 28));\r | |
578 | expect(Ext.Date.add(new Date(2001, 0, 30), Ext.Date.MONTH, 1)).toEqual(new Date(2001, 1, 28));\r | |
579 | expect(Ext.Date.add(new Date(2001, 0, 31), Ext.Date.MONTH, 1)).toEqual(new Date(2001, 1, 28));\r | |
580 | expect(Ext.Date.add(new Date(2000, 0, 29), Ext.Date.MONTH, 1)).toEqual(new Date(2000, 1, 29));\r | |
581 | expect(Ext.Date.add(new Date(2000, 0, 30), Ext.Date.MONTH, 1)).toEqual(new Date(2000, 1, 29));\r | |
582 | expect(Ext.Date.add(new Date(2000, 0, 31), Ext.Date.MONTH, 1)).toEqual(new Date(2000, 1, 29));\r | |
583 | });\r | |
584 | it("should consider last day of month when adding years", function() {\r | |
585 | expect(Ext.Date.add(new Date(2000, 1, 29), Ext.Date.YEAR, 1)).toEqual(new Date(2001, 1, 28));\r | |
586 | });\r | |
587 | });\r | |
588 | \r | |
589 | describe("between", function() {\r | |
590 | var startDate = new Date(2000, 0, 1),\r | |
591 | endDate = new Date(2000, 0, 31);\r | |
592 | it("should return true if the date is equal to the start date", function() {\r | |
593 | expect(Ext.Date.between(new Date(2000, 0, 1), startDate, endDate)).toBeTruthy();\r | |
594 | });\r | |
595 | it("should return true if the date is equal to the end date", function() {\r | |
596 | expect(Ext.Date.between(new Date(2000, 0, 31), startDate, endDate)).toBeTruthy();\r | |
597 | });\r | |
598 | it("should return true if date is between start and end dates", function() {\r | |
599 | expect(Ext.Date.between(new Date(2000, 0, 15), startDate, endDate)).toBeTruthy();\r | |
600 | });\r | |
601 | it("should return false if date is before start date", function() {\r | |
602 | expect(Ext.Date.between(new Date(1999, 11, 31, 23, 59, 59), startDate, endDate)).toBeFalsy();\r | |
603 | });\r | |
604 | it("should return false if date is after end date", function() {\r | |
605 | expect(Ext.Date.between(new Date(2000, 0, 31, 0, 0, 1), startDate, endDate)).toBeFalsy();\r | |
606 | });\r | |
607 | });\r | |
608 | \r | |
609 | describe("formatting", function(){\r | |
610 | // Set the reference date to be an absolute time value so that tests will\r | |
611 | // run in any time zone.\r | |
612 | // This is Friday, January 1, 2010, 21:45:32.004 UTC\r | |
613 | // In the below code we'll retrieve the local TZ offset so that no matter in\r | |
614 | // which TZ this runs, the date/time will always be the same\r | |
615 | // Around the world where tests may be run, the default toString\r | |
616 | // rendition of this may change, so testers beware.\r | |
617 | var baseline = Date.UTC(2010, 0, 1, 21, 45, 32, 4),\r | |
618 | tzOffset = (new Date(baseline)).getTimezoneOffset(),\r | |
619 | ms = baseline + (tzOffset * 60000), // ms in 1 minute\r | |
620 | date = new Date(ms),\r | |
621 | format = Ext.Date.format;\r | |
622 | \r | |
623 | it("should format with the d option", function() {\r | |
624 | expect(format(date, 'd')).toBe('01');\r | |
625 | });\r | |
626 | \r | |
627 | it("should format with the D option", function(){\r | |
628 | expect(format(date, 'D')).toBe('Fri');\r | |
629 | });\r | |
630 | \r | |
631 | it("should format with the j option", function(){\r | |
632 | expect(format(date, 'j')).toBe('1');\r | |
633 | });\r | |
634 | \r | |
635 | it("should format with the l option", function(){\r | |
636 | expect(format(date, 'l')).toBe('Friday');\r | |
637 | });\r | |
638 | \r | |
639 | it("should format with the N option", function(){\r | |
640 | expect(format(date, 'N')).toBe('5');\r | |
641 | });\r | |
642 | \r | |
643 | it("should format with the S option", function(){\r | |
644 | expect(format(date, 'S')).toBe('st');\r | |
645 | });\r | |
646 | \r | |
647 | it("should format with the w option", function(){\r | |
648 | expect(format(date, 'w')).toBe('5');\r | |
649 | });\r | |
650 | \r | |
651 | it("should format with the z option", function(){\r | |
652 | expect(format(date, 'z')).toBe('0');\r | |
653 | });\r | |
654 | \r | |
655 | it("should format with the W option", function(){\r | |
656 | expect(format(date, 'W')).toBe('53');\r | |
657 | });\r | |
658 | \r | |
659 | it("should format with the F option", function(){\r | |
660 | expect(format(date, 'F')).toBe('January');\r | |
661 | });\r | |
662 | \r | |
663 | it("should format with the m option", function(){\r | |
664 | expect(format(date, 'm')).toBe('01');\r | |
665 | });\r | |
666 | \r | |
667 | it("should format with the M option", function(){\r | |
668 | expect(format(date, 'M')).toBe('Jan');\r | |
669 | });\r | |
670 | \r | |
671 | it("should format with the n option", function(){\r | |
672 | expect(format(date, 'n')).toBe('1');\r | |
673 | });\r | |
674 | \r | |
675 | it("should format with the t option", function(){\r | |
676 | expect(format(date, 't')).toBe('31');\r | |
677 | });\r | |
678 | \r | |
679 | it("should format with the L option", function(){\r | |
680 | expect(format(date, 'L')).toBe('0');\r | |
681 | });\r | |
682 | \r | |
683 | it("should format with the o option", function(){\r | |
684 | expect(format(date, 'o')).toBe('2009');\r | |
685 | });\r | |
686 | \r | |
687 | it("should format with the Y option", function(){\r | |
688 | expect(format(date, 'Y')).toBe('2010');\r | |
689 | });\r | |
690 | \r | |
691 | it("should format with the y option", function(){\r | |
692 | expect(format(date, 'y')).toBe('10');\r | |
693 | });\r | |
694 | \r | |
695 | it("should format with the a option", function(){\r | |
696 | expect(format(date, 'a')).toBe('pm');\r | |
697 | });\r | |
698 | \r | |
699 | it("should format with the A option", function(){\r | |
700 | expect(format(date, 'A')).toBe('PM');\r | |
701 | });\r | |
702 | \r | |
703 | it("should format with the g option", function(){\r | |
704 | expect(format(date, 'g')).toBe('9');\r | |
705 | });\r | |
706 | \r | |
707 | it("should format with the G option", function(){\r | |
708 | expect(format(date, 'G')).toBe('21');\r | |
709 | });\r | |
710 | \r | |
711 | it("should format with the h option", function(){\r | |
712 | expect(format(date, 'h')).toBe('09');\r | |
713 | });\r | |
714 | \r | |
715 | it("should format with the H option", function(){\r | |
716 | expect(format(date, 'H')).toBe('21');\r | |
717 | });\r | |
718 | \r | |
719 | it("should format with the i option", function(){\r | |
720 | expect(format(date, 'i')).toBe('45');\r | |
721 | });\r | |
722 | \r | |
723 | it("should format with the s option", function(){\r | |
724 | expect(format(date, 's')).toBe('32');\r | |
725 | });\r | |
726 | \r | |
727 | it("should format with the u option", function(){\r | |
728 | expect(format(date, 'u')).toBe('004');\r | |
729 | });\r | |
730 | \r | |
731 | // can't be static, relies on TZ\r | |
732 | it("should format with the O option", function() {\r | |
733 | var value = Ext.Date.getGMTOffset(date, false);\r | |
734 | expect(format(date, 'O')).toBe(value);\r | |
735 | });\r | |
736 | \r | |
737 | // can't be static, relies on TZ\r | |
738 | it("should format with the P option", function(){\r | |
739 | var value = Ext.Date.getGMTOffset(date, true);\r | |
740 | expect(format(date, 'P')).toBe(value);\r | |
741 | });\r | |
742 | \r | |
743 | // can't be static, relies on TZ\r | |
744 | it("should format with the T option", function(){\r | |
745 | var value = Ext.Date.getTimezone(date);\r | |
746 | expect(format(date, 'T')).toBe(value);\r | |
747 | });\r | |
748 | \r | |
749 | // can't be static, relies on TZ\r | |
750 | it("should format with the Z option", function(){\r | |
751 | var value = (date.getTimezoneOffset() * -60) + '';\r | |
752 | expect(format(date, 'Z')).toBe(value);\r | |
753 | });\r | |
754 | \r | |
755 | // can't be static, relies on TZ\r | |
756 | it("should format with the c option", function(){\r | |
757 | var value = '2010-01-01T21:45:32' + Ext.Date.getGMTOffset(date, true);\r | |
758 | expect(format(date, 'c')).toBe(value);\r | |
759 | });\r | |
760 | \r | |
761 | it("should format with the C option", function(){\r | |
762 | // Use the baseline date here because we want a UTC string\r | |
763 | expect(format(new Date(baseline), 'C')).toBe('2010-01-01T21:45:32.004Z');\r | |
764 | });\r | |
765 | \r | |
766 | it("should format with the U option", function(){\r | |
767 | var value = Math.round((date.getTime() / 1000)) + '';\r | |
768 | expect(format(date, 'U')).toBe(value);\r | |
769 | });\r | |
770 | \r | |
771 | it("should format with the MS option", function(){\r | |
772 | var value = '\\/Date(' + date.getTime() + ')\\/';\r | |
773 | expect(format(date, 'MS')).toBe(value);\r | |
774 | });\r | |
775 | \r | |
776 | it("should format the time option", function(){\r | |
777 | // Can't use a static date because the timezone of the\r | |
778 | // local machine will change the result\r | |
779 | var value = date.getTime().toString();\r | |
780 | expect(format(date, 'time')).toBe(value);\r | |
781 | });\r | |
782 | \r | |
783 | it("should format the timestamp option", function(){\r | |
784 | // Can't use a static date because the timezone of the\r | |
785 | // local machine will change the result\r | |
786 | var stamp = Math.floor(date.getTime() / 1000),\r | |
787 | value = stamp.toString();\r | |
788 | \r | |
789 | expect(format(date, 'timestamp')).toBe(value);\r | |
790 | });\r | |
791 | \r | |
792 | it("should return an empty string", function(){\r | |
793 | expect(format(undefined, 'd')).toBe('');\r | |
794 | expect(format(null, 'd')).toBe('');\r | |
795 | expect(format({}, 'd')).toBe('');\r | |
796 | expect(format([], 'd')).toBe('');\r | |
797 | expect(format('', 'd')).toBe('');\r | |
798 | expect(format(true, 'd')).toBe('');\r | |
799 | expect(format(1992, 'd')).toBe('');\r | |
800 | });\r | |
801 | \r | |
802 | it("should not return an empty string", function(){\r | |
803 | expect(format(new Date(), 'd')).not.toBe('');\r | |
804 | });\r | |
805 | });\r | |
806 | \r | |
807 | describe("ISO-8601", function () {\r | |
808 | var ExtDate = Ext.Date;\r | |
809 | \r | |
810 | describe("dates", function () {\r | |
811 | describe("W - week", function () {\r | |
812 | it("should parse with the W option", function () {\r | |
813 | expect(ExtDate.parse('40', 'W')).not.toBe(null);\r | |
814 | });\r | |
815 | \r | |
816 | it("should only parse weeks 1 - 9 when prefixed by a zero (0)", function () {\r | |
817 | expect(ExtDate.parse('01', 'W')).not.toBe(null);\r | |
818 | });\r | |
819 | \r | |
820 | it("should not parse weeks 1 - 9 when not prefixed by a zero (0)", function () {\r | |
821 | expect(ExtDate.parse('1', 'W')).toBe(null);\r | |
822 | });\r | |
823 | \r | |
824 | it("should start with Monday", function () {\r | |
825 | // getDay() ... Monday === 1\r | |
826 | expect(ExtDate.parse('01', 'W').getDay()).toBe(1);\r | |
827 | });\r | |
828 | });\r | |
829 | \r | |
830 | describe("o - year", function () {\r | |
831 | it("should parse with the o option", function () {\r | |
832 | expect(ExtDate.parse('2012', 'o')).not.toBe(null);\r | |
833 | });\r | |
834 | \r | |
835 | it("should behave the same as Y when not parsed with another option", function(){\r | |
836 | expect(ExtDate.parse('2012', 'o').getTime()).toBe(ExtDate.parse('2012', 'Y').getTime());\r | |
837 | });\r | |
838 | });\r | |
839 | \r | |
840 | describe("can be part of year not same as the 'o' parse code", function () {\r | |
841 | it("should be the previous year than 'o' parse code", function () {\r | |
842 | expect(ExtDate.parse('2008-01', 'o-W').getFullYear()).toBe(2007);\r | |
843 | });\r | |
844 | \r | |
845 | it("should set the same year if required", function () {\r | |
846 | expect(ExtDate.parse('2009-53', 'o-W').getFullYear()).toBe(2009);\r | |
847 | });\r | |
848 | });\r | |
849 | });\r | |
850 | \r | |
851 | describe("times", function () {\r | |
852 | it("should correctly parse ISO format", function() {\r | |
853 | var date = Ext.Date.parse('2012-01-13T01:00:00', 'c'),\r | |
854 | expectedDate = new Date();\r | |
855 | \r | |
856 | expectedDate.setFullYear(2012);\r | |
857 | expectedDate.setMonth(0);\r | |
858 | expectedDate.setDate(13);\r | |
859 | expectedDate.setHours(1);\r | |
860 | expectedDate.setMinutes(0);\r | |
861 | expectedDate.setSeconds(0);\r | |
862 | expectedDate.setMilliseconds(0);\r | |
863 | expect(date).toEqual(expectedDate);\r | |
864 | \r | |
865 | date = Ext.Date.parse('2012-01-13T13:00:00', 'c');\r | |
866 | expectedDate.setFullYear(2012);\r | |
867 | expectedDate.setMonth(0);\r | |
868 | expectedDate.setDate(13);\r | |
869 | expectedDate.setHours(13);\r | |
870 | expectedDate.setMinutes(0);\r | |
871 | expectedDate.setSeconds(0);\r | |
872 | expectedDate.setMilliseconds(0);\r | |
873 | expect(date).toEqual(expectedDate);\r | |
874 | });\r | |
875 | \r | |
876 | describe("time zones", function(){\r | |
877 | it("should evaluate as equal dates with the same time zone", function(){\r | |
878 | var date, expectedDate;\r | |
879 | \r | |
880 | date = Ext.Date.parse("2012-10-03T20:29:24+12:00", "c");\r | |
881 | \r | |
882 | /*\r | |
883 | * IE older than 9 don't support ISO 8601 date notation and return NaN.\r | |
884 | * OTOH the browsers that do support ISO 8601 can be used as additional check.\r | |
885 | * JS dates don't work with timezones so there's always a potential for\r | |
886 | * errors in manual calculations, and this way we can be sure that this stuff\r | |
887 | * actually works as expected; if there's an error it'll blow up either in\r | |
888 | * old IEs or modern browsers.\r | |
889 | */\r | |
890 | if (Ext.isIE8) {\r | |
891 | expectedDate = new Date(0);\r | |
892 | expectedDate.setUTCFullYear(2012);\r | |
893 | expectedDate.setUTCMonth(9);\r | |
894 | expectedDate.setUTCDate(3);\r | |
895 | expectedDate.setUTCHours(20);\r | |
896 | expectedDate.setUTCMinutes(29);\r | |
897 | expectedDate.setUTCSeconds(24);\r | |
898 | expectedDate = new Date(expectedDate.valueOf() - 12*3600*1000);\r | |
899 | }\r | |
900 | else {\r | |
901 | expectedDate = new Date("2012-10-03T20:29:24+12:00");\r | |
902 | }\r | |
903 | \r | |
904 | expect(expectedDate.getTime()).toEqual(date.getTime());\r | |
905 | });\r | |
906 | \r | |
907 | it("should evaluate as equal dates with different time zones", function(){\r | |
908 | // NOTE one hour difference between these times.\r | |
909 | var date, expectedDate,\r | |
910 | oneHourInMs = 1000 * 60 * 60; // 3,600,000\r | |
911 | \r | |
912 | date = Ext.Date.parse("2012-10-03T20:29:24+12:00", "c");\r | |
913 | \r | |
914 | // See above\r | |
915 | if (Ext.isIE8) {\r | |
916 | expectedDate = new Date(0);\r | |
917 | expectedDate.setUTCFullYear(2012);\r | |
918 | expectedDate.setUTCMonth(9);\r | |
919 | expectedDate.setUTCDate(3);\r | |
920 | expectedDate.setUTCHours(20);\r | |
921 | expectedDate.setUTCMinutes(29);\r | |
922 | expectedDate.setUTCSeconds(24);\r | |
923 | expectedDate = new Date(expectedDate.valueOf() - 13*3600*1000);\r | |
924 | }\r | |
925 | else {\r | |
926 | expectedDate = new Date("2012-10-03T20:29:24+13:00");\r | |
927 | }\r | |
928 | \r | |
929 | expect(expectedDate.getTime() + oneHourInMs).toEqual(date.getTime());\r | |
930 | });\r | |
931 | \r | |
932 | it("should evaluate as not equal dates with different time zones", function(){\r | |
933 | var date = Ext.Date.parse("2012-10-03T20:29:24+12:00", "c"),\r | |
934 | expectedDate = new Date("2012-10-03T20:29:24+13:00");\r | |
935 | \r | |
936 | expect(expectedDate.getTime()).not.toEqual(date.getTime());\r | |
937 | });\r | |
938 | });\r | |
939 | });\r | |
940 | });\r | |
941 | });\r |