Skip to content

Commit 313e55d

Browse files
committed
Pick the current timezone of the browser by default.
1 parent 704c0b9 commit 313e55d

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

jquery-ui-timepicker-addon.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ $.extend(Timepicker.prototype, {
110110
minute: 0,
111111
second: 0,
112112
millisec: 0,
113-
timezone: '+0000',
114113
hourMinOriginal: null,
115114
minuteMinOriginal: null,
116115
secondMinOriginal: null,
@@ -444,7 +443,11 @@ $.extend(Timepicker.prototype, {
444443
.text(typeof val == "object" ? val.label : val);
445444
})
446445
);
447-
this.timezone_select.val((typeof this.timezone != "undefined" && this.timezone != null && this.timezone != "") ? this.timezone : o.timezone);
446+
if (typeof this.timezone != "undefined" && this.timezone != null && this.timezone != "") {
447+
this.timezone_select.val(this.timezone);
448+
} else {
449+
selectLocalTimeZone(tp_inst);
450+
}
448451
this.timezone_select.change(function() {
449452
tp_inst._onTimeChange();
450453
});
@@ -1125,18 +1128,9 @@ $.datepicker._gotoToday = function(id) {
11251128
var inst = this._getInst($(id)[0]),
11261129
$dp = inst.dpDiv;
11271130
this._base_gotoToday(id);
1128-
var now = new Date();
11291131
var tp_inst = this._get(inst, 'timepicker');
1130-
if (tp_inst && tp_inst._defaults.showTimezone && tp_inst.timezone_select) {
1131-
var tzoffset = now.getTimezoneOffset(); // If +0100, returns -60
1132-
var tzsign = tzoffset > 0 ? '-' : '+';
1133-
tzoffset = Math.abs(tzoffset);
1134-
var tzmin = tzoffset % 60;
1135-
tzoffset = tzsign + ('0' + (tzoffset - tzmin) / 60).slice(-2) + ('0' + tzmin).slice(-2);
1136-
if (tp_inst._defaults.timezoneIso8601)
1137-
tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3);
1138-
tp_inst.timezone_select.val(tzoffset);
1139-
}
1132+
selectLocalTimeZone(tp_inst);
1133+
var now = new Date();
11401134
this._setTime(inst, now);
11411135
$( '.ui-datepicker-today', $dp).click();
11421136
};
@@ -1403,6 +1397,24 @@ var parseDateTimeInternal = function(dateFormat, timeFormat, dateTimeString, dat
14031397
return {date: date};
14041398
}
14051399

1400+
//#######################################################################################
1401+
// Internal function to set timezone_select to the local timezone
1402+
//#######################################################################################
1403+
var selectLocalTimeZone = function(tp_inst)
1404+
{
1405+
if (tp_inst && tp_inst._defaults.showTimezone && tp_inst.timezone_select) {
1406+
var now = new Date();
1407+
var tzoffset = now.getTimezoneOffset(); // If +0100, returns -60
1408+
var tzsign = tzoffset > 0 ? '-' : '+';
1409+
tzoffset = Math.abs(tzoffset);
1410+
var tzmin = tzoffset % 60;
1411+
tzoffset = tzsign + ('0' + (tzoffset - tzmin) / 60).slice(-2) + ('0' + tzmin).slice(-2);
1412+
if (tp_inst._defaults.timezoneIso8601)
1413+
tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3);
1414+
tp_inst.timezone_select.val(tzoffset);
1415+
}
1416+
}
1417+
14061418
$.timepicker = new Timepicker(); // singleton instance
14071419
$.timepicker.version = "1.0.1";
14081420

0 commit comments

Comments
 (0)