Skip to content

Commit

Permalink
Merge pull request #380 from jonasdekeukelaere/514-time-type
Browse files Browse the repository at this point in the history
Reset date part for time type
  • Loading branch information
jonasdekeukelaere authored Apr 11, 2024
2 parents 613771f + 861647f commit 131355d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Common/Doctrine/Type/UTCTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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,
Expand Down

0 comments on commit 131355d

Please sign in to comment.