|
21 | 21 | }(function ($) {
|
22 | 22 | 'use strict';
|
23 | 23 |
|
24 |
| - var calendarBasePrototype; |
| 24 | + var calendarBasePrototype, |
| 25 | + datepickerPrototype = $.datepicker.constructor.prototype; |
25 | 26 |
|
26 | 27 | /**
|
27 |
| - * Get date/time according to store settings |
28 |
| - * @returns {Date} |
| 28 | + * Extend JQuery date picker prototype with store local time methods |
29 | 29 | */
|
30 |
| - function getTimezoneDate() { |
31 |
| - // Get local time in ms |
32 |
| - var ms = Date.now(), |
33 |
| - options = $.calendarConfig ? $.calendarConfig : {}; |
34 |
| - |
35 |
| - // Use store timestamp based on store timezone settings |
36 |
| - if (typeof options.serverTimezoneSeconds !== 'undefined') { |
37 |
| - //Adjust milliseconds according to client local timezone offset |
38 |
| - ms = (options.serverTimezoneSeconds + new Date().getTimezoneOffset() * 60) * 1000; |
39 |
| - } |
| 30 | + $.extend(datepickerPrototype, { |
40 | 31 |
|
41 |
| - return new Date(ms); |
42 |
| - } |
| 32 | + /** |
| 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 |
| 36 | + * @returns {Date} |
| 37 | + */ |
| 38 | + _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 this.options.serverTimezoneSeconds !== 'undefined') { |
| 49 | + //Set milliseconds according to client local timezone offset |
| 50 | + ms = (this.options.serverTimezoneSeconds + new Date().getTimezoneOffset() * 60) * 1000; |
| 51 | + } |
| 52 | + |
| 53 | + return new Date(ms); |
| 54 | + }, |
| 55 | + |
| 56 | + /** |
| 57 | + * Set date/time according to store settings. |
| 58 | + * @param {String|Object} target - the target input field or division or span |
| 59 | + */ |
| 60 | + _setTimezoneDateDatepicker: function (target) { |
| 61 | + this._setDateDatepicker(target, this._getTimezoneDate()); |
| 62 | + } |
| 63 | + }); |
43 | 64 |
|
44 | 65 | $.datepicker.markerClassName = '_has-datepicker';
|
45 | 66 |
|
|
99 | 120 | * @return {String} html template
|
100 | 121 | */
|
101 | 122 | $.datepicker.constructor.prototype._generateHTML = function (inst) {
|
102 |
| - var today = getTimezoneDate(), |
| 123 | + var today = this._getTimezoneDate(), |
103 | 124 | isRTL = this._get(inst, 'isRTL'),
|
104 | 125 | showButtonPanel = this._get(inst, 'showButtonPanel'),
|
105 | 126 | hideIfNoPrevNext = this._get(inst, 'hideIfNoPrevNext'),
|
|
339 | 360 | */
|
340 | 361 | _setCurrentDate: function (element) {
|
341 | 362 | if (!element.val()) {
|
342 |
| - element[this._picker()]('setDate', getTimezoneDate()) |
343 |
| - .val(''); |
| 363 | + element[this._picker()]('setTimezoneDate').val(''); |
344 | 364 | }
|
345 | 365 | },
|
346 | 366 |
|
|
523 | 543 | var pickerObject = $(el);
|
524 | 544 |
|
525 | 545 | //Set date/time according to timezone offset
|
526 |
| - pickerObject.datepicker('setDate', getTimezoneDate()) |
| 546 | + pickerObject.datepicker('setTimezoneDate') |
527 | 547 | // To ensure that user can re-select date field without clicking outside it first.
|
528 | 548 | .blur();
|
529 | 549 | };
|
|
0 commit comments