Skip to content
Snippets Groups Projects
Commit df64e476 authored by Saif Bataineh's avatar Saif Bataineh Committed by Yahya Al Hamad
Browse files

Issue #3255666 by SyfJO: Wrong DateTime when a website is using timezone other than UTC

parent 41f4acda
Branches
Tags 8.x-1.2
No related merge requests found
......@@ -122,12 +122,12 @@ class HijriFieldFormatter extends FormatterBase {
$class = get_class($item);
switch ($class) {
case DateRangeItem::class:
$date[] = $this->hijriFormatManager->convertToHijri(strtotime($item->getValue()['value']), $format, $is_indian);
$date[] = $this->hijriFormatManager->convertToHijri(strtotime($item->getValue()['end_value']), $format, $is_indian);
$date[] = $this->hijriFormatManager->convertToHijri($this->getUTCTimestamp($item->getValue()['value']), $format, $is_indian);
$date[] = $this->hijriFormatManager->convertToHijri($this->getUTCTimestamp($item->getValue()['end_value']), $format, $is_indian);
break;
case DateTimeItem::class:
$value = strtotime($item->getValue()['value']);
$value = $this->getUTCTimestamp($item->getValue()['value']);
default:
$value = $value ?? $item->getValue()['value'];
$date[] = $this->hijriFormatManager->convertToHijri($value, $format, $is_indian);
......@@ -141,4 +141,18 @@ class HijriFieldFormatter extends FormatterBase {
return $elements;
}
/**
* Gets the timestamp using UTC timezone.
*
* @param string $date_time_string
* DateTime string (e.g. 1996-04-24T12:00:00).
* @return int
* Timestamp using UTC timezone.
*/
private function getUTCTimestamp(string $date_time_string) {
$timezone = new \DateTimeZone('UTC');
$date_time_string = str_replace("T", " ", $date_time_string);
return \DateTime::createFromFormat('Y-m-d H:i:s', $date_time_string, $timezone)->getTimestamp();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment