File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ a ``DateTimeImmutable`` when the data is read from the database.
25
25
use Doctrine\ODM\MongoDB\Types\ClosureToPHP;
26
26
use Doctrine\ODM\MongoDB\Types\Type;
27
27
use MongoDB\BSON\UTCDateTime;
28
+ use RuntimeException;
28
29
29
30
class DateTimeWithTimezoneType extends Type
30
31
{
@@ -33,6 +34,10 @@ a ``DateTimeImmutable`` when the data is read from the database.
33
34
34
35
public function convertToPHPValue($value): DateTimeImmutable
35
36
{
37
+ if (!isset($value['utc'], $value['tz'])) {
38
+ throw new RuntimeException('Database value cannot be converted to date with timezone. Expected array with "utc" and "tz" keys.');
39
+ }
40
+
36
41
$timeZone = new DateTimeZone($value['tz']);
37
42
$dateTime = $value['utc']
38
43
->toDateTime()
@@ -43,8 +48,13 @@ a ``DateTimeImmutable`` when the data is read from the database.
43
48
44
49
public function convertToDatabaseValue($value): array
45
50
{
46
- if (! isset($value['utc'], $value['tz'])) {
47
- throw new RuntimeException('Database value cannot be converted to date with timezone. Expected array with "utc" and "tz" keys.');
51
+ if (!$value instanceof DateTimeImmutable) {
52
+ throw new \RuntimeException(
53
+ sprintf(
54
+ 'Expected instance of \DateTimeImmutable, got %s',
55
+ gettype($value)
56
+ )
57
+ );
48
58
}
49
59
50
60
return [
You can’t perform that action at this time.
0 commit comments