|
235 | 235 | tp_inst._defaults.timezoneList = timezoneList;
|
236 | 236 | }
|
237 | 237 |
|
238 |
| - tp_inst.timezone = tp_inst._defaults.timezone !== null? tp_inst._defaults.timezone : $.timepicker.timeZoneOffsetString((new Date()).getTimezoneOffset()); |
| 238 | + tp_inst.timezone = tp_inst._defaults.timezone !== null? tp_inst._defaults.timezone : $.timepicker.timezoneOffsetString((new Date()).getTimezoneOffset()); |
239 | 239 | tp_inst.hour = tp_inst._defaults.hour < tp_inst._defaults.hourMin? tp_inst._defaults.hourMin :
|
240 | 240 | tp_inst._defaults.hour > tp_inst._defaults.hourMax? tp_inst._defaults.hourMax : tp_inst._defaults.hour;
|
241 | 241 | tp_inst.minute = tp_inst._defaults.minute < tp_inst._defaults.minuteMin? tp_inst._defaults.minuteMin :
|
|
452 | 452 | }));
|
453 | 453 | if (typeof(this.timezone) != "undefined" && this.timezone !== null && this.timezone !== "") {
|
454 | 454 | var local_date = new Date(this.inst.selectedYear, this.inst.selectedMonth, this.inst.selectedDay, 12);
|
455 |
| - var local_timezone = $.timepicker.timeZoneOffsetString(local_date.getTimezoneOffset()); |
| 455 | + var local_timezone = $.timepicker.timezoneOffsetString(local_date.getTimezoneOffset()); |
456 | 456 | if (local_timezone == this.timezone) {
|
457 |
| - selectLocalTimeZone(tp_inst); |
| 457 | + selectLocalTimezone(tp_inst); |
458 | 458 | } else {
|
459 | 459 | this.timezone_select.val(this.timezone);
|
460 | 460 | }
|
461 | 461 | } else {
|
462 | 462 | if (typeof(this.hour) != "undefined" && this.hour !== null && this.hour !== "") {
|
463 | 463 | this.timezone_select.val(o.timezone);
|
464 | 464 | } else {
|
465 |
| - selectLocalTimeZone(tp_inst); |
| 465 | + selectLocalTimezone(tp_inst); |
466 | 466 | }
|
467 | 467 | }
|
468 | 468 | this.timezone_select.change(function() {
|
|
1174 | 1174 | minute: d.getMinutes(),
|
1175 | 1175 | second: d.getSeconds(),
|
1176 | 1176 | millisec: d.getMilliseconds(),
|
1177 |
| - timezone: $.timepicker.timeZoneOffsetString(d.getTimezoneOffset()) |
| 1177 | + timezone: $.timepicker.timezoneOffsetString(d.getTimezoneOffset()) |
1178 | 1178 | };
|
1179 | 1179 | }
|
1180 | 1180 | catch(err){
|
|
1406 | 1406 | $dp = inst.dpDiv;
|
1407 | 1407 | this._base_gotoToday(id);
|
1408 | 1408 | var tp_inst = this._get(inst, 'timepicker');
|
1409 |
| - selectLocalTimeZone(tp_inst); |
| 1409 | + selectLocalTimezone(tp_inst); |
1410 | 1410 | var now = new Date();
|
1411 | 1411 | this._setTime(inst, now);
|
1412 | 1412 | $('.ui-datepicker-today', $dp).click();
|
|
1507 | 1507 | return;
|
1508 | 1508 | }
|
1509 | 1509 |
|
1510 |
| - var tp_date = (date instanceof Date) ? new Date(date.getTime()) : date; |
| 1510 | + var tp_inst = this._get(inst, 'timepicker'), |
| 1511 | + tp_date = (date instanceof Date) ? new Date(date.getTime()) : date; |
| 1512 | + |
| 1513 | + // This is important if you are using the timezone option, javascript's Date |
| 1514 | + // object will only return the timezone offset for the current locale, so we |
| 1515 | + // adjust it accordingly. If not using timezone option this won't matter.. |
| 1516 | + // If a timezone is different in tp, keep the timezone as is |
| 1517 | + if(tp_inst && tp_inst.timezone != null){ |
| 1518 | + date = $.timepicker.timezoneAdjust(date, tp_inst.timezone); |
| 1519 | + tp_date = $.timepicker.timezoneAdjust(tp_date, tp_inst.timezone); |
| 1520 | + } |
1511 | 1521 |
|
1512 | 1522 | this._updateDatepicker(inst);
|
1513 | 1523 | this._base_setDateDatepicker.apply(this, arguments);
|
|
1540 | 1550 | // object will only return the timezone offset for the current locale, so we
|
1541 | 1551 | // adjust it accordingly. If not using timezone option this won't matter..
|
1542 | 1552 | if(tp_inst.timezone != null){
|
1543 |
| - date = $.timepicker.timeZoneAdjust(date, tp_inst.timezone); |
| 1553 | + date = $.timepicker.timezoneAdjust(date, tp_inst.timezone); |
1544 | 1554 | }
|
1545 | 1555 | }
|
1546 | 1556 | return date;
|
|
1796 | 1806 | /*
|
1797 | 1807 | * Internal function to set timezone_select to the local timezone
|
1798 | 1808 | */
|
1799 |
| - var selectLocalTimeZone = function(tp_inst, date) { |
| 1809 | + var selectLocalTimezone = function(tp_inst, date) { |
1800 | 1810 | if (tp_inst && tp_inst.timezone_select) {
|
1801 | 1811 | var now = typeof date !== 'undefined' ? date : new Date();
|
1802 |
| - var tzoffset = $.timepicker.timeZoneOffsetString(now.getTimezoneOffset()); |
| 1812 | + var tzoffset = $.timepicker.timezoneOffsetString(now.getTimezoneOffset()); |
1803 | 1813 | if (tp_inst._defaults.timezoneIso8601) {
|
1804 | 1814 | tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3);
|
1805 | 1815 | }
|
|
1818 | 1828 | * @param boolean if true formats in accordance to iso1806 "+12:45"
|
1819 | 1829 | * @return string
|
1820 | 1830 | */
|
1821 |
| - $.timepicker.timeZoneOffsetString = function(tzMinutes, iso1806) { |
| 1831 | + $.timepicker.timezoneOffsetString = function(tzMinutes, iso1806) { |
1822 | 1832 | var off = tzMinutes * -1,
|
1823 | 1833 | minutes = off % 60,
|
1824 | 1834 | hours = (off - minutes) / 60,
|
|
1836 | 1846 | * @param string formated like "+0500", "-1245"
|
1837 | 1847 | * @return number
|
1838 | 1848 | */
|
1839 |
| - $.timepicker.timeZoneOffsetNumber = function(tzString) { |
| 1849 | + $.timepicker.timezoneOffsetNumber = function(tzString) { |
1840 | 1850 | tzString = tzString.replace(/(\:|z)/gi,''); // excuse any iso1806, end up with "+1245"
|
1841 | 1851 |
|
1842 | 1852 | if(!/^(\-|\+)\d{4}$/.test(tzString)){
|
|
1848 | 1858 | };
|
1849 | 1859 |
|
1850 | 1860 | /**
|
1851 |
| - * No way to set timezone in js Date, so we must adjust the minutes to compensate |
| 1861 | + * No way to set timezone in js Date, so we must adjust the minutes to compensate. (think setDate, getDate) |
1852 | 1862 | * @param date
|
1853 | 1863 | * @param string formated like "+0500", "-1245"
|
1854 | 1864 | * @return date
|
1855 | 1865 | */
|
1856 |
| - $.timepicker.timeZoneAdjust = function(date, toTimeZone) { |
| 1866 | + $.timepicker.timezoneAdjust = function(date, toTimezone) { |
1857 | 1867 | var currTz = date.getTimezoneOffset(),
|
1858 |
| - toTz = $.timepicker.timeZoneOffsetNumber(toTimeZone)*-1, |
| 1868 | + toTz = $.timepicker.timezoneOffsetNumber(toTimezone)*-1, |
1859 | 1869 | diff = currTz - toTz; // difference in minutes
|
1860 | 1870 |
|
1861 | 1871 | date.setMinutes(date.getMinutes()+diff);
|
|
0 commit comments