Skip to content

Commit 055ae0f

Browse files
author
olysenko
committed
Merge remote-tracking branch 'origin/MAGETWO-51588' into pr
2 parents 04795a6 + 6c5c664 commit 055ae0f

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,10 +15,6 @@ 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
2218
validationParams: {
2319
dateFormat: '${ $.outputDateFormat }'
2420
},
@@ -28,7 +24,7 @@ define([
2824
* server (ICU Date Format).
2925
*
3026
* Used only in date picker mode
31-
* (this.showsTime == false).
27+
* (this.options.showsTime == false).
3228
*
3329
* @type {String}
3430
*/
@@ -39,7 +35,7 @@ define([
3935
* server (ICU Date Format).
4036
*
4137
* Used only in date picker mode
42-
* (this.showsTime == false).
38+
* (this.options.showsTime == false).
4339
*
4440
* @type {String}
4541
*/
@@ -51,7 +47,10 @@ define([
5147
*
5248
* @type {String}
5349
*/
54-
datetimeFormat: '',
50+
pickerDateTimeFormat: '',
51+
52+
pickerDefaultDateFormat: 'MM/dd/y', // ICU Date Format
53+
pickerDefaultTimeFormat: 'h:mm a', // ICU Time Format
5554

5655
elementTmpl: 'ui/form/element/date',
5756

@@ -78,13 +77,15 @@ define([
7877
initConfig: function () {
7978
this._super();
8079

81-
utils.extend(this.options, {
82-
showsTime: this.showsTime,
83-
timeFormat: this.timeFormat,
84-
dateFormat: this.dateFormat
85-
});
80+
if (!this.options.dateFormat) {
81+
this.options.dateFormat = this.pickerDefaultDateFormat;
82+
}
83+
84+
if (!this.options.timeFormat) {
85+
this.options.timeFormat = this.pickerDefaultTimeFormat;
86+
}
8687

87-
this.prepareDatetimeFormats();
88+
this.prepareDateTimeFormats();
8889

8990
return this;
9091
},
@@ -107,15 +108,15 @@ define([
107108
shiftedValue;
108109

109110
if (value) {
110-
if (this.showsTime) {
111+
if (this.options.showsTime) {
111112
shiftedValue = moment.utc(value).add(this.timeOffset, 'seconds');
112113
} else {
113114
dateFormat = this.shiftedValue() ? this.outputDateFormat : this.inputDateFormat;
114115

115116
shiftedValue = moment(value, dateFormat);
116117
}
117118

118-
shiftedValue = shiftedValue.format(this.datetimeFormat);
119+
shiftedValue = shiftedValue.format(this.pickerDateTimeFormat);
119120
} else {
120121
shiftedValue = '';
121122
}
@@ -135,12 +136,11 @@ define([
135136
var value;
136137

137138
if (shiftedValue) {
138-
139-
if (this.showsTime) {
140-
value = moment.utc(shiftedValue, this.datetimeFormat);
139+
if (this.options.showsTime) {
140+
value = moment.utc(shiftedValue, this.pickerDateTimeFormat);
141141
value = value.subtract(this.timeOffset, 'seconds').toISOString();
142142
} else {
143-
value = moment(shiftedValue, this.datetimeFormat);
143+
value = moment(shiftedValue, this.pickerDateTimeFormat);
144144
value = value.format(this.outputDateFormat);
145145
}
146146
} else {
@@ -156,17 +156,22 @@ define([
156156
* Prepares and converts all date/time formats to be compatible
157157
* with moment.js library.
158158
*/
159-
prepareDatetimeFormats: function () {
160-
this.datetimeFormat = this.dateFormat;
159+
prepareDateTimeFormats: function () {
160+
this.pickerDateTimeFormat = this.options.dateFormat;
161161

162-
if (this.showsTime) {
163-
this.datetimeFormat += ' ' + this.timeFormat;
162+
if (this.options.showsTime) {
163+
this.pickerDateTimeFormat += ' ' + this.options.timeFormat;
164164
}
165165

166-
this.datetimeFormat = utils.normalizeDate(this.datetimeFormat);
166+
this.pickerDateTimeFormat = utils.normalizeDate(this.pickerDateTimeFormat);
167+
168+
if (this.dateFormat) {
169+
this.inputDateFormat = this.dateFormat;
170+
}
167171

168172
this.inputDateFormat = utils.normalizeDate(this.inputDateFormat);
169173
this.outputDateFormat = utils.normalizeDate(this.outputDateFormat);
174+
170175
this.validationParams.dateFormat = this.outputDateFormat;
171176
}
172177
});

0 commit comments

Comments
 (0)