Skip to content

Commit

Permalink
Force timezone v2 (#50)
Browse files Browse the repository at this point in the history
* Use the correct timezone
  • Loading branch information
janvernieuwe authored Jan 6, 2024
1 parent 9ba61b1 commit a366a9f
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/Entity/Anplan/Timeslot.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a366a9f

Please sign in to comment.