summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Vance <steve@vance.com>2013-07-06 17:23:42 -0400
committerStephen Vance <steve@vance.com>2013-07-06 22:19:55 -0400
commit3c4e42e60e0a9e994f50586c079bf0b1ded369a0 (patch)
tree2b4fa081e15b2805c844daa6ebe416b95782d909
parentea4252ea21bb010eec88d9377d71ade2aa85d90e (diff)
downloadjQuery-Timepicker-Addon-3c4e42e60e0a9e994f50586c079bf0b1ded369a0.zip
jQuery-Timepicker-Addon-3c4e42e60e0a9e994f50586c079bf0b1ded369a0.tar.gz
jQuery-Timepicker-Addon-3c4e42e60e0a9e994f50586c079bf0b1ded369a0.tar.bz2
Test and simplify convert24to12, including making it resistant to out of bounds values.
-rw-r--r--jquery-ui-timepicker-addon.js7
-rw-r--r--test/jquery-ui-timepicker-addon_spec.js24
2 files changed, 27 insertions, 4 deletions
diff --git a/jquery-ui-timepicker-addon.js b/jquery-ui-timepicker-addon.js
index 584244c..973ac61 100644
--- a/jquery-ui-timepicker-addon.js
+++ b/jquery-ui-timepicker-addon.js
@@ -1814,9 +1814,7 @@
* Returns 12 hour without leading 0
*/
var convert24to12 = function(hour) {
- if (hour > 12) {
- hour = hour - 12;
- }
+ hour %= 12;
if (hour === 0) {
hour = 12;
@@ -2112,7 +2110,8 @@
*/
$.timepicker.util = {
_extendRemove: extendRemove,
- _isEmptyObject: isEmptyObject
+ _isEmptyObject: isEmptyObject,
+ _convert24to12: convert24to12
};
/*
diff --git a/test/jquery-ui-timepicker-addon_spec.js b/test/jquery-ui-timepicker-addon_spec.js
index 94ee485..29f8648 100644
--- a/test/jquery-ui-timepicker-addon_spec.js
+++ b/test/jquery-ui-timepicker-addon_spec.js
@@ -65,5 +65,29 @@ describe('datetimepicker', function() {
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);
+ })
+ });
});
}); \ No newline at end of file