Loading src/Plugin/Field/FieldFormatter/HijriFieldFormatter.php +17 −3 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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(); } } Loading
src/Plugin/Field/FieldFormatter/HijriFieldFormatter.php +17 −3 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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(); } }