Skip to content

Commit 20d9ee7

Browse files
author
Dmytro Voskoboinikov
committed
MAGETWO-51588: Date selection in grid filter shows wrong year
1 parent f4ae285 commit 20d9ee7

File tree

2 files changed

+29
-32
lines changed
  • app/code/Magento/Ui
    • Component/Form/Element/DataType
    • view/base/web/js/form/element

2 files changed

+29
-32
lines changed

app/code/Magento/Ui/Component/Form/Element/DataType/Date.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,6 @@ public function prepare()
7070
))->getOffset();
7171
}
7272

73-
if (!isset($config['timeFormat'])) {
74-
$config['timeFormat'] = $this->localeDate->getTimeFormat(\IntlDateFormatter::SHORT);
75-
}
76-
77-
if (!isset($config['dateFormat'])) {
78-
$config['dateFormat'] = $this->localeDate->getDateFormat(\IntlDateFormatter::MEDIUM);
79-
}
80-
8173
$this->setData('config', $config);
8274

8375
parent::prepare();

app/code/Magento/Ui/view/base/web/js/form/element/date.js

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,12 @@ define([
1515

1616
timeOffset: 0,
1717

18-
showsTime: false,
19-
20-
dateFormat: 'MM/dd/y', // ICU Date Format
21-
timeFormat: 'HH:mm', // ICU Time Format
22-
2318
/**
2419
* Format of date that comes from the
2520
* server (ICU Date Format).
2621
*
2722
* Used only in date picker mode
28-
* (this.showsTime == false).
23+
* (this.options.showsTime == false).
2924
*
3025
* @type {String}
3126
*/
@@ -36,7 +31,7 @@ define([
3631
* server (ICU Date Format).
3732
*
3833
* Used only in date picker mode
39-
* (this.showsTime == false).
34+
* (this.options.showsTime == false).
4035
*
4136
* @type {String}
4237
*/
@@ -48,7 +43,10 @@ define([
4843
*
4944
* @type {String}
5045
*/
51-
datetimeFormat: '',
46+
pickerDateTimeFormat: '',
47+
48+
pickerDefaultDateFormat: 'MM/dd/y', // ICU Date Format
49+
pickerDefaultTimeFormat: 'h:mm a', // ICU Time Format
5250

5351
elementTmpl: 'ui/form/element/date',
5452

@@ -75,13 +73,15 @@ define([
7573
initConfig: function () {
7674
this._super();
7775

78-
utils.extend(this.options, {
79-
showsTime: this.showsTime,
80-
timeFormat: this.timeFormat,
81-
dateFormat: this.dateFormat
82-
});
76+
if (!this.options.dateFormat) {
77+
this.options.dateFormat = this.pickerDefaultDateFormat;
78+
}
8379

84-
this.prepareDatetimeFormats();
80+
if (!this.options.timeFormat) {
81+
this.options.timeFormat = this.pickerDefaultTimeFormat;
82+
}
83+
84+
this.prepareDateTimeFormats();
8585

8686
return this;
8787
},
@@ -104,15 +104,15 @@ define([
104104
shiftedValue;
105105

106106
if (value) {
107-
if (this.showsTime) {
107+
if (this.options.showsTime) {
108108
shiftedValue = moment.utc(value).add(this.timeOffset, 'seconds');
109109
} else {
110110
dateFormat = this.shiftedValue() ? this.outputDateFormat : this.inputDateFormat;
111111

112112
shiftedValue = moment(value, dateFormat);
113113
}
114114

115-
shiftedValue = shiftedValue.format(this.datetimeFormat);
115+
shiftedValue = shiftedValue.format(this.pickerDateTimeFormat);
116116

117117
if (shiftedValue !== this.shiftedValue()) {
118118
this.shiftedValue(shiftedValue);
@@ -130,11 +130,11 @@ define([
130130
var value;
131131

132132
if (shiftedValue) {
133-
if (this.showsTime) {
134-
value = moment.utc(shiftedValue, this.datetimeFormat);
133+
if (this.options.showsTime) {
134+
value = moment.utc(shiftedValue, this.pickerDateTimeFormat);
135135
value = value.subtract(this.timeOffset, 'seconds').toISOString();
136136
} else {
137-
value = moment(shiftedValue, this.datetimeFormat);
137+
value = moment(shiftedValue, this.pickerDateTimeFormat);
138138
value = value.format(this.outputDateFormat);
139139
}
140140

@@ -148,16 +148,21 @@ define([
148148
* Prepares and converts all date/time formats to be compatible
149149
* with moment.js library.
150150
*/
151-
prepareDatetimeFormats: function () {
152-
this.datetimeFormat = this.dateFormat;
151+
prepareDateTimeFormats: function () {
152+
this.pickerDateTimeFormat = this.options.dateFormat;
153153

154-
if (this.showsTime) {
155-
this.datetimeFormat += ' ' + this.timeFormat;
154+
if (this.options.showsTime) {
155+
this.pickerDateTimeFormat += ' ' + this.options.timeFormat;
156156
}
157157

158-
this.datetimeFormat = utils.normalizeDate(this.datetimeFormat);
158+
this.pickerDateTimeFormat = utils.normalizeDate(this.pickerDateTimeFormat);
159+
160+
if (this.dateFormat) {
161+
this.inputDateFormat = this.dateFormat;
162+
}
159163

160164
this.inputDateFormat = utils.normalizeDate(this.inputDateFormat);
165+
161166
this.outputDateFormat = utils.normalizeDate(this.outputDateFormat);
162167
}
163168
});

0 commit comments

Comments
 (0)