Skip to content

Commit 3a7d3d7

Browse files
Merge pull request trentrichardson#424 from Zauberfisch/dev
BUGFIX timeZoneString UTC & UTC+5.5
2 parents 6ff9b7a + cd51fb3 commit 3a7d3d7

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

jquery-ui-timepicker-addon.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ $.extend(Timepicker.prototype, {
471471
);
472472
if (typeof(this.timezone) != "undefined" && this.timezone !== null && this.timezone !== "") {
473473
var local_date = new Date(this.inst.selectedYear, this.inst.selectedMonth, this.inst.selectedDay, 12);
474-
var local_timezone = timeZoneString(local_date);
474+
var local_timezone = $.timepicker.timeZoneOffsetString(local_date);
475475
if (local_timezone == this.timezone) {
476476
selectLocalTimeZone(tp_inst);
477477
} else {
@@ -1553,26 +1553,29 @@ var selectLocalTimeZone = function(tp_inst, date)
15531553
if (tp_inst && tp_inst.timezone_select) {
15541554
tp_inst._defaults.useLocalTimezone = true;
15551555
var now = typeof date !== 'undefined' ? date : new Date();
1556-
var tzoffset = timeZoneString(now);
1556+
var tzoffset = $.timepicker.timeZoneOffsetString(now);
15571557
if (tp_inst._defaults.timezoneIso8601) {
15581558
tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3);
15591559
}
15601560
tp_inst.timezone_select.val(tzoffset);
15611561
}
15621562
};
15631563

1564-
// Input: Date Object
1565-
// Output: String with timezone offset, e.g. '+0100'
1566-
var timeZoneString = function(date)
1567-
{
1568-
var off = date.getTimezoneOffset() * -10100 / 60;
1569-
var timezone = (off >= 0 ? '+' : '-') + Math.abs(off).toString().substr(1);
1570-
return timezone;
1571-
};
1572-
15731564
$.timepicker = new Timepicker(); // singleton instance
15741565
$.timepicker.version = "1.0.2";
15751566

1567+
/**
1568+
* Get the timezone offset as string from a date object (eg '+0530' for UTC+5.5)
1569+
* @param date
1570+
* @return string
1571+
*/
1572+
$.timepicker.timeZoneOffsetString = function(date) {
1573+
var off = date.getTimezoneOffset() * -1,
1574+
minutes = off % 60,
1575+
hours = (off-minutes) / 60;
1576+
return (off >= 0 ? '+' : '-') + ('0'+(hours*101).toString()).substr(-2) + ('0'+(minutes*101).toString()).substr(-2);
1577+
};
1578+
15761579
//#######################################################################################
15771580
// Changes by simonvwade to better handle time range limits
15781581
//#######################################################################################

0 commit comments

Comments
 (0)