From a366a9f08581f088adee684f20cd51888705d660 Mon Sep 17 00:00:00 2001 From: Jan Vernieuwe Date: Sat, 6 Jan 2024 21:37:26 +0100 Subject: [PATCH] Force timezone v2 (#50) * Use the correct timezone --- src/Entity/Anplan/Timeslot.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Entity/Anplan/Timeslot.php b/src/Entity/Anplan/Timeslot.php index 1f94ca2..80eeeee 100644 --- a/src/Entity/Anplan/Timeslot.php +++ b/src/Entity/Anplan/Timeslot.php @@ -119,14 +119,13 @@ public function getLocation(): Location private function forceTimezone(DateTimeInterface $date): string { - $timezone = new \DateTimeZone('Europe/Amsterdam'); - - return sprintf( - '%sT%s+0%d:00', - $date->format('Y-m-d'), - $date->format('H:i:s'), - $timezone->getOffset($date) / 3600 - ); + $local = new \DateTimeZone('Europe/Amsterdam'); + $timezonedDate = DateTime::createFromFormat('U', (string) $date->getTimestamp(), $local); + if ($timezonedDate === false) { + throw new \Exception('Could not create DateTime from timestamp'); + } + + return $timezonedDate->setTimezone($local)->format(DATE_ATOM); } public function setDateStartsAt(DateTime $dateStartsAt): Timeslot