Skip to content

Commit bb16e33

Browse files
Solving #22964
It was needed to change the appendTimeIfNeeded, because isn't right to transform DateTime without hour into with hour just appending a string in the end of other string.
1 parent 3e23510 commit bb16e33

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function date($date = null, $locale = null, $useTimezone = true, $include
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,31 @@ public function convertConfigTimeToUtc($date, $format = 'Y-m-d H:i:s')
347347
}
348348

349349
/**
350-
* Retrieve date with time
351-
*
352350
* @param string $date
353-
* @param bool $includeTime
351+
* @param boolean $includeTime
352+
* @param string $timezone
353+
* @param string $locale
354354
* @return string
355355
*/
356-
private function appendTimeIfNeeded($date, $includeTime)
356+
private function appendTimeIfNeeded($date, $includeTime, $timezone, $locale)
357357
{
358358
if ($includeTime && !preg_match('/\d{1}:\d{2}/', $date)) {
359-
$date .= " 0:00am";
359+
360+
$formatterWithoutHour = new \IntlDateFormatter(
361+
$locale,
362+
\IntlDateFormatter::SHORT,
363+
\IntlDateFormatter::NONE,
364+
new \DateTimeZone($timezone)
365+
);
366+
$convertedDate = $formatterWithoutHour->parse($date);
367+
$formatterWithHour = new \IntlDateFormatter(
368+
$locale,
369+
\IntlDateFormatter::SHORT,
370+
\IntlDateFormatter::SHORT,
371+
new \DateTimeZone($timezone)
372+
);
373+
374+
$date = $formatterWithHour->format($convertedDate);
360375
}
361376
return $date;
362377
}

0 commit comments

Comments
 (0)