add support for DateTimeImmutable

Adds support for DateTimeImmutable by using the shared DateTimeInterface
which both this and DateTime implement.
This commit is contained in:
Rhodri Pugh committed 2021-05-24 19:48:16 +01:00
1 parent 7923bfef7a
commit 3f67dbe66f
2 files changed
+2 -1

No files matched your search

+1 -1
View File
@@ -61,7 +61,7 @@ class CellTypeHelper
public static function isDateTimeOrDateInterval($value) public static function isDateTimeOrDateInterval($value)
{ {
return ( return (
$value instanceof \DateTime || $value instanceof \DateTimeInterface ||
$value instanceof \DateInterval $value instanceof \DateInterval
); );
} }
@@ -90,6 +90,7 @@ class CellTypeHelperTest extends TestCase
public function testIsDateOrInterval() public function testIsDateOrInterval()
{ {
$this->assertTrue(CellTypeHelper::isDateTimeOrDateInterval(new \DateTime())); $this->assertTrue(CellTypeHelper::isDateTimeOrDateInterval(new \DateTime()));
$this->assertTrue(CellTypeHelper::isDateTimeOrDateInterval(new \DateTimeImmutable()));
$this->assertTrue(CellTypeHelper::isDateTimeOrDateInterval(new \DateInterval('P1D'))); $this->assertTrue(CellTypeHelper::isDateTimeOrDateInterval(new \DateInterval('P1D')));
$this->assertFalse(CellTypeHelper::isDateTimeOrDateInterval(true)); $this->assertFalse(CellTypeHelper::isDateTimeOrDateInterval(true));