|
73 | 73 | second: 0,
|
74 | 74 | millisec: 0,
|
75 | 75 | timezone: null,
|
76 |
| - useLocalTimezone: false, |
77 |
| - defaultTimezone: "+0000", |
78 | 76 | hourMin: 0,
|
79 | 77 | minuteMin: 0,
|
80 | 78 | secondMin: 0,
|
|
125 | 123 | second: 0,
|
126 | 124 | millisec: 0,
|
127 | 125 | timezone: null,
|
128 |
| - defaultTimezone: "+0000", |
129 | 126 | hourMinOriginal: null,
|
130 | 127 | minuteMinOriginal: null,
|
131 | 128 | secondMinOriginal: null,
|
|
158 | 155 | _newInst: function($input, o) {
|
159 | 156 | var tp_inst = new Timepicker(),
|
160 | 157 | inlineSettings = {},
|
161 |
| - fns = {}, |
162 |
| - overrides, i; |
| 158 | + fns = {}, |
| 159 | + overrides, i; |
163 | 160 |
|
164 | 161 | for (var attrName in this._defaults) {
|
165 | 162 | if(this._defaults.hasOwnProperty(attrName)){
|
|
173 | 170 | }
|
174 | 171 | }
|
175 | 172 | }
|
| 173 | + |
176 | 174 | overrides = {
|
177 | 175 | beforeShow: function (input, dp_inst) {
|
178 | 176 | if ($.isFunction(tp_inst._defaults.evnts.beforeShow)) {
|
|
200 | 198 | fns[i] = o[i] || null;
|
201 | 199 | }
|
202 | 200 | }
|
| 201 | + |
203 | 202 | tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, overrides, {
|
204 | 203 | evnts:fns,
|
205 | 204 | timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
|
|
236 | 235 | tp_inst._defaults.timezoneList = timezoneList;
|
237 | 236 | }
|
238 | 237 |
|
239 |
| - tp_inst.timezone = tp_inst._defaults.timezone; |
| 238 | + tp_inst.timezone = tp_inst._defaults.timezone !== null? tp_inst._defaults.timezone : $.timepicker.timeZoneOffsetString((new Date()).getTimezoneOffset()); |
240 | 239 | tp_inst.hour = tp_inst._defaults.hour < tp_inst._defaults.hourMin? tp_inst._defaults.hourMin :
|
241 | 240 | tp_inst._defaults.hour > tp_inst._defaults.hourMax? tp_inst._defaults.hourMax : tp_inst._defaults.hour;
|
242 | 241 | tp_inst.minute = tp_inst._defaults.minute < tp_inst._defaults.minuteMin? tp_inst._defaults.minuteMin :
|
|
453 | 452 | }));
|
454 | 453 | if (typeof(this.timezone) != "undefined" && this.timezone !== null && this.timezone !== "") {
|
455 | 454 | var local_date = new Date(this.inst.selectedYear, this.inst.selectedMonth, this.inst.selectedDay, 12);
|
456 |
| - var local_timezone = $.timepicker.timeZoneOffsetString(local_date); |
| 455 | + var local_timezone = $.timepicker.timeZoneOffsetString(local_date.getTimezoneOffset()); |
457 | 456 | if (local_timezone == this.timezone) {
|
458 | 457 | selectLocalTimeZone(tp_inst);
|
459 | 458 | } else {
|
460 | 459 | this.timezone_select.val(this.timezone);
|
461 | 460 | }
|
462 | 461 | } else {
|
463 | 462 | if (typeof(this.hour) != "undefined" && this.hour !== null && this.hour !== "") {
|
464 |
| - this.timezone_select.val(o.defaultTimezone); |
| 463 | + this.timezone_select.val(o.timezone); |
465 | 464 | } else {
|
466 | 465 | selectLocalTimeZone(tp_inst);
|
467 | 466 | }
|
468 | 467 | }
|
469 | 468 | this.timezone_select.change(function() {
|
470 |
| - tp_inst._defaults.useLocalTimezone = false; |
471 | 469 | tp_inst._onTimeChange();
|
472 | 470 | tp_inst._onSelectHandler();
|
473 | 471 | });
|
|
698 | 696 | // If the update was done using the sliders, update the input field.
|
699 | 697 | var hasChanged = (hour != this.hour || minute != this.minute || second != this.second || millisec != this.millisec
|
700 | 698 | || (this.ampm.length > 0 && (hour < 12) != ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1))
|
701 |
| - || ((this.timezone === null && timezone != this.defaultTimezone) || (this.timezone !== null && timezone != this.timezone))); |
| 699 | + || (this.timezone !== null && timezone != this.timezone)); |
702 | 700 |
|
703 | 701 | if (hasChanged) {
|
704 | 702 |
|
|
1176 | 1174 | minute: d.getMinutes(),
|
1177 | 1175 | second: d.getSeconds(),
|
1178 | 1176 | millisec: d.getMilliseconds(),
|
1179 |
| - timezone: $.timepicker.timeZoneOffsetString(d) |
| 1177 | + timezone: $.timepicker.timeZoneOffsetString(d.getTimezoneOffset()) |
1180 | 1178 | };
|
1181 | 1179 | }
|
1182 | 1180 | catch(err){
|
|
1245 | 1243 | case 'l':
|
1246 | 1244 | return ('00' + time.millisec).slice(-3);
|
1247 | 1245 | case 'z':
|
1248 |
| - return time.timezone === null? options.defaultTimezone : time.timezone; |
| 1246 | + return time.timezone === null? options.timezone : time.timezone; |
1249 | 1247 | case 'T':
|
1250 | 1248 | return ampmName.charAt(0).toUpperCase();
|
1251 | 1249 | case 'TT':
|
|
1306 | 1304 | var tp_inst = this._get(inst, 'timepicker');
|
1307 | 1305 | if (tp_inst) {
|
1308 | 1306 | tp_inst._addTimePicker(inst);
|
1309 |
| - |
1310 |
| -// if (tp_inst._defaults.useLocalTimezone) { //checks daylight saving with the new date. |
1311 |
| -// var date = new Date(inst.selectedYear, inst.selectedMonth, inst.selectedDay, 12); |
1312 |
| -// selectLocalTimeZone(tp_inst, date); |
1313 |
| -// tp_inst._onTimeChange(); |
1314 |
| -// } |
1315 | 1307 | }
|
1316 | 1308 | }
|
1317 | 1309 | };
|
|
1543 | 1535 | var date = this._getDate(inst);
|
1544 | 1536 | if (date && tp_inst._parseTime($(target).val(), tp_inst.timeOnly)) {
|
1545 | 1537 | date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
|
| 1538 | + |
| 1539 | + // This is important if you are using the timezone option, javascript's Date |
| 1540 | + // object will only return the timezone offset for the current locale, so we |
| 1541 | + // adjust it accordingly. If not using timezone option this won't matter.. |
| 1542 | + if(tp_inst.timezone != null){ |
| 1543 | + date = $.timepicker.timeZoneAdjust(date, tp_inst.timezone); |
| 1544 | + } |
1546 | 1545 | }
|
1547 | 1546 | return date;
|
1548 | 1547 | }
|
|
1799 | 1798 | */
|
1800 | 1799 | var selectLocalTimeZone = function(tp_inst, date) {
|
1801 | 1800 | if (tp_inst && tp_inst.timezone_select) {
|
1802 |
| - tp_inst._defaults.useLocalTimezone = true; |
1803 | 1801 | var now = typeof date !== 'undefined' ? date : new Date();
|
1804 |
| - var tzoffset = $.timepicker.timeZoneOffsetString(now); |
| 1802 | + var tzoffset = $.timepicker.timeZoneOffsetString(now.getTimezoneOffset()); |
1805 | 1803 | if (tp_inst._defaults.timezoneIso8601) {
|
1806 | 1804 | tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3);
|
1807 | 1805 | }
|
|
1817 | 1815 | /**
|
1818 | 1816 | * Get the timezone offset as string from a date object (eg '+0530' for UTC+5.5)
|
1819 | 1817 | * @param date
|
| 1818 | + * @param boolean if true formats in accordance to iso1806 "+12:45" |
1820 | 1819 | * @return string
|
1821 | 1820 | */
|
1822 |
| - $.timepicker.timeZoneOffsetString = function(date) { |
1823 |
| - var off = date.getTimezoneOffset() * -1, |
| 1821 | + $.timepicker.timeZoneOffsetString = function(tzMinutes, iso1806) { |
| 1822 | + var off = tzMinutes * -1, |
1824 | 1823 | minutes = off % 60,
|
1825 |
| - hours = (off - minutes) / 60; |
1826 |
| - return (off >= 0 ? '+' : '-') + ('0' + (hours * 101).toString()).slice(-2) + ('0' + (minutes * 101).toString()).slice(-2); |
| 1824 | + hours = (off - minutes) / 60, |
| 1825 | + iso = iso1806? ':':'', |
| 1826 | + tz = (off >= 0 ? '+' : '-') + ('0' + (hours * 101).toString()).slice(-2) + iso + ('0' + (minutes * 101).toString()).slice(-2); |
| 1827 | + |
| 1828 | + if(tz == '+00:00'){ |
| 1829 | + return 'Z'; |
| 1830 | + } |
| 1831 | + return tz; |
| 1832 | + }; |
| 1833 | + |
| 1834 | + /** |
| 1835 | + * Get the number in minutes that represents a timezone string |
| 1836 | + * @param string formated like "+0500", "-1245" |
| 1837 | + * @return number |
| 1838 | + */ |
| 1839 | + $.timepicker.timeZoneOffsetNumber = function(tzString) { |
| 1840 | + tzString = tzString.replace(/(\:|z)/gi,''); // excuse any iso1806, end up with "+1245" |
| 1841 | + |
| 1842 | + if(!/^(\-|\+)\d{4}$/.test(tzString)){ |
| 1843 | + return 0; |
| 1844 | + } |
| 1845 | + return ((tzString.substr(0,1) =='-'? -1 : 1) * // plus or minus |
| 1846 | + ((parseInt(tzString.substr(1,2),10)*60) + // hours (converted to minutes) |
| 1847 | + parseInt(tzString.substr(3,2),10))); // minutes |
| 1848 | + }; |
| 1849 | + |
| 1850 | + /** |
| 1851 | + * No way to set timezone in js Date, so we must adjust the minutes to compensate |
| 1852 | + * @param date |
| 1853 | + * @param string formated like "+0500", "-1245" |
| 1854 | + * @return date |
| 1855 | + */ |
| 1856 | + $.timepicker.timeZoneAdjust = function(date, toTimeZone) { |
| 1857 | + var currTz = date.getTimezoneOffset(), |
| 1858 | + toTz = $.timepicker.timeZoneOffsetNumber(toTimeZone)*-1, |
| 1859 | + diff = currTz - toTz; // difference in minutes |
| 1860 | + |
| 1861 | + date.setMinutes(date.getMinutes()+diff); |
| 1862 | + |
| 1863 | + return date; |
1827 | 1864 | };
|
1828 | 1865 |
|
1829 | 1866 | /**
|
|
0 commit comments