Skip to content

Commit 859a118

Browse files
committed
MAGETWO-53299: "Go Today" button is not working for dates range component
- return to static method and widget prototype extending
1 parent e11a310 commit 859a118

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

lib/web/mage/calendar.js

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,45 @@
2424
var calendarBasePrototype,
2525
datepickerPrototype = $.datepicker.constructor.prototype;
2626

27+
$.datepicker.markerClassName = '_has-datepicker';
28+
29+
/**
30+
* Get date/time according to store settings.
31+
* We use serverTimezoneOffset (in seconds) instead of serverTimezoneSeconds
32+
* in order to have ability to know actual store time even if page hadn't been reloaded
33+
* @returns {Date}
34+
*/
35+
function getTimezoneDate() {
36+
37+
// local time in ms
38+
var ms = Date.now(),
39+
options = $.calendarConfig ? $.calendarConfig : {};
40+
41+
// Adjust milliseconds according to store timezone offset,
42+
// mind the GMT zero offset
43+
if (typeof options.serverTimezoneOffset !== 'undefined') {
44+
// Make UTC time and add store timezone offset in seconds
45+
ms += new Date().getTimezoneOffset() * 60 * 1000 + options.serverTimezoneOffset * 1000;
46+
} else if (typeof options.serverTimezoneSeconds !== 'undefined') {
47+
//Set milliseconds according to client local timezone offset
48+
ms = (options.serverTimezoneSeconds + new Date().getTimezoneOffset() * 60) * 1000;
49+
}
50+
51+
return new Date(ms);
52+
}
53+
2754
/**
2855
* Extend JQuery date picker prototype with store local time methods
2956
*/
3057
$.extend(datepickerPrototype, {
3158

3259
/**
33-
* Get date/time according to store settings.
34-
* We use serverTimezoneOffset (in seconds) instead of serverTimezoneSeconds
35-
* in order to have ability to know actual store time even if page hadn't been reloaded
60+
* Get date/time according to store settings
3661
* @returns {Date}
62+
* @private
3763
*/
3864
_getTimezoneDate: function () {
39-
// local time in ms
40-
var ms = Date.now(),
41-
options = $.calendarConfig ? $.calendarConfig : {};
42-
43-
// Adjust milliseconds according to store timezone offset,
44-
// mind the GMT zero offset
45-
if (typeof options.serverTimezoneOffset !== 'undefined') {
46-
// Make UTC time and add store timezone offset in seconds
47-
ms += new Date().getTimezoneOffset() * 60 * 1000 + options.serverTimezoneOffset * 1000;
48-
} else if (typeof options.serverTimezoneSeconds !== 'undefined') {
49-
//Set milliseconds according to client local timezone offset
50-
ms = (options.serverTimezoneSeconds + new Date().getTimezoneOffset() * 60) * 1000;
51-
}
52-
53-
return new Date(ms);
65+
return getTimezoneDate();
5466
},
5567

5668
/**
@@ -62,8 +74,6 @@
6274
}
6375
});
6476

65-
$.datepicker.markerClassName = '_has-datepicker';
66-
6777
/**
6878
* Widget calendar
6979
*/
@@ -396,7 +406,7 @@
396406
* @return {Object} date
397407
*/
398408
getTimezoneDate: function () {
399-
return datepickerPrototype._getTimezoneDate.call(this);
409+
return getTimezoneDate();
400410
}
401411
});
402412

0 commit comments

Comments
 (0)