Skip to content

Commit 9a0e197

Browse files
author
Bohdan Korablov
committed
MAGETWO-94196: [2.1] The fix of incorrect date format was lost since 2.1.13
1 parent 1ea334e commit 9a0e197

File tree

3 files changed

+69
-10
lines changed
  • app/code/Magento
    • Catalog/Ui/DataProvider/Product/Form/Modifier
    • Ui
      • Component/Form/Element/DataType
      • view/base/web/js/form/element

3 files changed

+69
-10
lines changed

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,22 +255,36 @@ protected function customizeNewDateRangeField(array $meta)
255255
$fromContainerPath = $this->arrayManager->slicePath($fromFieldPath, 0, -2);
256256
$toContainerPath = $this->arrayManager->slicePath($toFieldPath, 0, -2);
257257

258+
$commonFieldsMeta = [
259+
'outputDateTimeToISO' => false,
260+
'inputDateTimeFormat' => 'YYYY-MM-DD h:mm',
261+
'options' => [
262+
'showsTime' => true,
263+
]
264+
];
265+
258266
$meta = $this->arrayManager->merge(
259267
$fromFieldPath . self::META_CONFIG_PATH,
260268
$meta,
261-
[
262-
'label' => __('Set Product as New From'),
263-
'additionalClasses' => 'admin__field-date',
264-
]
269+
array_merge(
270+
[
271+
'label' => __('Set Product as New From'),
272+
'additionalClasses' => 'admin__field-date',
273+
],
274+
$commonFieldsMeta
275+
)
265276
);
266277
$meta = $this->arrayManager->merge(
267278
$toFieldPath . self::META_CONFIG_PATH,
268279
$meta,
269-
[
270-
'label' => __('To'),
271-
'scopeLabel' => null,
272-
'additionalClasses' => 'admin__field-date',
273-
]
280+
array_merge(
281+
[
282+
'label' => __('To'),
283+
'scopeLabel' => null,
284+
'additionalClasses' => 'admin__field-date',
285+
],
286+
$commonFieldsMeta
287+
)
274288
);
275289
$meta = $this->arrayManager->merge(
276290
$fromContainerPath . self::META_CONFIG_PATH,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public function prepare()
6565
$storeTimeZone = $this->localeDate->getConfigTimezone();
6666
$config['storeTimeZone'] = $storeTimeZone;
6767
}
68+
69+
if (!empty($config['options']['showsTime'])) {
70+
$config['options']['timeFormat'] = $this->localeDate->getTimeFormat();
71+
}
72+
6873
// Set date format pattern by current locale
6974
$localeDateFormat = $this->localeDate->getDateFormat();
7075
$config['options']['dateFormat'] = $localeDateFormat;

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ define([
3131
*/
3232
inputDateFormat: 'y-MM-dd',
3333

34+
/**
35+
* Format of date that comes from the
36+
* server (ICU Date Format).
37+
*
38+
* Used only in date/time picker mode
39+
* (this.options.showsTime == false).
40+
*
41+
* @type {String}
42+
*/
43+
inputDateTimeFormat: 'y-MM-dd h:mm',
44+
3445
/**
3546
* Format of date that should be sent to the
3647
* server (ICU Date Format).
@@ -42,6 +53,25 @@ define([
4253
*/
4354
outputDateFormat: 'MM/dd/y',
4455

56+
/**
57+
* Format of date that should be sent to the
58+
* server (ICU Date Format).
59+
*
60+
* Used only in datetime picker mode with disabled ISO format.
61+
* (this.options.showsTime == true, this.options.outputDateTimeToISO == false)
62+
*
63+
* @type {String}
64+
*/
65+
outputDateTimeFormat: '',
66+
67+
/**
68+
* Converts output date/time to ISO string
69+
*
70+
* Used only in datetime picker mode
71+
* (this.options.showsTime == false)
72+
*/
73+
outputDateTimeToISO: true,
74+
4575
/**
4676
* Date/time format that is used to display date in
4777
* the input field.
@@ -114,10 +144,20 @@ define([
114144
shiftedValue;
115145

116146
if (value) {
147+
if (this.options.showsTime && !this.outputDateTimeToISO) {
148+
dateFormat = this.shiftedValue() ?
149+
this.outputDateTimeFormat :
150+
this.inputDateTimeFormat;
151+
152+
value = moment(value, dateFormat).format(this.timezoneFormat);
153+
}
154+
117155
if (this.options.showsTime) {
118156
shiftedValue = moment.tz(value, 'UTC').tz(this.storeTimeZone);
119157
} else {
120-
dateFormat = this.shiftedValue() ? this.outputDateFormat : this.inputDateFormat;
158+
dateFormat = this.shiftedValue() ?
159+
this.outputDateTimeFormat :
160+
this.inputDateTimeFormat;
121161

122162
shiftedValue = moment(value, dateFormat);
123163
}

0 commit comments

Comments
 (0)