From 861647f4279ae1bec881c9e2b6b3d7868dd020a8 Mon Sep 17 00:00:00 2001 From: Jonas De Keukelaere Date: Thu, 11 Apr 2024 10:38:10 +0100 Subject: [PATCH] Reset date part for time type --- src/Common/Doctrine/Type/UTCTimeType.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Common/Doctrine/Type/UTCTimeType.php b/src/Common/Doctrine/Type/UTCTimeType.php index fa1e0af22d..aec269a9a7 100644 --- a/src/Common/Doctrine/Type/UTCTimeType.php +++ b/src/Common/Doctrine/Type/UTCTimeType.php @@ -24,6 +24,10 @@ class UTCTimeType extends TimeType */ public function convertToDatabaseValue($time, AbstractPlatform $platform): ?string { + // Reset date part of the time object to 01/01/1970 to keep the timezone consistent + // between writing and reading the entity from the database + $time->setDate(1970, 1, 1); + if ($time instanceof DateTime) { $time->setTimezone(self::getUtc()); } @@ -47,6 +51,10 @@ public function convertToPHPValue($timeString, AbstractPlatform $platform): ?Dat $time = DateTime::createFromFormat($platform->getTimeFormatString(), $timeString, self::getUtc()); + // Reset date part of the time object to 01/01/1970 to keep the timezone consistent + // between writing and reading the entity from the database + $time->setDate(1970, 1, 1); + if (!$time) { throw ConversionException::conversionFailedFormat( $timeString,