fix: emit export pickup times as clock readings without an offset

This commit is contained in:
fromme committed 2026-09-30 14:52:04 +02:00
1 parent 6c700ea18b
commit ede8fd840a
6 files changed
+136 -27

No files matched your search

+5 -2
View File
@@ -79,6 +79,9 @@ trait TypeConversionTrait
* This method is used primarily to parse pickup-times since data is
* either provided with date and time or time only. In this case a
* date has to be provided which defaults to a travel's start date.
*
* Both shapes are read in the default date's zone, so a caller that needs plain clock
* readings can pass a UTC date and no daylight saving gap shifts the time.
*/
protected function stringToDateTimeFuzzy(?string $string, \DateTimeImmutable $defaultDate): ?\DateTimeImmutable
{
@@ -89,12 +92,12 @@ trait TypeConversionTrait
try {
if (1 === preg_match('/^\d{2}:\d{2}$/', $string)) {
// time only provided
$dateTime = Carbon::createFromFormat('H:i', $string);
$dateTime = Carbon::createFromFormat('H:i', $string, $defaultDate->getTimezone());
// assign default date
$dateTime->setDateFrom($defaultDate);
} else {
// date and time provided
$dateTime = Carbon::createFromFormat('d.m.Y H:i', substr($string, 0, 16));
$dateTime = Carbon::createFromFormat('d.m.Y H:i', substr($string, 0, 16), $defaultDate->getTimezone());
}
return $dateTime->toDateTimeImmutable();
+7 -2
View File
@@ -193,6 +193,10 @@ class ProductExportBuilder
* getPickups() resolves both zeit shapes and rolls a bare time past midnight onto the
* next day. Entries with id 0 are kept: the consumer drops them itself.
*
* `datetime` is BusPro's clock reading, without an offset. Resolving in Europe/Berlin
* would move a bare 02:45 on the spring-forward night to 03:45, so the dates are
* resolved in UTC, where no time is skipped or repeated.
*
* @param array<int|string, Pickup> $masterData
* @param array<int, true> $pickupsWithoutMasterData
*
@@ -201,8 +205,9 @@ class ProductExportBuilder
private function buildPickups(Crawler $dateNode, \DateTimeImmutable $dateFrom, array $masterData, array &$pickupsWithoutMasterData): array
{
$resolved = [];
$clockDate = new \DateTimeImmutable($dateFrom->format('Y-m-d'), new \DateTimeZone('UTC'));
foreach ($this->travelParser->getPickups($this->productExportParser->children($dateNode, 'zustiege/zustieg'), $dateFrom, true) as $pickup) {
foreach ($this->travelParser->getPickups($this->productExportParser->children($dateNode, 'zustiege/zustieg'), $clockDate, true) as $pickup) {
$pickupId = (int) $pickup->id;
$details = $masterData[$pickupId] ?? null;
@@ -216,7 +221,7 @@ class ProductExportBuilder
'city' => $details?->city,
'street' => $details?->street,
'price' => $pickup->price,
'datetime' => $pickup->time?->format('c'),
'datetime' => $pickup->time?->format('Y-m-d\TH:i:s'),
];
}
+11 -3
View File
@@ -144,8 +144,15 @@ class TravelExportBuilder
// getPickups() is what buys stringToDateTimeFuzzy() for both zeit shapes and
// adjustOvernightTimes(), which rolls an 02:15 listed after a 23:59 onto the next
// calendar day. Resolved once per travel date, then shared by its hotel rows.
//
// Resolved in UTC: the times are BusPro's clock readings, and in Europe/Berlin a
// bare 02:45 on the spring-forward night would move to 03:45.
$pickups = $this->buildPickups(
$this->travelParser->getPickups($node->filterXPath('.//zustiege/zustieg'), $dateFrom, true),
$this->travelParser->getPickups(
$node->filterXPath('.//zustiege/zustieg'),
new \DateTimeImmutable($dateFrom->format('Y-m-d'), new \DateTimeZone('UTC')),
true,
),
$pickupMasterData,
$pickupsWithoutMasterData,
);
@@ -234,8 +241,9 @@ class TravelExportBuilder
'street' => $details?->street,
'time' => $pickup->time?->format('H:i'),
// Emitted for time-only sources too: adjustOvernightTimes() has already
// worked out the real day, and a null here would throw that away.
'datetime' => $pickup->time?->format('c'),
// worked out the real day, and a null here would throw that away. A clock
// reading without an offset, like `time`.
'datetime' => $pickup->time?->format('Y-m-d\TH:i:s'),
];
}