Skip to content

Commit

Permalink
Solving magento#22964
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marcoaacoliveira committed Jan 5, 2020
1 parent 3e23510 commit bb16e33
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function date($date = null, $locale = null, $useTimezone = true, $include
new \DateTimeZone($timezone)
);

$date = $this->appendTimeIfNeeded($date, $includeTime);
$date = $this->appendTimeIfNeeded($date, $includeTime, $timezone, $locale);
$date = $formatter->parse($date) ?: (new \DateTime($date))->getTimestamp();
break;
}
Expand Down Expand Up @@ -347,16 +347,31 @@ public function convertConfigTimeToUtc($date, $format = 'Y-m-d H:i:s')
}

/**
* Retrieve date with time
*
* @param string $date
* @param bool $includeTime
* @param boolean $includeTime
* @param string $timezone
* @param string $locale
* @return string
*/
private function appendTimeIfNeeded($date, $includeTime)
private function appendTimeIfNeeded($date, $includeTime, $timezone, $locale)
{
if ($includeTime && !preg_match('/\d{1}:\d{2}/', $date)) {
$date .= " 0:00am";

$formatterWithoutHour = new \IntlDateFormatter(
$locale,
\IntlDateFormatter::SHORT,
\IntlDateFormatter::NONE,
new \DateTimeZone($timezone)
);
$convertedDate = $formatterWithoutHour->parse($date);
$formatterWithHour = new \IntlDateFormatter(
$locale,
\IntlDateFormatter::SHORT,
\IntlDateFormatter::SHORT,
new \DateTimeZone($timezone)
);

$date = $formatterWithHour->format($convertedDate);
}
return $date;
}
Expand Down

0 comments on commit bb16e33

Please sign in to comment.