summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Vance <steve@vance.com>2013-07-27 16:20:06 -0400
committerStephen Vance <steve@vance.com>2013-07-27 16:20:06 -0400
commit356868a0a2516de9cadb0163b5bffc50edb1b9ff (patch)
tree418451a00face31773a07ce9b1d0ed5ad036c3a9
parentb872d7403ce770e3ed8b7ea5207452660549f42d (diff)
downloadjQuery-Timepicker-Addon-356868a0a2516de9cadb0163b5bffc50edb1b9ff.zip
jQuery-Timepicker-Addon-356868a0a2516de9cadb0163b5bffc50edb1b9ff.tar.gz
jQuery-Timepicker-Addon-356868a0a2516de9cadb0163b5bffc50edb1b9ff.tar.bz2
Start the tests for $.datepicker.formatTime(), fix a bug in it for microsecond handling, and change the method comments to jsdoc.
-rw-r--r--jquery-ui-timepicker-addon.js14
-rw-r--r--test/jquery-ui-timepicker-addon_spec.js112
2 files changed, 119 insertions, 7 deletions
diff --git a/jquery-ui-timepicker-addon.js b/jquery-ui-timepicker-addon.js
index f8edf43..2297428 100644
--- a/jquery-ui-timepicker-addon.js
+++ b/jquery-ui-timepicker-addon.js
@@ -1251,12 +1251,13 @@
return strictParse(timeFormat, timeString, o);
};
- /*
- * Public utility to format the time
- * format = string format of the time
- * time = a {}, not a Date() for timezones
- * options = essentially the regional[].. amNames, pmNames, ampm
- */
+ /**
+ * Public utility to format the time
+ * @param {string} format format of the time
+ * @param {Object} time Object not a Date for timezones
+ * @param {Object} options essentially the regional[].. amNames, pmNames, ampm
+ * @returns {string} the formatted time
+ */
$.datepicker.formatTime = function(format, time, options) {
options = options || {};
options = $.extend({}, $.timepicker._defaults, options);
@@ -1265,6 +1266,7 @@
minute: 0,
second: 0,
millisec: 0,
+ microsec: 0,
timezone: 0
}, time);
diff --git a/test/jquery-ui-timepicker-addon_spec.js b/test/jquery-ui-timepicker-addon_spec.js
index 4676c25..8c49f08 100644
--- a/test/jquery-ui-timepicker-addon_spec.js
+++ b/test/jquery-ui-timepicker-addon_spec.js
@@ -87,7 +87,7 @@ describe('datetimepicker', function() {
var expectedValue = 11;
expect(util._convert24to12(expectedValue + 12 * 3)).toBe("" + expectedValue);
- })
+ });
});
describe('detectSupport', function() {
@@ -461,4 +461,114 @@ describe('datetimepicker', function() {
});
});
});
+
+ 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');
+ });
+ });
+
+ // TODO: Should microseconds be three digits or six? Does this complement millis or replace? The regexp looks like it replaces.
+ describe('microseconds', function() {
+ it('formats c correctly', function() {
+ var singleDigitMillis = {microsec: 3},
+ doubleDigitMillis = {microsec: 17},
+ tripleDigitMillis = {microsec: 123};
+
+ expect($.datepicker.formatTime('c', emptyTime)).toBe('000');
+ expect($.datepicker.formatTime('c', singleDigitMillis)).toBe('003');
+ expect($.datepicker.formatTime('c', doubleDigitMillis)).toBe('017');
+ expect($.datepicker.formatTime('c', tripleDigitMillis)).toBe('123');
+ });
+ });
+
+ describe('timezone', function() {
+ // TODO: Finish
+ });
+
+ describe('am/pm', function() {
+ // TODO: Finish
+ });
+
+ describe('other', function() {
+ // TODO: Finish
+ });
+ });
+ });
+ });
}); \ No newline at end of file