Skip to content

Commit d7efe16

Browse files
author
Volodymyr Zaets
committed
Merge remote-tracking branch 'origin/MAGETWO-51629' into PR
2 parents b5b73f9 + e0fcf63 commit d7efe16

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

app/code/Magento/Backend/view/adminhtml/templates/page/js/calendar.phtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ require([
5050
showTime: false,
5151
showHour: false,
5252
showMinute: false,
53+
serverTimezoneSeconds: <?php echo (int) $block->getStoreTimestamp(); ?>,
5354
yearRange: '<?php /* @escapeNotVerified */ echo $block->getYearRange() ?>'
5455
}
5556
});

lib/web/mage/calendar.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,15 @@
7575
var self = this;
7676

7777
/**
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+
*
7982
* @param {Object} inst - instance datepicker.
8083
* @return {String} html template
8184
*/
8285
$.datepicker.constructor.prototype._generateHTML = function (inst) {
83-
var today = this._daylightSavingAdjust(self.getTimezoneDate()),
86+
var today = self.getTimezoneDate(),
8487
isRTL = this._get(inst, 'isRTL'),
8588
showButtonPanel = this._get(inst, 'showButtonPanel'),
8689
hideIfNoPrevNext = this._get(inst, 'hideIfNoPrevNext'),
@@ -315,17 +318,20 @@
315318

316319
/**
317320
* If server timezone is defined then take to account server timezone shift
318-
* @param {Object} date
319321
* @return {Object} date
320322
*/
321-
getTimezoneDate: function (date) {
322-
date = date || new Date();
323+
getTimezoneDate: function () {
323324

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;
326332
}
327333

328-
return date;
334+
return new Date(ms);
329335
},
330336

331337
/**
@@ -518,9 +524,12 @@
518524
* @param {Object} el
519525
*/
520526
$.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();
524533
};
525534

526535
return {

0 commit comments

Comments
 (0)