Skip to content

Commit a4f80a9

Browse files
committed
Force pattern if locale not found
1 parent 6bda779 commit a4f80a9

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,18 @@ public function convertConfigTimeToUtc($date, $format = 'Y-m-d H:i:s')
324324
* @return string
325325
* @deprecated
326326
*/
327-
public function convertConfigTimeToUtcWithPattern($date, $format = 'Y-m-d H:i:s', $pattern = 'Y-M-dd HH:mm:ss')
327+
public function convertConfigTimeToUtcWithPattern($date, $format = 'Y-m-d H:i:s', $pattern = null)
328328
{
329329
if (!($date instanceof \DateTimeInterface)) {
330330
if ($date instanceof \DateTimeImmutable) {
331331
$date = new \DateTime($date->format('Y-m-d H:i:s'), new \DateTimeZone($this->getConfigTimezone()));
332332
} else {
333+
$locale = $this->_localeResolver->getLocale();
334+
if ($locale === null) {
335+
$pattern = 'Y-M-dd HH:mm:ss';
336+
}
333337
$formatter = new \IntlDateFormatter(
334-
$this->_localeResolver->getLocale(),
338+
$locale,
335339
\IntlDateFormatter::MEDIUM,
336340
\IntlDateFormatter::MEDIUM,
337341
$this->getConfigTimezone(),

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,15 @@ public function dateIncludeTimeDataProvider()
124124
* @param string $expectedResult
125125
* @dataProvider getConvertConfigTimeToUtcFixtures
126126
*/
127-
public function testConvertConfigTimeToUtc($date, $configuredTimezone, $expectedResult)
127+
public function testConvertConfigTimeToUtc($date, $configuredTimezone, $configuredLocale, $expectedResult)
128128
{
129+
$this->localeResolver
130+
->method('getLocale')
131+
->willReturn($configuredLocale);
132+
129133
$this->scopeConfigWillReturnConfiguredTimezone($configuredTimezone);
130134

131-
$this->assertEquals($expectedResult, $this->getTimezone()->convertConfigTimeToUtc($date));
135+
$this->assertEquals($expectedResult, $this->getTimezone()->convertConfigTimeToUtcWithPattern($date));
132136
}
133137

134138
/**
@@ -141,16 +145,37 @@ public function getConvertConfigTimeToUtcFixtures()
141145
'string' => [
142146
'2016-10-10 10:00:00',
143147
'UTC',
148+
null,
144149
'2016-10-10 10:00:00'
145150
],
151+
'string-en_US' => [
152+
'Sep 29, 2018, 6:07:38 PM',
153+
'UTC',
154+
'en_US',
155+
'2018-09-29 18:07:38'
156+
],
157+
'string-pt_BR' => [
158+
'29 de set de 2018 18:07:38',
159+
'UTC',
160+
'pt_BR',
161+
'2018-09-29 18:07:38'
162+
],
163+
'string-tr_TR' => [
164+
'29 Eyl 2018 18:07:38',
165+
'UTC',
166+
'tr_TR',
167+
'2018-09-29 18:07:38'
168+
],
146169
'datetime' => [
147170
new \DateTime('2016-10-10 10:00:00', new \DateTimeZone('UTC')),
148171
'UTC',
172+
null,
149173
'2016-10-10 10:00:00'
150174
],
151175
'datetimeimmutable' => [
152176
new \DateTimeImmutable('2016-10-10 10:00:00', new \DateTimeZone('UTC')),
153177
'UTC',
178+
null,
154179
'2016-10-10 10:00:00'
155180
]
156181
];

0 commit comments

Comments
 (0)