|
23 | 23 |
|
24 | 24 | var calendarBasePrototype;
|
25 | 25 |
|
| 26 | + /** |
| 27 | + * Get date/time according to store settings |
| 28 | + * @returns {Date} |
| 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 | + } |
| 40 | + |
| 41 | + return new Date(ms); |
| 42 | + } |
| 43 | + |
26 | 44 | $.datepicker.markerClassName = '_has-datepicker';
|
27 | 45 |
|
28 | 46 | /**
|
|
72 | 90 | * Wrapper for overwrite jQuery UI datepicker function.
|
73 | 91 | */
|
74 | 92 | _overwriteGenerateHtml: function () {
|
75 |
| - var self = this; |
76 |
| - |
77 | 93 | /**
|
78 | 94 | * Overwrite jQuery UI datepicker function.
|
79 | 95 | * Reason: magento date could be set before calendar show
|
|
83 | 99 | * @return {String} html template
|
84 | 100 | */
|
85 | 101 | $.datepicker.constructor.prototype._generateHTML = function (inst) {
|
86 |
| - var today = self.getTimezoneDate(), |
| 102 | + var today = getTimezoneDate(), |
87 | 103 | isRTL = this._get(inst, 'isRTL'),
|
88 | 104 | showButtonPanel = this._get(inst, 'showButtonPanel'),
|
89 | 105 | hideIfNoPrevNext = this._get(inst, 'hideIfNoPrevNext'),
|
|
316 | 332 | };
|
317 | 333 | },
|
318 | 334 |
|
319 |
| - /** |
320 |
| - * If server timezone is defined then take to account server timezone shift |
321 |
| - * @return {Object} date |
322 |
| - */ |
323 |
| - getTimezoneDate: function () { |
324 |
| - |
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; |
332 |
| - } |
333 |
| - |
334 |
| - return new Date(ms); |
335 |
| - }, |
336 |
| - |
337 | 335 | /**
|
338 | 336 | * Set current date if the date is not set
|
339 | 337 | * @protected
|
340 | 338 | * @param {Object} element
|
341 | 339 | */
|
342 | 340 | _setCurrentDate: function (element) {
|
343 | 341 | if (!element.val()) {
|
344 |
| - element[this._picker()]('setDate', this.getTimezoneDate()) |
| 342 | + element[this._picker()]('setDate', getTimezoneDate()) |
345 | 343 | .val('');
|
346 | 344 | }
|
347 | 345 | },
|
|
356 | 354 | pickerButtonText = picker.next('.ui-datepicker-trigger')
|
357 | 355 | .find('img')
|
358 | 356 | .attr('title');
|
| 357 | + |
359 | 358 | picker.next('.ui-datepicker-trigger')
|
360 | 359 | .addClass('v-middle')
|
361 | 360 | .text('') // Remove jQuery UI datepicker generated image
|
|
523 | 522 | $.datepicker._gotoToday = function (el) {
|
524 | 523 | var pickerObject = $(el);
|
525 | 524 |
|
526 |
| - // Set date/time according to timezone offset |
527 |
| - pickerObject.datepicker( "setDate", pickerObject.calendar("getTimezoneDate") ) |
| 525 | + //Set date/time according to timezone offset |
| 526 | + pickerObject.datepicker('setDate', getTimezoneDate()) |
528 | 527 | // To ensure that user can re-select date field without clicking outside it first.
|
529 | 528 | .blur();
|
530 | 529 | };
|
|
0 commit comments