cirandas.net

ref: master

public/javascripts/vendor/jquery-timepicker-addon/test/jquery-ui-timepicker-addon_spec.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
describe('datetimepicker', function() {
	describe('utility functions', function() {
		var util = $.timepicker._util;

		describe('extendRemove', function() {
			var target,
				props;

			beforeEach(function() {
				target = {};
				props = {};
			});

			it('should add a nonexistent property to the target', function() {
				var expectedValue = "set",
					propertyName = "prop";
				props[propertyName] = expectedValue;

				var newTarget = util._extendRemove(target, props);

				expect(target[propertyName]).toBe(expectedValue);
				expect(newTarget).toBe(target);
			});

			it('should change the value of an existing property', function() {
				var expectedValue = "new",
					originalValue = "old",
					propertyName = "prop";
				target[propertyName] = originalValue;
				props[propertyName] = expectedValue;

				util._extendRemove(target, props);

				expect(target[propertyName]).not.toBe(originalValue);
				expect(target[propertyName]).toBe(expectedValue);
			});

			it('should null the value of an existing property', function() {
				var expectedValue = null,
					propertyName = "prop";
				target[propertyName] = "original";
				props[propertyName] = expectedValue;

				util._extendRemove(target, props);

				expect(target[propertyName]).toBeNull();
			});
		});

		describe('isEmptyObject', function() {
			it('should say an empty object is empty', function() {
				expect(util._isEmptyObject({})).toBe(true);
			});

			it('should say an object with a property is not empty', function() {
				var testObject = {"prop": "value"};

				expect(util._isEmptyObject(testObject)).toBe(false);
			});

			it('should say object with a supplemental prototype property is empty', function() {
				var testObject = function () {};
				testObject.prototype["prop"] = "something";

				expect(util._isEmptyObject(testObject)).toBe(true);
			});
		});

		describe('convert24to12', function() {
			it('should return the value for a non-zero value less than 12', function() {
				var expectedHour = 6;

				expect(util._convert24to12(expectedHour)).toBe("" + expectedHour);
			});

			it('should return 12 hours less if the value is greater than 12 and less than 24', function() {
				var expectedHour = 7;

				expect(util._convert24to12(expectedHour + 12)).toBe("" + expectedHour);
			});

			it('should return 12 if the normalized value is 0', function() {
				expect(util._convert24to12(0)).toBe('12');
			});

			it('should normalize values that are clearly out of the expected range', function() {
				var expectedValue = 11;

				expect(util._convert24to12(expectedValue + 12 * 3)).toBe("" + expectedValue);
			});
		});

		describe('detectSupport', function() {
			it('should detect support for hours', function() {
				expect(util._detectSupport('H').hour).toBe(true);
				expect(util._detectSupport('HH').hour).toBe(true);
				expect(util._detectSupport('h').hour).toBe(true);
				expect(util._detectSupport('hh').hour).toBe(true);

				expect(util._detectSupport('asdf').hour).toBe(false);
			});

			it('should detect support for minutes', function() {
				expect(util._detectSupport('m').minute).toBe(true);
				expect(util._detectSupport('mm').minute).toBe(true);

				expect(util._detectSupport('asdf').minute).toBe(false);
			});

			it('should detect support for seconds', function() {
				expect(util._detectSupport('s').second).toBe(true);
				expect(util._detectSupport('ss').second).toBe(true);

				expect(util._detectSupport('acdf').second).toBe(false);
			});

			it('should detect support for milliseconds', function() {
				expect(util._detectSupport('l').millisec).toBe(true);

				expect(util._detectSupport('acdf').millisec).toBe(false);
			});

			it('should detect support for microseconds', function() {
				expect(util._detectSupport('c').microsec).toBe(true);

				expect(util._detectSupport('asdf').microsec).toBe(false);
			});

			it('should detect support for AM/PM', function() {
				expect(util._detectSupport('h t').ampm).toBe(true);
				expect(util._detectSupport('h tt').ampm).toBe(true);
				expect(util._detectSupport('h T').ampm).toBe(true);
				expect(util._detectSupport('h TT').ampm).toBe(true);

				expect(util._detectSupport('t').ampm).toBe(false);
				expect(util._detectSupport('h').ampm).toBe(false);
				expect(util._detectSupport('H t').ampm).toBe(false);
				expect(util._detectSupport('acdf').ampm).toBe(false);
			});

			it('should detect support for timezone', function() {
				expect(util._detectSupport('z').timezone).toBe(true);
				expect(util._detectSupport('Z').timezone).toBe(true);

				expect(util._detectSupport('acdf').timezone).toBe(false);
			});

			it('should detect support for iso8601', function() {
				expect(util._detectSupport('Z').iso8601).toBe(true);

				expect(util._detectSupport('z').iso8601).toBe(false);
				expect(util._detectSupport('acdf').iso8601).toBe(false);
			});
		});

		describe('selectLocalTimezone', function() {
			var timepicker,
				timezoneOffset,
				defaultTimezoneOffset;

			beforeEach(function() {
				timepicker = {
					timezone_select: affix('select')
				};
				var now = new Date();
				timezoneOffset = String(-now.getTimezoneOffset());
				defaultTimezoneOffset = String(timezoneOffset - 60);
				timepicker.timezone_select.affix('option').text(defaultTimezoneOffset);
				timepicker.timezone_select.affix('option').text(timezoneOffset);
				timepicker.timezone_select.affix('option').text(timezoneOffset + 60);

			});

			it('should do nothing for a falsey timepicker', function() {
				util._selectLocalTimezone(undefined);

				expect(timepicker.timezone_select.val()).toBe(defaultTimezoneOffset);
			});

			it('should do nothing for a timepicker with a falsey timezone_select', function() {
				util._selectLocalTimezone({});

				expect(timepicker.timezone_select.val()).toBe(defaultTimezoneOffset);
			});

			it('should select the current timezone with a valid timezone_select and no date', function() {
				util._selectLocalTimezone(timepicker);

				expect(timepicker.timezone_select.val()).toBe(timezoneOffset);
			});

			it('should select the current timezone with a valid timezone_select and a date', function() {
				util._selectLocalTimezone(timepicker, new Date());

				expect(timepicker.timezone_select.val()).toBe(timezoneOffset);
			});
		});

		describe('computeEffectiveSetting', function() {
			it('pulls the setting from the passed settings object if it is there', function() {
				var expectedUniqueValue = 'This is very unique',
					settings = {
						property: expectedUniqueValue
					};

				expect(util._computeEffectiveSetting(settings, 'property')).toBe(expectedUniqueValue);
			});

			it('pulls the setting from the timepicker defaults if there are no passed settings', function() {
				var expectedValue = $.timepicker._defaults.separator;
				expect(expectedValue).toBeDefined();

				expect(util._computeEffectiveSetting(undefined, 'separator')).toBe(expectedValue);
			});

			it('pulls the setting from the timepicker defaults if not present in the passed settings', function() {
				var expectedValue = $.timepicker._defaults.separator,
					settings = {};
				expect(expectedValue).toBeDefined();

				expect(util._computeEffectiveSetting(settings, 'separator')).toBe(expectedValue);
			});
		});

		describe('splitDateTime', function() {
			var expectedDateString = '3/6/1967',
				expectedTimeString = '07:32';

			it('splits a date and time into its parts using the default separator', function() {
				var inputDateTimeString = expectedDateString + $.timepicker._defaults.separator + expectedTimeString,
					result;

				result = $.timepicker._util._splitDateTime(inputDateTimeString, {});

				expect(result).toEqual({dateString: expectedDateString, timeString: expectedTimeString});
			});

			it('splits a date and time into its parts using a supplied separator', function() {
				var separator = '-',
					inputDateTimeString = expectedDateString + separator + expectedTimeString,
					result;

				result = $.timepicker._util._splitDateTime(inputDateTimeString, {separator: separator});

				expect(result).toEqual({dateString: expectedDateString, timeString: expectedTimeString});
			});

			it('splits a date and time into its parts when there are multiple separators in the time format', function() {
				var timeFormat = 'hh mm tt',
					separator = ' ',
					alternateTimeString = '07 32 am',
					inputDateTimeString = expectedDateString + separator + alternateTimeString,
					timeSettings = {separator: separator, timeFormat: timeFormat},
					result;

				result = $.timepicker._util._splitDateTime(inputDateTimeString, timeSettings);

				expect(result).toEqual({dateString: expectedDateString, timeString: alternateTimeString});
			});

			it('splits only a date into itself', function() {
				var result = $.timepicker._util._splitDateTime(expectedDateString, {});

				expect(result).toEqual({dateString: expectedDateString, timeString: ''});
			});
		});

		describe('parseDateTimeInternal', function() {
			var dateFormat = 'mm/dd/yy';

			it('should return only a date if there is no time component', function() {
				var inputDateString = '9/11/2001',
					expectedDate = new Date(inputDateString),
					result;

				result = util._parseDateTimeInternal(dateFormat, undefined, inputDateString, undefined, undefined);

				expect(result.date).toEqual(expectedDate);
				expect(result.timeObj).toBeUndefined();
			});

			it('should return a date and a parsed time if a time is included', function() {
				var expectedDateString = '7/4/1976',
					expectedParsedTime = {
						hour: 1,
						minute: 23,
						second: 45,
						millisec: 678,
						microsec: 0
					},
					inputDateTimeString = expectedDateString + ' ' +
											expectedParsedTime.hour + ':' +
											expectedParsedTime.minute + ':' +
											expectedParsedTime.second + '.' +
											expectedParsedTime.millisec,
					expectedDate = new Date(expectedDateString),
					result;

				result = util._parseDateTimeInternal(dateFormat, 'H:m:s.l', inputDateTimeString, undefined, undefined);

				expect(result.date).toEqual(expectedDate);
				expect(result.timeObj).toEqual(expectedParsedTime);
			});

			it('should throw an exception if it cannot parse the time', function() {
				var inputDateString = '4/17/2008 11:22:33';

				expect(function() {
					util._parseDateTimeInternal(dateFormat, 'q', inputDateString, undefined, undefined);
				}).toThrow('Wrong time format');
			});
		});
	});

	describe('timepicker functions', function() {
		describe('timezoneOffsetNumber', function() {
			it('returns 0 if the time zone string is iso8601 Zulu', function() {
				expect($.timepicker.timezoneOffsetNumber('Z')).toBe(0);
				expect($.timepicker.timezoneOffsetNumber('z')).toBe(0);
				expect($.timepicker.timezoneOffsetNumber(':Z')).toBe(0);
			});

			it('returns a string that does not match the expected representations', function() {
				expect($.timepicker.timezoneOffsetNumber('EDT')).toBe('EDT');
				expect($.timepicker.timezoneOffsetNumber('1234')).toBe('1234');
				expect($.timepicker.timezoneOffsetNumber('+123')).toBe('+123');
				expect($.timepicker.timezoneOffsetNumber('-123')).toBe('-123');
				expect($.timepicker.timezoneOffsetNumber('abc:def')).toBe('abc:def');
			});

			it('returns the minute offset from a time zone offset string', function() {
				expect($.timepicker.timezoneOffsetNumber('-0000')).toBe(0);
				expect($.timepicker.timezoneOffsetNumber('+0000')).toBe(0);
				expect($.timepicker.timezoneOffsetNumber('-0400')).toBe(-240);
				expect($.timepicker.timezoneOffsetNumber('+0400')).toBe(240);
			});
		});

		describe('timezoneOffsetString', function() {
			it('returns NaN if the input is NaN', function() {
				expect($.timepicker.timezoneOffsetString(NaN, false)).toBeNaN();
			});

			it('returns the input if the input is greater than 840 (+14:00)', function() {
				var expectedMinutes = 850;

				var actualMinutes = $.timepicker.timezoneOffsetString(expectedMinutes, false);

				expect(actualMinutes).toBe(expectedMinutes);
			});

			it('returns the input if the input is less than -720 (-12:00)', function() {
				var expectedMinutes = -730;

				var actualMinutes = $.timepicker.timezoneOffsetString(expectedMinutes, false);

				expect(actualMinutes).toBe(expectedMinutes);
			});

			it('returns "Z" if the offset is 0 and iso8601 is true', function() {
				expect($.timepicker.timezoneOffsetString(0, true)).toBe('Z');
			});

			it('returns the expected offset string for non-iso8601 values', function() {
				expect($.timepicker.timezoneOffsetString(0, false)).toBe('+0000');
				expect($.timepicker.timezoneOffsetString(60, false)).toBe('+0100');
				expect($.timepicker.timezoneOffsetString(480, false)).toBe('+0800');
				expect($.timepicker.timezoneOffsetString(-60, false)).toBe('-0100');
				expect($.timepicker.timezoneOffsetString(-480, false)).toBe('-0800');
				expect($.timepicker.timezoneOffsetString(-720, false)).toBe('-1200');
				expect($.timepicker.timezoneOffsetString(840, false)).toBe('+1400');
			});

			it('returns the expected offset string for iso8601 values', function() {
				expect($.timepicker.timezoneOffsetString(60, true)).toBe('+01:00');
				expect($.timepicker.timezoneOffsetString(480, true)).toBe('+08:00');
				expect($.timepicker.timezoneOffsetString(-60, true)).toBe('-01:00');
				expect($.timepicker.timezoneOffsetString(-480, true)).toBe('-08:00');
				expect($.timepicker.timezoneOffsetString(-720, true)).toBe('-12:00');
				expect($.timepicker.timezoneOffsetString(840, true)).toBe('+14:00');
			});

			it('handles abnormal values reasonably', function() {
				expect($.timepicker.timezoneOffsetString(null, false)).toBe('+0000');
				expect($.timepicker.timezoneOffsetString(null, true)).toBe('Z');

				expect($.timepicker.timezoneOffsetString(undefined, false)).toBeUndefined();
				expect($.timepicker.timezoneOffsetString(undefined, true)).toBeUndefined();
			});
		});

		describe('timezoneAdjust', function() {
			it('does not change the date if the timezone yields NaN for an offset', function() {
				var expectedDate = new Date();

				expect($.timepicker.timezoneAdjust(expectedDate, NaN)).toEqual(expectedDate);
			});

			it('changes the minutes by the time zone offset minutes', function() {
				var inputDate,
					originalMillis,
					expectedDifference,
					adjustedDate;

				inputDate = new Date();
				originalMillis = inputDate.getTime();
				expectedDifference = -(inputDate.getTimezoneOffset() + 60) * 60 * 1000;

				adjustedDate = $.timepicker.timezoneAdjust(inputDate, '+0100');

				expect(adjustedDate.getTime() - originalMillis).toBe(expectedDifference);
			});
		});

		describe('log', function() {
			it('calls console.log with the message if the console exists', function() {
				var expectedMessage = "Just what I expected!";
				spyOn(window.console, "log");

				$.timepicker.log(expectedMessage);

				expect(window.console.log).toHaveBeenCalledWith(expectedMessage);
			});

			it('does not call console.log if there is no console', function() {
				var originalConsole = window.console,
					consoleLogSpy = spyOn(window.console, "log");
				window.console = undefined;

				$.timepicker.log("Don't care");

				expect(consoleLogSpy).not.toHaveBeenCalled();

				window.console = originalConsole;
			});
		});

		describe('range functions', function() {
			var startTime = $('<p>start</p>'),
				endTime = $('<p>end</p>'),
				options = {};

			describe('convenience functions', function() {
				beforeEach(function() {
					spyOn($.timepicker, 'handleRange');
				});

				it('timeRange calls handleRange the right way', function() {
					$.timepicker.timeRange(startTime, endTime, options);

					expect($.timepicker.handleRange).toHaveBeenCalledWith('timepicker', startTime, endTime, options);
				});

				it('datetimeRange calls handleRange the right way', function() {
					$.timepicker.datetimeRange(startTime, endTime, options);

					expect($.timepicker.handleRange).toHaveBeenCalledWith('datetimepicker', startTime, endTime, options);
				});

				it('dateRange calls handleRange the right way', function() {
					$.timepicker.dateRange(startTime, endTime, options);

					expect($.timepicker.handleRange).toHaveBeenCalledWith('datepicker', startTime, endTime, options);
				});
			});

			xdescribe('handleRange', function() {
				// TODO: Difficult to test. Needs attention.
			});
		});
	});

	describe('datepicker functions', function() {
		describe('formatTime', function() {
			describe('single formats, default options', function() {
				var emptyTime = {};

				describe('hours', function() {
					var earlyHour = {hour: 7},
						lateHour = {hour: 17};

					it('formats HH correctly', function() {
						expect($.datepicker.formatTime('HH', emptyTime)).toBe('00');
						expect($.datepicker.formatTime('HH', earlyHour)).toBe('07');
						expect($.datepicker.formatTime('HH', lateHour)).toBe('17');
					});

					it('formats H correctly', function() {
						expect($.datepicker.formatTime('H', emptyTime)).toBe('0');
						expect($.datepicker.formatTime('H', earlyHour)).toBe('7');
						expect($.datepicker.formatTime('H', lateHour)).toBe('17');
					});

					it('formats hh correctly', function() {
						expect($.datepicker.formatTime('hh', emptyTime)).toBe('12');
						expect($.datepicker.formatTime('hh', earlyHour)).toBe('07');
						expect($.datepicker.formatTime('hh', lateHour)).toBe('05');
					});

					it('formats h correctly', function() {
						expect($.datepicker.formatTime('h', emptyTime)).toBe('12');
						expect($.datepicker.formatTime('h', earlyHour)).toBe('7');
						expect($.datepicker.formatTime('h', lateHour)).toBe('5');
					});
				});

				describe('minutes', function() {
					var singleDigitMinute = {minute: 3},
						doubleDigitMinute = {minute: 42};

					it('formats mm correctly', function() {
						expect($.datepicker.formatTime('mm', emptyTime)).toBe('00');
						expect($.datepicker.formatTime('mm', singleDigitMinute)).toBe('03');
						expect($.datepicker.formatTime('mm', doubleDigitMinute)).toBe('42');
					});

					it('formats m correctly', function() {
						expect($.datepicker.formatTime('m', emptyTime)).toBe('0');
						expect($.datepicker.formatTime('m', singleDigitMinute)).toBe('3');
						expect($.datepicker.formatTime('m', doubleDigitMinute)).toBe('42');
					});
				});

				describe('seconds', function() {
					var singleDigitSecond = {second: 5},
						doubleDigitSecond = {second: 31};

					it('formats ss correctly', function() {
						expect($.datepicker.formatTime('ss', emptyTime)).toBe('00');
						expect($.datepicker.formatTime('ss', singleDigitSecond)).toBe('05');
						expect($.datepicker.formatTime('ss', doubleDigitSecond)).toBe('31');
					});

					it('formats s correctly', function() {
						expect($.datepicker.formatTime('s', emptyTime)).toBe('0');
						expect($.datepicker.formatTime('s', singleDigitSecond)).toBe('5');
						expect($.datepicker.formatTime('s', doubleDigitSecond)).toBe('31');
					});
				});

				describe('milliseconds', function() {
					it('formats l correctly', function() {
						var singleDigitMillis = {millisec: 3},
							doubleDigitMillis = {millisec: 17},
							tripleDigitMillis = {millisec: 123};

						expect($.datepicker.formatTime('l', emptyTime)).toBe('000');
						expect($.datepicker.formatTime('l', singleDigitMillis)).toBe('003');
						expect($.datepicker.formatTime('l', doubleDigitMillis)).toBe('017');
						expect($.datepicker.formatTime('l', tripleDigitMillis)).toBe('123');
					});
				});

				describe('microseconds', function() {
					it('formats c correctly', function() {
						var singleDigitMicros = {microsec: 3},
							doubleDigitMicros = {microsec: 17},
							tripleDigitMicros = {microsec: 123};

						expect($.datepicker.formatTime('c', emptyTime)).toBe('000');
						expect($.datepicker.formatTime('c', singleDigitMicros)).toBe('003');
						expect($.datepicker.formatTime('c', doubleDigitMicros)).toBe('017');
						expect($.datepicker.formatTime('c', tripleDigitMicros)).toBe('123');
					});
				});

				describe('timezone', function() {
					var nullTimezoneTime = {timezone: null},
						noTimezoneTime = emptyTime,
						timezoneTime = {timezone: -240},
						noTimezoneOptions = {},
						timezoneOptions = {timezone: 600};

					it('handles z correctly', function() {
						expect($.datepicker.formatTime('z', timezoneTime, noTimezoneOptions)).toBe('-0400');
						expect($.datepicker.formatTime('z', timezoneTime, timezoneOptions)).toBe('-0400');

						expect($.datepicker.formatTime('z', nullTimezoneTime, timezoneOptions)).toBe('+1000');
						expect($.datepicker.formatTime('z', noTimezoneTime, timezoneOptions)).toBe('+1000');
						expect($.datepicker.formatTime('z', nullTimezoneTime, noTimezoneOptions)).toBe('+0000');
						expect($.datepicker.formatTime('z', noTimezoneTime, noTimezoneOptions)).toBe('+0000');
					});

					it('handles Z correctly', function() {
						expect($.datepicker.formatTime('Z', timezoneTime, noTimezoneOptions)).toBe('-04:00');
						expect($.datepicker.formatTime('Z', timezoneTime, timezoneOptions)).toBe('-04:00');

						expect($.datepicker.formatTime('Z', nullTimezoneTime, timezoneOptions)).toBe('+10:00');
						expect($.datepicker.formatTime('Z', noTimezoneTime, timezoneOptions)).toBe('+10:00');
						expect($.datepicker.formatTime('Z', nullTimezoneTime, noTimezoneOptions)).toBe('Z');
						expect($.datepicker.formatTime('Z', noTimezoneTime, noTimezoneOptions)).toBe('Z');
					});
				});

				describe('am/pm', function() {
					var morningHour = {hour: 3},
						afternoonHour = {hour: 15};

					it('formats t correctly', function() {
						expect($.datepicker.formatTime('t', emptyTime)).toBe('a');
						expect($.datepicker.formatTime('t', morningHour)).toBe('a');
						expect($.datepicker.formatTime('t', afternoonHour)).toBe('p');
					});

					it('formats T correctly', function() {
						expect($.datepicker.formatTime('T', emptyTime)).toBe('A');
						expect($.datepicker.formatTime('T', morningHour)).toBe('A');
						expect($.datepicker.formatTime('T', afternoonHour)).toBe('P');
					});

					it('formats tt correctly', function() {
						expect($.datepicker.formatTime('tt', emptyTime)).toBe('am');
						expect($.datepicker.formatTime('tt', morningHour)).toBe('am');
						expect($.datepicker.formatTime('tt', afternoonHour)).toBe('pm');
					});

					it('formats TT correctly', function() {
						expect($.datepicker.formatTime('TT', emptyTime)).toBe('AM');
						expect($.datepicker.formatTime('TT', morningHour)).toBe('AM');
						expect($.datepicker.formatTime('TT', afternoonHour)).toBe('PM');
					});
				});

				describe('literals', function() {
					it('handles literals correctly', function() {
						expect($.datepicker.formatTime('', emptyTime)).toBe('');
						expect($.datepicker.formatTime("'abc'", emptyTime)).toBe('abc');
						expect($.datepicker.formatTime("'", emptyTime)).toBe("'");
						expect($.datepicker.formatTime("''", emptyTime)).toBe("");
						expect($.datepicker.formatTime("'abc' h 'def'", emptyTime)).toBe('abc 12 def');
					});

					it('does not treat double quotes as literals', function() {
						expect($.datepicker.formatTime('"ab"', emptyTime)).toBe('"ab"');
						expect($.datepicker.formatTime('"abc"', emptyTime)).toBe('"ab000"');
					});
				});
			});

			describe('preserves whitespace in formats', function() {
				it('preserves leading whitespace', function() {
					expect($.datepicker.formatTime(' H', {hour: 3})).toBe(' 3');
				});

				it('preserves trailing whitespace', function() {
					expect($.datepicker.formatTime('H ', {hour: 3})).toBe('3 ');
				});
			});
		});
	});

	describe('methods', function() {
		describe('setDate', function() {
			it('should accept null as date', function() {
				var $input = affix('input').datetimepicker();
				$input.datetimepicker('setDate', '2013-11-25 15:30:25');

				$input.datetimepicker('setDate', null);

				expect($input.datetimepicker('getDate')).toBeNull();
			});
		});
	});
});