summaryrefslogtreecommitdiffstats
path: root/jquery-ui-timepicker-addon.js
diff options
context:
space:
mode:
authorVaughn Draughon <vaughn@rocksolidwebdesign.com>2012-10-23 21:38:30 -0600
committerVaughn Draughon <vaughn@rocksolidwebdesign.com>2012-10-23 21:38:30 -0600
commitfc244f36e50adc0db1311528d0e80b192caf47f2 (patch)
tree8680fba80df30874b05c010a2d20bc2432a6126d /jquery-ui-timepicker-addon.js
parentbdd14b9c6d152acf7f89e65611617f4e2ad91428 (diff)
downloadjQuery-Timepicker-Addon-fc244f36e50adc0db1311528d0e80b192caf47f2.zip
jQuery-Timepicker-Addon-fc244f36e50adc0db1311528d0e80b192caf47f2.tar.gz
jQuery-Timepicker-Addon-fc244f36e50adc0db1311528d0e80b192caf47f2.tar.bz2
Added 12 hour option to formatTime
Diffstat (limited to 'jquery-ui-timepicker-addon.js')
-rw-r--r--jquery-ui-timepicker-addon.js36
1 files changed, 27 insertions, 9 deletions
diff --git a/jquery-ui-timepicker-addon.js b/jquery-ui-timepicker-addon.js
index 47877e8..c57d59b 100644
--- a/jquery-ui-timepicker-addon.js
+++ b/jquery-ui-timepicker-addon.js
@@ -1130,6 +1130,26 @@
return false;
};
+ _convert24to12 = function(hour) {
+ if (hour > 12) {
+ hour = hour - 12;
+ }
+
+ if (hour == 0) {
+ hour = 12;
+ }
+
+ var result;
+ if (hour < 10) {
+ result = "0" + hour;
+ }
+ else {
+ result = String(hour);
+ }
+
+ return result;
+ };
+
/*
* Public utility to format the time
* format = string format of the time
@@ -1154,16 +1174,14 @@
if (options.ampm) {
if (hour > 11) {
ampmName = options.pmNames[0];
- if (hour > 12) {
- hour = hour % 12;
- }
- }
- if (hour === 0) {
- hour = 12;
}
}
- tmptime = tmptime.replace(/(?:hh?|mm?|ss?|[tT]{1,2}|[lz]|'.*?')/g, function(match) {
- switch (match.toLowerCase()) {
+ tmptime = tmptime.replace(/(?:HH?|hh?|mm?|ss?|[tT]{1,2}|[lz]|('.*?'|".*?"))/g, function(match) {
+ switch (match) {
+ case 'HH':
+ return _convert24to12(hour).slice(-2);
+ case 'H':
+ return _convert24to12(hour);
case 'hh':
return ('0' + hour).slice(-2);
case 'h':
@@ -1847,4 +1865,4 @@
*/
$.timepicker.version = "1.1.0";
-})(jQuery); \ No newline at end of file
+})(jQuery);