@@ -35,6 +35,22 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
35
35
}
36
36
37
37
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
+
38
54
return $ value ->format ($ platform ->getDateFormatString ());
39
55
}
40
56
@@ -56,8 +72,28 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
56
72
*/
57
73
public function convertToPHPValue ($ value , AbstractPlatform $ platform )
58
74
{
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 ;
61
97
}
62
98
63
99
$ dateTime = DateTimeImmutable::createFromFormat ('! ' . $ platform ->getDateFormatString (), $ value );
0 commit comments