Skip to content

Commit 99f250b

Browse files
iso8601 option removed, pulls from support property
1 parent 4a1d222 commit 99f250b

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

index.html

+1-3
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,6 @@ <h3>Alt Field Options</h3>
211211
<h3>Timezone Options</h3>
212212
<dl class="defs">
213213

214-
<dt>timezoneIso8601</dt>
215-
<dd><em>Default: false</em> - Whether to follow the ISO 8601 standard.</dd>
216-
217214
<dt>timezoneList</dt>
218215
<dd><em>Default: [generated timezones]</em> - An array of timezones used to populate the timezone select. Can be an array of values or an array of objects: { label: "EST", value: "+0400" }</dd>
219216
</dl>
@@ -418,6 +415,7 @@ <h2>Formatting Your Time</h2>
418415
<dt>tt</dt><dd>am or pm for AM/PM</dd>
419416
<dt>TT</dt><dd>AM or PM for AM/PM</dd>
420417
<dt>z</dt><dd>Timezone as defined by timezoneList</dd>
418+
<dt>Z</dt><dd>Timezone in Iso 8601 format (+04:45)</dd>
421419
<dt>'...'</dt><dd>Literal text (Uses single quotes)</dd>
422420
</dl>
423421

jquery-ui-timepicker-addon.js

+38-36
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
pickerTimeFormat: null,
105105
pickerTimeSuffix: null,
106106
showTimepicker: true,
107-
timezoneIso8601: false,
108107
timezoneList: null,
109108
addSliderAccess: false,
110109
sliderAccessArgs: null,
@@ -245,15 +244,16 @@
245244
'+0100', '+0200', '+0300', '+0330', '+0400', '+0430', '+0500', '+0530', '+0545', '+0600', '+0630', '+0700', '+0800', '+0845', '+0900', '+0930',
246245
'+1000', '+1030', '+1100', '+1130', '+1200', '+1245', '+1300', '+1400'];
247246

248-
if (tp_inst._defaults.timezoneIso8601) {
247+
if (tp_inst.support.iso8601) {
249248
timezoneList = $.map(timezoneList, function(val) {
250249
return val == '+0000' ? 'Z' : (val.substring(0, 3) + ':' + val.substring(3));
251250
});
252251
}
253252
tp_inst._defaults.timezoneList = timezoneList;
254253
}
255254

256-
tp_inst.timezone = tp_inst._defaults.timezone !== null? tp_inst._defaults.timezone : $.timepicker.timezoneOffsetString((new Date()).getTimezoneOffset());
255+
tp_inst.timezone = tp_inst._defaults.timezone !== null? tp_inst._defaults.timezone :
256+
$.timepicker.timezoneOffsetString((new Date()).getTimezoneOffset(), tp_inst.support.iso8601);
257257
tp_inst.hour = tp_inst._defaults.hour < tp_inst._defaults.hourMin? tp_inst._defaults.hourMin :
258258
tp_inst._defaults.hour > tp_inst._defaults.hourMax? tp_inst._defaults.hourMax : tp_inst._defaults.hour;
259259
tp_inst.minute = tp_inst._defaults.minute < tp_inst._defaults.minuteMin? tp_inst._defaults.minuteMin :
@@ -477,7 +477,7 @@
477477
}));
478478
if (typeof(this.timezone) != "undefined" && this.timezone !== null && this.timezone !== "") {
479479
var local_date = new Date(this.inst.selectedYear, this.inst.selectedMonth, this.inst.selectedDay, 12);
480-
var local_timezone = $.timepicker.timezoneOffsetString(local_date.getTimezoneOffset());
480+
var local_timezone = $.timepicker.timezoneOffsetString(local_date.getTimezoneOffset(), this.support.iso8601);
481481
if (local_timezone == this.timezone) {
482482
selectLocalTimezone(tp_inst);
483483
} else {
@@ -1082,7 +1082,8 @@
10821082
* Public utility to parse time
10831083
*/
10841084
$.datepicker.parseTime = function(timeFormat, timeString, options) {
1085-
var o = extendRemove(extendRemove({}, $.timepicker._defaults), options || {});
1085+
var o = extendRemove(extendRemove({}, $.timepicker._defaults), options || {}),
1086+
iso8601 = (timeFormat.replace(/\'.*?\'/g,'').indexOf('Z') !== -1);
10861087

10871088
// Strict parse requires the timeString to match the timeFormat exactly
10881089
var strictParse = function(f, s, o){
@@ -1126,7 +1127,7 @@
11261127
};
11271128

11281129
var regstr = '^' + f.toString()
1129-
.replace(/([hH]{1,2}|mm?|ss?|[tT]{1,2}|[lcz]|'.*?')/g, function (match) {
1130+
.replace(/([hH]{1,2}|mm?|ss?|[tT]{1,2}|[zZ]|[lc]|'.*?')/g, function (match) {
11301131
var ml = match.length;
11311132
switch (match.charAt(0).toLowerCase()) {
11321133
case 'h': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})';
@@ -1193,27 +1194,28 @@
11931194
}
11941195
if (order.z !== -1 && treg[order.z] !== undefined) {
11951196
var tz = treg[order.z].toUpperCase();
1197+
11961198
switch (tz.length) {
1197-
case 1:
1198-
// Z
1199-
tz = o.timezoneIso8601 ? 'Z' : '+0000';
1200-
break;
1201-
case 5:
1202-
// +hhmm
1203-
if (o.timezoneIso8601) {
1204-
tz = tz.substring(1) == '0000' ? 'Z' : tz.substring(0, 3) + ':' + tz.substring(3);
1205-
}
1206-
break;
1207-
case 6:
1208-
// +hh:mm
1209-
if (!o.timezoneIso8601) {
1210-
tz = tz == 'Z' || tz.substring(1) == '00:00' ? '+0000' : tz.replace(/:/, '');
1211-
} else {
1212-
if (tz.substring(1) == '00:00') {
1213-
tz = 'Z';
1199+
case 1:
1200+
// Z
1201+
tz = iso8601 ? 'Z' : '+0000';
1202+
break;
1203+
case 5:
1204+
// +hhmm
1205+
if (iso8601) {
1206+
tz = tz.substring(1) == '0000' ? 'Z' : tz.substring(0, 3) + ':' + tz.substring(3);
12141207
}
1215-
}
1216-
break;
1208+
break;
1209+
case 6:
1210+
// +hh:mm
1211+
if (!iso8601) {
1212+
tz = tz == 'Z' || tz.substring(1) == '00:00' ? '+0000' : tz.replace(/:/, '');
1213+
} else {
1214+
if (tz.substring(1) == '00:00') {
1215+
tz = 'Z';
1216+
}
1217+
}
1218+
break;
12171219
}
12181220
resTime.timezone = tz;
12191221
}
@@ -1244,7 +1246,7 @@
12441246
second: d.getSeconds(),
12451247
millisec: d.getMilliseconds(),
12461248
microsec: d.getMicroseconds(),
1247-
timezone: $.timepicker.timezoneOffsetString(d.getTimezoneOffset())
1249+
timezone: $.timepicker.timezoneOffsetString(d.getTimezoneOffset(), iso8601)
12481250
};
12491251
}
12501252
catch(err){
@@ -1292,7 +1294,7 @@
12921294
ampmName = options.pmNames[0];
12931295
}
12941296

1295-
tmptime = tmptime.replace(/(?:HH?|hh?|mm?|ss?|[tT]{1,2}|[lcz]|('.*?'|".*?"))/g, function(match) {
1297+
tmptime = tmptime.replace(/(?:HH?|hh?|mm?|ss?|[tT]{1,2}|[zZ]|[lc]|('.*?'|".*?"))/g, function(match) {
12961298
switch (match) {
12971299
case 'HH':
12981300
return ('0' + hour).slice(-2);
@@ -1316,6 +1318,8 @@
13161318
return ('00' + time.microsec).slice(-3);
13171319
case 'z':
13181320
return time.timezone === null? options.timezone : time.timezone;
1321+
case 'Z':
1322+
return time.timezone === null? options.timezone : time.timezone;
13191323
case 'T':
13201324
return ampmName.charAt(0).toUpperCase();
13211325
case 'TT':
@@ -1796,7 +1800,8 @@
17961800
millisec: isIn(tf,'l'),
17971801
microsec: isIn(tf,'c'),
17981802
timezone: isIn(tf,'z'),
1799-
ampm: isIn('t') && isIn(timeFormat,'h')
1803+
ampm: isIn('t') && isIn(timeFormat,'h'),
1804+
iso8601: isIn(timeFormat, 'Z')
18001805
};
18011806
};
18021807

@@ -1897,10 +1902,7 @@
18971902
var selectLocalTimezone = function(tp_inst, date) {
18981903
if (tp_inst && tp_inst.timezone_select) {
18991904
var now = typeof date !== 'undefined' ? date : new Date();
1900-
var tzoffset = $.timepicker.timezoneOffsetString(now.getTimezoneOffset());
1901-
if (tp_inst._defaults.timezoneIso8601) {
1902-
tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3);
1903-
}
1905+
var tzoffset = $.timepicker.timezoneOffsetString(now.getTimezoneOffset(), tp_inst.support.iso8601);
19041906
tp_inst.timezone_select.val(tzoffset);
19051907
}
19061908
};
@@ -1913,14 +1915,14 @@
19131915
/**
19141916
* Get the timezone offset as string from a date object (eg '+0530' for UTC+5.5)
19151917
* @param date
1916-
* @param boolean if true formats in accordance to iso1806 "+12:45"
1918+
* @param boolean if true formats in accordance to iso8601 "+12:45"
19171919
* @return string
19181920
*/
1919-
$.timepicker.timezoneOffsetString = function(tzMinutes, iso1806) {
1921+
$.timepicker.timezoneOffsetString = function(tzMinutes, iso8601) {
19201922
var off = tzMinutes * -1,
19211923
minutes = off % 60,
19221924
hours = (off - minutes) / 60,
1923-
iso = iso1806? ':':'',
1925+
iso = iso8601? ':':'',
19241926
tz = (off >= 0 ? '+' : '-') + ('0' + (hours * 101).toString()).slice(-2) + iso + ('0' + (minutes * 101).toString()).slice(-2);
19251927

19261928
if(tz == '+00:00'){
@@ -1935,7 +1937,7 @@
19351937
* @return number
19361938
*/
19371939
$.timepicker.timezoneOffsetNumber = function(tzString) {
1938-
tzString = tzString.replace(/(\:|z)/gi,''); // excuse any iso1806, end up with "+1245"
1940+
tzString = tzString.replace(/(\:|z)/gi,''); // excuse any iso8601, end up with "+1245"
19391941

19401942
if(!/^(\-|\+)\d{4}$/.test(tzString)){
19411943
return 0;

0 commit comments

Comments
 (0)