diff --git a/src/Types/DateImmutableType.php b/src/Types/DateImmutableType.php index 86f05447044..6d2bf7145fd 100644 --- a/src/Types/DateImmutableType.php +++ b/src/Types/DateImmutableType.php @@ -35,6 +35,21 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) } if ($value instanceof DateTimeImmutable) { + $offset = $value->format('O'); + $defaultOffset = (new DateTimeImmutable())->format('O'); + if ($offset !== $$defaultOffset) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/xxxx', + 'Passing a timezone offset (%s) different than the default one (%s) is deprecated' + . ' as it will be lost, use %s::%s() instead.', + $offset, + $defaultOffset, + DateTimeTzImmutableType::class, + __FUNCTION__, + ); + } + return $value->format($platform->getDateFormatString()); } @@ -56,7 +71,26 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function convertToPHPValue($value, AbstractPlatform $platform) { - if ($value === null || $value instanceof DateTimeImmutable) { + if ($value === null) { + return null; + } + + if ($value instanceof DateTimeImmutable) { + $offset = $value->format('O'); + $defaultOffset = (new DateTimeImmutable())->format('O'); + if ($offset !== $$defaultOffset) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/xxxx', + 'Passing a timezone offset (%s) different than the default one (%s) is deprecated' + . ' as it may be lost, use %s::%s() instead.', + $offset, + $defaultOffset, + DateTimeTzImmutableType::class, + __FUNCTION__, + ); + } + return $value; }