Skip to content

Commit e9f2cb6

Browse files
authored
Fix converting DateTimeInterface to BSON in php 7.4 (#281)
Co-authored-by: al.tarasov <al.tarasov@corp.mail.ru>
1 parent ed0176f commit e9f2cb6

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/Alcaeus/MongoDbAdapter/TypeConverter.php

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public static function fromLegacy($value)
4343
return $value->toBSONType();
4444
case $value instanceof BSON\Type:
4545
return $value;
46+
case $value instanceof \DateTimeInterface:
47+
return self::fromLegacy((array) $value);
4648
case is_array($value):
4749
case is_object($value):
4850
$result = [];

tests/Alcaeus/MongoDbAdapter/TypeConverterTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ public static function converterData()
3737
'nestedArrays' => [
3838
[['foo' => 'bar']], [new BSONDocument(['foo' => 'bar'])]
3939
],
40+
'dateTime' => [
41+
\DateTime::createFromFormat('Y-m-d\TH:i:sP', '2021-06-30T12:34:56-7'),
42+
new BSONDocument([
43+
'date' => '2021-06-30 12:34:56.000000',
44+
'timezone_type' => 1,
45+
'timezone' => '-07:00',
46+
]),
47+
],
4048
];
4149
}
4250

0 commit comments

Comments
 (0)