Skip to content

Commit 19dfb8c

Browse files
Merge pull request trentrichardson#492 from rocksolidwebdesign/dev
12 hour format, force alt field to always be UTC
2 parents bdd14b9 + fc244f3 commit 19dfb8c

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

jquery-ui-timepicker-addon.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,26 @@
11301130
return false;
11311131
};
11321132

1133+
_convert24to12 = function(hour) {
1134+
if (hour > 12) {
1135+
hour = hour - 12;
1136+
}
1137+
1138+
if (hour == 0) {
1139+
hour = 12;
1140+
}
1141+
1142+
var result;
1143+
if (hour < 10) {
1144+
result = "0" + hour;
1145+
}
1146+
else {
1147+
result = String(hour);
1148+
}
1149+
1150+
return result;
1151+
};
1152+
11331153
/*
11341154
* Public utility to format the time
11351155
* format = string format of the time
@@ -1154,16 +1174,14 @@
11541174
if (options.ampm) {
11551175
if (hour > 11) {
11561176
ampmName = options.pmNames[0];
1157-
if (hour > 12) {
1158-
hour = hour % 12;
1159-
}
1160-
}
1161-
if (hour === 0) {
1162-
hour = 12;
11631177
}
11641178
}
1165-
tmptime = tmptime.replace(/(?:hh?|mm?|ss?|[tT]{1,2}|[lz]|'.*?')/g, function(match) {
1166-
switch (match.toLowerCase()) {
1179+
tmptime = tmptime.replace(/(?:HH?|hh?|mm?|ss?|[tT]{1,2}|[lz]|('.*?'|".*?"))/g, function(match) {
1180+
switch (match) {
1181+
case 'HH':
1182+
return _convert24to12(hour).slice(-2);
1183+
case 'H':
1184+
return _convert24to12(hour);
11671185
case 'hh':
11681186
return ('0' + hour).slice(-2);
11691187
case 'h':
@@ -1847,4 +1865,4 @@
18471865
*/
18481866
$.timepicker.version = "1.1.0";
18491867

1850-
})(jQuery);
1868+
})(jQuery);

0 commit comments

Comments
 (0)