Skip to content

Commit d6cc2ce

Browse files
committed
Refactored internals to calculate the timeZoneString.
1 parent e657640 commit d6cc2ce

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

jquery-ui-timepicker-addon.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -1423,17 +1423,22 @@ var selectLocalTimeZone = function(tp_inst, date)
14231423
if (tp_inst && tp_inst._defaults.showTimezone && tp_inst.timezone_select) {
14241424
tp_inst.useLocalTimezone = true;
14251425
var now = typeof date !== 'undefined' ? date : new Date();
1426-
var tzoffset = now.getTimezoneOffset(); // If +0100, returns -60
1427-
var tzsign = tzoffset > 0 ? '-' : '+';
1428-
tzoffset = Math.abs(tzoffset);
1429-
var tzmin = tzoffset % 60;
1430-
tzoffset = tzsign + ('0' + (tzoffset - tzmin) / 60).slice(-2) + ('0' + tzmin).slice(-2);
1426+
var tzoffset = timeZoneString(now);
14311427
if (tp_inst._defaults.timezoneIso8601)
14321428
tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3);
14331429
tp_inst.timezone_select.val(tzoffset);
14341430
}
14351431
}
14361432

1433+
// Input: Date Object
1434+
// Output: String with timezone offset, e.g. '+0100'
1435+
var timeZoneString = function(date)
1436+
{
1437+
var off = date.getTimezoneOffset() * -10100 / 60;
1438+
var timezone = (off >= 0 ? '+' : '-') + Math.abs(off).toString().substr(1);
1439+
return timezone;
1440+
}
1441+
14371442
$.timepicker = new Timepicker(); // singleton instance
14381443
$.timepicker.version = "1.0.1";
14391444

0 commit comments

Comments
 (0)