File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -20,8 +20,6 @@ a ``DateTimeImmutable`` when the data is read from the database.
20
20
21
21
namespace My\Project\Types;
22
22
23
- use DateTimeImmutable;
24
- use DateTimeZone;
25
23
use Doctrine\ODM\MongoDB\Types\ClosureToPHP;
26
24
use Doctrine\ODM\MongoDB\Types\Type;
27
25
use MongoDB\BSON\UTCDateTime;
@@ -31,20 +29,25 @@ a ``DateTimeImmutable`` when the data is read from the database.
31
29
// This trait provides default closureToPHP used during data hydration
32
30
use ClosureToPHP;
33
31
34
- public function convertToPHPValue($value): DateTimeImmutable
32
+ public function convertToPHPValue($value): \ DateTimeImmutable
35
33
{
36
- $timeZone = new DateTimeZone($value['tz']);
34
+ $timeZone = new \ DateTimeZone($value['tz']);
37
35
$dateTime = $value['utc']
38
36
->toDateTime()
39
37
->setTimeZone($timeZone);
40
38
41
- return DateTimeImmutable::createFromMutable($dateTime);
39
+ return \ DateTimeImmutable::createFromMutable($dateTime);
42
40
}
43
41
44
42
public function convertToDatabaseValue($value): array
45
43
{
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.');
44
+ if (!$value instanceof \DateTimeImmutable) {
45
+ throw new \RuntimeException(
46
+ sprintf(
47
+ 'Expected instance of \DateTimeImmutable, got %s',
48
+ gettype($value)
49
+ )
50
+ );
48
51
}
49
52
50
53
return [
You can’t perform that action at this time.
0 commit comments