feat: travel data API endpoint for travelinfo pages in TYPO3

This commit is contained in:
Björn Fromme
2025-05-15 11:54:37 +02:00
parent 1e5401ea25
commit 6bf22045c4
6 changed files with 120 additions and 9 deletions
+29 -1
View File
@@ -66,7 +66,35 @@ trait TypeConversionTrait
}
try {
$dateTime = Carbon::createFromFormat('d.m.Y H:i', substr($string, 0, 16))->startOfDay();
$dateTime = Carbon::createFromFormat('d.m.Y H:i', substr($string, 0, 16));
return $dateTime->toDateTimeImmutable();
} catch (InvalidFormatException $e) {
return null;
}
}
/**
* 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.
*/
protected function stringToDateTimeFuzzy(?string $string, \DateTimeImmutable $defaultDate): ?\DateTimeImmutable
{
if (true === empty($string)) {
return null;
}
try {
if (1 === preg_match('/^\d{2}:\d{2}$/', $string)) {
// time only provided
$dateTime = Carbon::createFromFormat('H:i', $string);
// assign default date
$dateTime->setDateFrom($defaultDate);
} else {
// date and time provided
$dateTime = Carbon::createFromFormat('d.m.Y H:i', substr($string, 0, 16));
}
return $dateTime->toDateTimeImmutable();
} catch (InvalidFormatException $e) {