Skip to content

Commit 399d980

Browse files
committed
Merge remote-tracking branch 'trentrichardson/dev' into l10n-ampm
2 parents 95ee51e + 67386ec commit 399d980

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

jquery-ui-timepicker-addon.js

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,8 @@ function Timepicker() {
8181
separator: ' ',
8282
altFieldTimeOnly: true,
8383
showTimepicker: true,
84-
timezoneList: ["-1100", "-1000", "-0900", "-0800", "-0700", "-0600",
85-
"-0500", "-0400", "-0300", "-0200", "-0100", "+0000",
86-
"+0100", "+0200", "+0300", "+0400", "+0500", "+0600",
87-
"+0700", "+0800", "+0900", "+1000", "+1100", "+1200"]
84+
timezoneIso8609: false,
85+
timezoneList: null
8886
};
8987
$.extend(this._defaults, this.regional['']);
9088
}
@@ -116,10 +114,7 @@ $.extend(Timepicker.prototype, {
116114
formattedDate: '',
117115
formattedTime: '',
118116
formattedDateTime: '',
119-
timezoneList: ["-1100", "-1000", "-0900", "-0800", "-0700", "-0600",
120-
"-0500", "-0400", "-0300", "-0200", "-0100", "+0000",
121-
"+0100", "+0200", "+0300", "+0400", "+0500", "+0600",
122-
"+0700", "+0800", "+0900", "+1000", "+1100", "+1200"],
117+
timezoneList: null,
123118

124119
/* Override the default settings for all instances of the time picker.
125120
@param settings object - the new settings to use as defaults (anonymous object)
@@ -168,6 +163,17 @@ $.extend(Timepicker.prototype, {
168163
tp_inst.amNames = $.map(tp_inst._defaults.amNames, function(val) { return val.toUpperCase() });
169164
tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function(val) { return val.toUpperCase() });
170165

166+
if (tp_inst._defaults.timezoneList === null) {
167+
var timezoneList = [];
168+
for (var i = -11; i <= 12; i++)
169+
timezoneList.push((i >= 0 ? '+' : '-') + ('0' + Math.abs(i).toString()).slice(-2) + '00');
170+
if (tp_inst._defaults.timezoneIso8609)
171+
timezoneList = $.map(timezoneList, function(val) {
172+
return val == '+0000' ? 'Z' : (val.substring(0, 3) + ':' + val.substring(3));
173+
});
174+
tp_inst._defaults.timezoneList = timezoneList;
175+
}
176+
171177
tp_inst.hour = tp_inst._defaults.hour;
172178
tp_inst.minute = tp_inst._defaults.minute;
173179
tp_inst.second = tp_inst._defaults.second;
@@ -224,7 +230,7 @@ $.extend(Timepicker.prototype, {
224230
.replace(/s{1,2}/ig, '(\\d?\\d)')
225231
.replace(/l{1}/ig, '(\\d?\\d?\\d)')
226232
.replace(/t{1,2}/ig, this._getPatternAmpm())
227-
.replace(/z{1}/ig, '((\\+|-)\\d\\d\\d\\d)?')
233+
.replace(/z{1}/ig, '(z|[-+]\\d\\d:?\\d\\d)?')
228234
.replace(/\s/g, '\\s?') + this._defaults.timeSuffix + '$',
229235
order = this._getFormatPositions(),
230236
ampm = '',
@@ -265,7 +271,29 @@ $.extend(Timepicker.prototype, {
265271
if (order.m !== -1) this.minute = Number(treg[order.m]);
266272
if (order.s !== -1) this.second = Number(treg[order.s]);
267273
if (order.l !== -1) this.millisec = Number(treg[order.l]);
268-
if (order.z !== -1) this.timezone = treg[order.z];
274+
if (order.z !== -1 && treg[order.z] !== undefined) {
275+
var tz = treg[order.z].toUpperCase();
276+
switch (tz.length) {
277+
case 1: // Z
278+
tz = this._defaults.timezoneIso8609 ? 'Z' : '+0000';
279+
break;
280+
case 5: // +hhmm
281+
if (this._defaults.timezoneIso8609)
282+
tz = tz.substring(1) == '0000'
283+
? 'Z'
284+
: tz.substring(0, 3) + ':' + tz.substring(3);
285+
break;
286+
case 6: // +hh:mm
287+
if (!this._defaults.timezoneIso8609)
288+
tz = tz == 'Z' || tz.substring(1) == '00:00'
289+
? '+0000'
290+
: tz.replace(/:/, '');
291+
else if (tz.substring(1) == '00:00')
292+
tz = 'Z';
293+
break;
294+
}
295+
this.timezone = tz;
296+
}
269297

270298
return true;
271299

@@ -1025,6 +1053,8 @@ $.datepicker._gotoToday = function(id) {
10251053
tzoffset = Math.abs(tzoffset);
10261054
var tzmin = tzoffset % 60
10271055
tzoffset = tzsign + ('0' + (tzoffset - tzmin) / 60).slice(-2) + ('0' + tzmin).slice(-2);
1056+
if (tp_inst._defaults.timezoneIso8609)
1057+
tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3);
10281058
tp_inst.timezone_select.val(tzoffset);
10291059
}
10301060
this._setTime(inst, now);

0 commit comments

Comments
 (0)