Skip to content

Commit 694728b

Browse files
committed
Deprecate passing timezone information to methods where it is ignored
1 parent b30518d commit 694728b

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/Types/DateImmutableType.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
3535
}
3636

3737
if ($value instanceof DateTimeImmutable) {
38+
$offset = $value->format('O');
39+
$defaultOffset = (new DateTimeImmutable())->format('O');
40+
41+
if ($offset !== $defaultOffset) {
42+
Deprecation::triggerIfCalledFromOutside(
43+
'doctrine/dbal',
44+
'https://github.com/doctrine/dbal/pull/xxxx',
45+
'Passing a timezone offset (%s) different than the default one (%s) is deprecated'
46+
. ' as it will be lost, use %s::%s() instead.',
47+
$offset,
48+
$defaultOffset,
49+
DateTimeTzImmutableType::class,
50+
__FUNCTION__,
51+
);
52+
}
53+
3854
return $value->format($platform->getDateFormatString());
3955
}
4056

@@ -56,8 +72,28 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
5672
*/
5773
public function convertToPHPValue($value, AbstractPlatform $platform)
5874
{
59-
if ($value === null || $value instanceof DateTimeImmutable) {
60-
return $value;
75+
if ($value === null) {
76+
return null;
77+
}
78+
79+
if ($value instanceof DateTimeImmutable) {
80+
$offset = $value->format('O');
81+
$defaultOffset = (new DateTimeImmutable())->format('O');
82+
83+
if ($offset !== $defaultOffset) {
84+
Deprecation::triggerIfCalledFromOutside(
85+
'doctrine/dbal',
86+
'https://github.com/doctrine/dbal/pull/xxxx',
87+
'Passing a timezone offset (%s) different than the default one (%s) is deprecated'
88+
. ' as it may be lost, use %s::%s() instead.',
89+
$offset,
90+
$defaultOffset,
91+
DateTimeTzImmutableType::class,
92+
__FUNCTION__,
93+
);
94+
}
95+
96+
return null;
6197
}
6298

6399
$dateTime = DateTimeImmutable::createFromFormat('!' . $platform->getDateFormatString(), $value);

0 commit comments

Comments
 (0)