Skip to content

Commit cc55346

Browse files
authored
Merge pull request #333 from os2display/feature/327-skewed-times-in-bookings
Add timezone support for booking date parsing in BrndFeedType
2 parents b0de9c4 + fedc264 commit cc55346

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
- [#333](https://github.com/os2display/display-api-service/pull/333)
8+
- Fix date parsing issue in BRND booking feed type
79
- [#313](https://github.com/os2display/display-api-service/pull/313)
810
- Add BRND booking feed type
911

src/Feed/BrndFeedType.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class BrndFeedType implements FeedTypeInterface
2424

2525
final public const string SUPPORTED_FEED_TYPE = FeedOutputModels::BRND_BOOKING_OUTPUT;
2626

27+
/**
28+
* BRND api datetime values are always given as 'Europe/Copenhagen'.
29+
*/
30+
private const string BRND_API_TIMEZONE = 'Europe/Copenhagen';
31+
2732
public function __construct(
2833
private readonly FeedService $feedService,
2934
private readonly ApiClient $apiClient,
@@ -94,6 +99,7 @@ public function getData(Feed $feed): array
9499

95100
private function parseBrndBooking(array $booking): array
96101
{
102+
$tz = new \DateTimeZone(self::BRND_API_TIMEZONE);
97103
// Parse start time
98104
$startDateTime = null;
99105
if (!empty($booking['dato']) && isset($booking['starttid']) && is_string($booking['starttid'])) {
@@ -102,7 +108,7 @@ private function parseBrndBooking(array $booking): array
102108
$startTimeString = preg_replace('/\.(\d{6})\d+$/', '.$1', $booking['starttid']);
103109
$dateOnly = substr($booking['dato'], 0, 10);
104110
$dateTimeString = $dateOnly.' '.$startTimeString;
105-
$startDateTime = \DateTimeImmutable::createFromFormat('m/d/Y H:i:s.u', $dateTimeString);
111+
$startDateTime = \DateTimeImmutable::createFromFormat('m/d/Y H:i:s.u', $dateTimeString, $tz);
106112
if (false === $startDateTime) {
107113
$startDateTime = null;
108114
}
@@ -118,7 +124,7 @@ private function parseBrndBooking(array $booking): array
118124
$endTimeString = preg_replace('/\.(\d{6})\d+$/', '.$1', $booking['sluttid']);
119125
$dateOnly = substr($booking['dato'], 0, 10);
120126
$dateTimeString = $dateOnly.' '.$endTimeString;
121-
$endDateTime = \DateTimeImmutable::createFromFormat('m/d/Y H:i:s.u', $dateTimeString);
127+
$endDateTime = \DateTimeImmutable::createFromFormat('m/d/Y H:i:s.u', $dateTimeString, $tz);
122128
if (false === $endDateTime) {
123129
$endDateTime = null;
124130
}

0 commit comments

Comments
 (0)