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