Skip to content

Commit 9a0b5a8

Browse files
ENGCOM-6552: Fix #22964 #26270
- Merge Pull Request #26270 from marcoaacoliveira/magento2:2.4-develop - Merged commits: 1. bb16e33 2. d12ac21 3. 32be472 4. 6a19b12 5. 6e80158 6. 8ee89af 7. c85410d
2 parents 01ab2cd + c85410d commit 9a0b5a8

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

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

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,12 @@ public function date($date = null, $locale = null, $useTimezone = true, $include
177177
$timeType = $includeTime ? \IntlDateFormatter::SHORT : \IntlDateFormatter::NONE;
178178
$formatter = new \IntlDateFormatter(
179179
$locale,
180-
\IntlDateFormatter::SHORT,
180+
\IntlDateFormatter::MEDIUM,
181181
$timeType,
182182
new \DateTimeZone($timezone)
183183
);
184184

185-
$date = $this->appendTimeIfNeeded($date, $includeTime);
185+
$date = $this->appendTimeIfNeeded($date, $includeTime, $timezone, $locale);
186186
$date = $formatter->parse($date) ?: (new \DateTime($date))->getTimestamp();
187187
break;
188188
}
@@ -347,16 +347,44 @@ public function convertConfigTimeToUtc($date, $format = 'Y-m-d H:i:s')
347347
}
348348

349349
/**
350-
* Retrieve date with time
350+
* Append time to DateTime
351351
*
352352
* @param string $date
353-
* @param bool $includeTime
353+
* @param boolean $includeTime
354+
* @param string $timezone
355+
* @param string $locale
354356
* @return string
357+
* @throws LocalizedException
355358
*/
356-
private function appendTimeIfNeeded($date, $includeTime)
359+
private function appendTimeIfNeeded($date, $includeTime, $timezone, $locale)
357360
{
358361
if ($includeTime && !preg_match('/\d{1}:\d{2}/', $date)) {
359-
$date .= " 0:00am";
362+
363+
$formatterWithoutHour = new \IntlDateFormatter(
364+
$locale,
365+
\IntlDateFormatter::MEDIUM,
366+
\IntlDateFormatter::NONE,
367+
new \DateTimeZone($timezone)
368+
);
369+
$convertedDate = $formatterWithoutHour->parse($date);
370+
371+
if (!$convertedDate) {
372+
throw new LocalizedException(
373+
new Phrase(
374+
'Could not append time to DateTime'
375+
)
376+
);
377+
378+
}
379+
380+
$formatterWithHour = new \IntlDateFormatter(
381+
$locale,
382+
\IntlDateFormatter::MEDIUM,
383+
\IntlDateFormatter::SHORT,
384+
new \DateTimeZone($timezone)
385+
);
386+
387+
$date = $formatterWithHour->format($convertedDate);
360388
}
361389
return $date;
362390
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ public function dateIncludeTimeDataProvider(): array
128128
true, // include time
129129
1495170060 // expected timestamp
130130
],
131+
'Parse greek d/m/y date without time' => [
132+
'30/10/2021', // datetime
133+
'el_GR', // locale
134+
false, // include time
135+
1635570000 // expected timestamp
136+
],
137+
'Parse greek d/m/y date with time' => [
138+
'30/10/2021, 12:01 π.μ.', // datetime
139+
'el_GR', // locale
140+
true, // include time
141+
1635570060 // expected timestamp
142+
],
131143
];
132144
}
133145

0 commit comments

Comments
 (0)