|
73 | 73 | var self = this;
|
74 | 74 |
|
75 | 75 | /**
|
76 |
| - * overwrite jQuery UI datepicker function. |
| 76 | + * Overwrite jQuery UI datepicker function. |
| 77 | + * Reason: magento date could be set before calendar show |
| 78 | + * but local date will be styled as current in original _generateHTML |
| 79 | + * |
77 | 80 | * @param {Object} inst - instance datepicker.
|
78 | 81 | * @return {String} html template
|
79 | 82 | */
|
80 | 83 | $.datepicker.constructor.prototype._generateHTML = function (inst) {
|
81 |
| - var today = this._daylightSavingAdjust(self.getTimezoneDate()), |
| 84 | + var today = self.getTimezoneDate(), |
82 | 85 | isRTL = this._get(inst, 'isRTL'),
|
83 | 86 | showButtonPanel = this._get(inst, 'showButtonPanel'),
|
84 | 87 | hideIfNoPrevNext = this._get(inst, 'hideIfNoPrevNext'),
|
|
313 | 316 |
|
314 | 317 | /**
|
315 | 318 | * If server timezone is defined then take to account server timezone shift
|
316 |
| - * @param {Object} date |
317 | 319 | * @return {Object} date
|
318 | 320 | */
|
319 |
| - getTimezoneDate: function (date) { |
320 |
| - date = date || new Date(); |
| 321 | + getTimezoneDate: function () { |
321 | 322 |
|
322 |
| - if (this.options.serverTimezoneSeconds) { |
323 |
| - date.setTime((this.options.serverTimezoneSeconds + date.getTimezoneOffset() * 60) * 1000); |
| 323 | + // Get local time in ms |
| 324 | + var ms = Date.now(); |
| 325 | + |
| 326 | + // Adjust milliseconds according to store timezone offset |
| 327 | + // Mind the GMT zero offset |
| 328 | + if (typeof this.options.serverTimezoneOffset !== 'undefined') { |
| 329 | + // Make UTC time and add store timezone offset in seconds |
| 330 | + ms += (new Date().getTimezoneOffset() * 60 * 1000) + this.options.serverTimezoneOffset * 1000; |
324 | 331 | }
|
325 | 332 |
|
326 |
| - return date; |
| 333 | + return new Date(ms); |
327 | 334 | },
|
328 | 335 |
|
329 | 336 | /**
|
|
515 | 522 | * @param {Object} el
|
516 | 523 | */
|
517 | 524 | $.datepicker._gotoToday = function (el) {
|
518 |
| - $.datepicker._gotoTodayOriginal.call(this, el); |
519 |
| - $.datepicker._selectDate.call(this, el); |
520 |
| - $(el).blur(); // To ensure that user can re-select date field without clicking outside it first. |
| 525 | + var pickerObject = $(el); |
| 526 | + |
| 527 | + // Set date/time according to timezone offset |
| 528 | + pickerObject.datepicker( "setDate", pickerObject.calendar("getTimezoneDate") ) |
| 529 | + // To ensure that user can re-select date field without clicking outside it first. |
| 530 | + .blur(); |
521 | 531 | };
|
522 | 532 |
|
523 | 533 | return {
|
|
0 commit comments