Skip to content

Commit ce67530

Browse files
committed
MC-37369: Datepicker issue with arabic locale on orders grid
1 parent af7b84a commit ce67530

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateDatetimeProductAttributeTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
2828
</after>
2929
<!-- Generate the datetime default value -->
30-
<generateDate date="now" format="n/j/Y g:i A" stepKey="generateDefaultValue"/>
30+
<generateDate date="now" format="n/j/y g:i A" stepKey="generateDefaultValue"/>
3131
<!-- Create new datetime product attribute -->
3232
<actionGroup ref="AdminOpenProductAttributePageActionGroup" stepKey="goToProductAttributes"/>
3333
<actionGroup ref="CreateProductAttributeWithDatetimeFieldActionGroup" stepKey="createAttribute">

lib/internal/Magento/Framework/Stdlib/DateTime/Intl/DateFormatterFactory.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,29 @@ class DateFormatterFactory
3232
* @param int $dateStyle
3333
* @param int $timeStyle
3434
* @param string|null $timeZone
35+
* @param bool $useFourDigitsForYear
3536
* @return \IntlDateFormatter
3637
*/
3738
public function create(
3839
string $locale,
3940
int $dateStyle,
4041
int $timeStyle,
41-
?string $timeZone = null
42+
?string $timeZone = null,
43+
bool $useFourDigitsForYear = true
4244
): \IntlDateFormatter {
4345
$formatter = new \IntlDateFormatter(
4446
$locale,
4547
$dateStyle,
4648
$timeStyle,
47-
$timeZone ? new \DateTimeZone($timeZone): null
49+
$timeZone
4850
);
4951
/**
5052
* Process custom date formats
5153
*/
5254
$customDateFormat = $this->getCustomDateFormat($locale, $dateStyle, $timeStyle);
5355
if ($customDateFormat !== null) {
5456
$formatter->setPattern($customDateFormat);
55-
} elseif ($dateStyle === \IntlDateFormatter::SHORT) {
57+
} elseif ($dateStyle === \IntlDateFormatter::SHORT && $useFourDigitsForYear) {
5658
/**
5759
* Gives 4 places for year value in short style
5860
*/

lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ public function getDateFormat($type = \IntlDateFormatter::SHORT)
129129
$formatter = $this->dateFormatterFactory->create(
130130
(string)$this->_localeResolver->getLocale(),
131131
(int)$type,
132-
\IntlDateFormatter::NONE
132+
\IntlDateFormatter::NONE,
133+
null,
134+
false
133135
);
134136

135137
return $formatter->getPattern();
@@ -140,7 +142,13 @@ public function getDateFormat($type = \IntlDateFormatter::SHORT)
140142
*/
141143
public function getDateFormatWithLongYear()
142144
{
143-
return $this->getDateFormat();
145+
$formatter = $this->dateFormatterFactory->create(
146+
(string)$this->_localeResolver->getLocale(),
147+
\IntlDateFormatter::SHORT,
148+
\IntlDateFormatter::NONE
149+
);
150+
151+
return $formatter->getPattern();
144152
}
145153

146154
/**

lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/TimezoneTest.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,23 @@ public function dateIncludeTimeDataProvider(): array
180180
null
181181
],
182182
'Parse date in short style with long year 1999' => [
183-
'9/11/1999',
183+
'8/11/1999',
184184
'en_US',
185185
false,
186-
'1999-09-11'
186+
'1999-08-11'
187187
],
188188
'Parse date in short style with long year 2099' => [
189189
'9/2/2099',
190190
'en_US',
191191
false,
192192
'2099-09-02'
193193
],
194+
'Parse date in short style with short year 1999' => [
195+
'8/11/99',
196+
'en_US',
197+
false,
198+
'1999-08-11'
199+
],
194200
];
195201
}
196202

@@ -207,14 +213,40 @@ public function testGetDatetimeFormat(string $locale, int $style, string $expect
207213
$this->assertEquals($expectedFormat, $this->getTimezone()->getDateTimeFormat($style));
208214
}
209215

216+
/**
217+
* @return array
218+
*/
210219
public function getDatetimeFormatDataProvider(): array
211220
{
212221
return [
213-
['en_US', \IntlDateFormatter::SHORT, 'M/d/y h:mm a'],
222+
['en_US', \IntlDateFormatter::SHORT, 'M/d/yy h:mm a'],
214223
['ar_SA', \IntlDateFormatter::SHORT, 'd/MM/y h:mm a']
215224
];
216225
}
217226

227+
/**
228+
* @param string $locale
229+
* @param int $style
230+
* @param string $expectedFormat
231+
* @dataProvider getDateFormatWithLongYearDataProvider
232+
*/
233+
public function testGetDateFormatWithLongYear(string $locale, string $expectedFormat): void
234+
{
235+
/** @var Timezone $timezone */
236+
$this->localeResolver->method('getLocale')->willReturn($locale);
237+
$this->assertEquals($expectedFormat, $this->getTimezone()->getDateFormatWithLongYear());
238+
}
239+
240+
/**
241+
* @return array
242+
*/
243+
public function getDateFormatWithLongYearDataProvider(): array
244+
{
245+
return [
246+
['en_US', 'M/d/y'],
247+
];
248+
}
249+
218250
/**
219251
* @param string $date
220252
* @param string $configuredTimezone

0 commit comments

Comments
 (0)