Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions src/Feed/BrndFeedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -94,6 +99,7 @@ public function getData(Feed $feed): array

private function parseBrndBooking(array $booking): array
{
$tz = new \DateTimeZone(self::BRND_API_TIMEZONE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to manually add this constant to the top of the class, for the code to work:

/* BRND api datetime values are always given as 'Europe/Copenhagen' */
private const string BRND_API_TIMEZONE = 'Europe/Copenhagen';

// Parse start time
$startDateTime = null;
if (!empty($booking['dato']) && isset($booking['starttid']) && is_string($booking['starttid'])) {
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
Loading