Skip to content

Commit 7253bb5

Browse files
committed
Merge remote-tracking branch 'mainline-ce/develop' into new-PAT
2 parents 0878967 + 8d4d0c0 commit 7253bb5

File tree

5 files changed

+667
-11
lines changed
  • app/code/Magento/Ui
  • dev/tests
    • js/jasmine/tests/app/code/Magento/Ui/base/js/form/element
    • static/testsuite/Magento/Test/Js/_files/blacklist

5 files changed

+667
-11
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@ public function __construct(
6060
public function prepare()
6161
{
6262
$config = $this->getData('config');
63+
6364
if (!isset($config['storeTimeZone'])) {
6465
$storeTimeZone = $this->localeDate->getConfigTimezone();
6566
$config['storeTimeZone'] = $storeTimeZone;
6667
}
6768
// Set date format pattern by current locale
6869
$localeDateFormat = $this->localeDate->getDateFormat();
6970
$config['options']['dateFormat'] = $localeDateFormat;
70-
$config['outputDateFormat'] = $localeDateFormat;
71+
$config['options']['storeLocale'] = $this->locale;
7172
$this->setData('config', $config);
7273
parent::prepare();
7374
}

app/code/Magento/Ui/Test/Unit/Component/Form/Element/DataType/DateTest.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ public function testPrepareWithTimeOffset()
7070
$this->assertArrayHasKey('options', $config);
7171
$this->assertArrayHasKey('dateFormat', $config['options']);
7272
$this->assertEquals($localeDateFormat, $config['options']['dateFormat']);
73-
74-
$this->assertArrayHasKey('outputDateFormat', $config);
75-
$this->assertEquals($localeDateFormat, $config['outputDateFormat']);
7673
}
7774

7875
public function testPrepareWithoutTimeOffset()
@@ -112,15 +109,14 @@ public function testPrepareWithoutTimeOffset()
112109
$this->assertArrayHasKey('dateFormat', $config['options']);
113110
$this->assertEquals($localeDateFormat, $config['options']['dateFormat']);
114111

115-
$this->assertArrayHasKey('outputDateFormat', $config);
116-
$this->assertEquals($localeDateFormat, $config['outputDateFormat']);
117112
}
118113

119114
/**
120115
* This tests ensures that userTimeZone is properly saved in the configuration
121116
*/
122117
public function testPrepare()
123118
{
119+
$this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn('de-DE');
124120
$this->date = $this->objectManagerHelper->getObject(
125121
Date::class,
126122
[
@@ -133,5 +129,6 @@ public function testPrepare()
133129
$this->date->prepare();
134130
$configArray = $this->date->getData('config');
135131
$this->assertEquals('America/Chicago', $configArray['storeTimeZone']);
132+
$this->assertEquals('de-DE', $configArray['options']['storeLocale']);
136133
}
137134
}

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

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright © 2015 Magento. All rights reserved.
2+
* Copyright © 2016 Magento. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
55
define([
@@ -53,6 +53,12 @@ define([
5353
pickerDefaultDateFormat: 'MM/dd/y', // ICU Date Format
5454
pickerDefaultTimeFormat: 'h:mm a', // ICU Time Format
5555

56+
/**
57+
* Moment compatible format used for moment conversion
58+
* of date from datePicker
59+
*/
60+
momentFormat: 'MM/DD/YYYY',
61+
5662
elementTmpl: 'ui/form/element/date',
5763

5864
listens: {
@@ -142,7 +148,7 @@ define([
142148
formattedValue = moment(shiftedValue).format('YYYY-MM-DD HH:mm');
143149
value = moment.tz(formattedValue, this.storeTimeZone).tz('UTC').toISOString();
144150
} else {
145-
value = moment(shiftedValue, this.pickerDateTimeFormat);
151+
value = moment(shiftedValue, this.momentFormat);
146152
value = value.format(this.outputDateFormat);
147153
}
148154
} else {
@@ -160,6 +166,8 @@ define([
160166
*/
161167
prepareDateTimeFormats: function () {
162168
this.pickerDateTimeFormat = this.options.dateFormat;
169+
this.momentFormat = this.options.dateFormat ?
170+
this.convertToMomentFormat(this.options.dateFormat) : this.momentFormat;
163171

164172
if (this.options.showsTime) {
165173
this.pickerDateTimeFormat += ' ' + this.options.timeFormat;
@@ -175,6 +183,22 @@ define([
175183
this.outputDateFormat = utils.normalizeDate(this.outputDateFormat);
176184

177185
this.validationParams.dateFormat = this.outputDateFormat;
186+
},
187+
188+
/**
189+
* Converts PHP IntlFormatter format to moment format.
190+
*
191+
* @param {String} format - PHP format
192+
* @returns {String} - moment compatible formatting
193+
*/
194+
convertToMomentFormat: function (format) {
195+
var newFormat;
196+
197+
newFormat = format.replace(/yy|y/gi, 'YYYY'); // replace the year
198+
newFormat = newFormat.replace(/dd|d/g, 'DD'); // replace the date
199+
newFormat = newFormat.replace(/mm|m/gi, 'MM'); //replace the month
200+
201+
return newFormat;
178202
}
179203
});
180204
});

0 commit comments

Comments
 (0)