- Issue created by @kmani
- Status changed to Postponed: needs info
4 months ago 12:57pm 5 September 2024 - 🇮🇳India kmani
Step 1: create a datatime field in any content type
step 2: Render the datatime field in twig file.
step 3: Check the time tag<time datetime="2024-09-05T04:09:23Z">05/09/2024 12:09</time>
Both datatime and displayed time is different
Solution: In DateTimeFormatterBase.php field formatter, we need update the below code to fix this issue.
Current one in Core:
protected function buildDateWithIsoAttribute(DrupalDateTime $date) { // Create the ISO date in Universal Time. $iso_date = $date->format("Y-m-d\TH:i:s") . 'Z'; $this->setTimeZone($date); $build = [ '#theme' => 'time', '#text' => $this->formatDate($date), '#attributes' => [ 'datetime' => $iso_date, ], '#cache' => [ 'contexts' => [ 'timezone', ], ], ]; return $build; }
Solution: We need to move above $this->setTimeZone($date); to iso_date field conversion.
protected function buildDateWithIsoAttribute(DrupalDateTime $date) { // Create the ISO date in Universal Time. $this->setTimeZone($date); $iso_date = $date->format("Y-m-d\TH:i:s") . 'Z'; $build = [ '#theme' => 'time', '#text' => $this->formatDate($date), '#attributes' => [ 'datetime' => $iso_date, ], '#cache' => [ 'contexts' => [ 'timezone', ], ], ]; return $build; }
- Status changed to Active
4 months ago 6:59am 6 September 2024 - Status changed to Needs work
4 months ago 12:19pm 6 September 2024 Put the steps to reproduce in the issue summary. The current merge request fails a DateTime test.
- 🇮🇳India anchal_gupta
I am not able to reproduce this issue in my system.
DateTime field format its working fine.
As per reference I have attach screenshot.