diff --git a/CHANGELOG.md b/CHANGELOG.md index 55202752..4d93d68d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +- [#333](https://github.com/os2display/display-api-service/pull/333) + - Fix date parsing issue in BRND booking feed type - [#313](https://github.com/os2display/display-api-service/pull/313) - Add BRND booking feed type diff --git a/src/Feed/BrndFeedType.php b/src/Feed/BrndFeedType.php index 66b0f96e..b0dfd1b7 100644 --- a/src/Feed/BrndFeedType.php +++ b/src/Feed/BrndFeedType.php @@ -24,6 +24,11 @@ class BrndFeedType implements FeedTypeInterface final public const string SUPPORTED_FEED_TYPE = FeedOutputModels::BRND_BOOKING_OUTPUT; + /** + * BRND api datetime values are always given as 'Europe/Copenhagen'. + */ + private const string BRND_API_TIMEZONE = 'Europe/Copenhagen'; + public function __construct( private readonly FeedService $feedService, private readonly ApiClient $apiClient, @@ -94,6 +99,7 @@ public function getData(Feed $feed): array private function parseBrndBooking(array $booking): array { + $tz = new \DateTimeZone(self::BRND_API_TIMEZONE); // Parse start time $startDateTime = null; if (!empty($booking['dato']) && isset($booking['starttid']) && is_string($booking['starttid'])) { @@ -102,7 +108,7 @@ private function parseBrndBooking(array $booking): array $startTimeString = preg_replace('/\.(\d{6})\d+$/', '.$1', $booking['starttid']); $dateOnly = substr($booking['dato'], 0, 10); $dateTimeString = $dateOnly.' '.$startTimeString; - $startDateTime = \DateTimeImmutable::createFromFormat('m/d/Y H:i:s.u', $dateTimeString); + $startDateTime = \DateTimeImmutable::createFromFormat('m/d/Y H:i:s.u', $dateTimeString, $tz); if (false === $startDateTime) { $startDateTime = null; } @@ -118,7 +124,7 @@ private function parseBrndBooking(array $booking): array $endTimeString = preg_replace('/\.(\d{6})\d+$/', '.$1', $booking['sluttid']); $dateOnly = substr($booking['dato'], 0, 10); $dateTimeString = $dateOnly.' '.$endTimeString; - $endDateTime = \DateTimeImmutable::createFromFormat('m/d/Y H:i:s.u', $dateTimeString); + $endDateTime = \DateTimeImmutable::createFromFormat('m/d/Y H:i:s.u', $dateTimeString, $tz); if (false === $endDateTime) { $endDateTime = null; }