Skip to content

Commit fb5f8d4

Browse files
committed
Support DateTimeImmutable as cell value
1 parent 6f76306 commit fb5f8d4

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/PhpSpreadsheet/Cell/DefaultValueBinder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace PhpOffice\PhpSpreadsheet\Cell;
44

5-
use DateTime;
5+
use DateTimeInterface;
66
use PhpOffice\PhpSpreadsheet\RichText\RichText;
77
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
88

@@ -16,14 +16,14 @@ class DefaultValueBinder implements IValueBinder
1616
*
1717
* @return bool
1818
*/
19-
public function bindValue(Cell $cell, $value = null)
19+
public function bindValue(Cell $cell, $value)
2020
{
2121
// sanitize UTF-8 strings
2222
if (is_string($value)) {
2323
$value = StringHelper::sanitizeUTF8($value);
2424
} elseif (is_object($value)) {
2525
// Handle any objects that might be injected
26-
if ($value instanceof DateTime) {
26+
if ($value instanceof DateTimeInterface) {
2727
$value = $value->format('Y-m-d H:i:s');
2828
} elseif (!($value instanceof RichText)) {
2929
$value = (string) $value;

src/PhpSpreadsheet/Cell/IValueBinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ interface IValueBinder
1212
*
1313
* @return bool
1414
*/
15-
public function bindValue(Cell $cell, $value = null);
15+
public function bindValue(Cell $cell, $value);
1616
}

tests/PhpSpreadsheetTests/Cell/DefaultValueBinderTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PhpOffice\PhpSpreadsheetTests\Cell;
44

55
use DateTime;
6+
use DateTimeImmutable;
67
use PhpOffice\PhpSpreadsheet\Cell\Cell;
78
use PhpOffice\PhpSpreadsheet\Cell\DataType;
89
use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder;
@@ -11,9 +12,9 @@
1112

1213
class DefaultValueBinderTest extends TestCase
1314
{
14-
protected $cellStub;
15+
private $cellStub;
1516

16-
protected function createCellStub()
17+
private function createCellStub()
1718
{
1819
// Create a stub for the Cell class.
1920
$this->cellStub = $this->getMockBuilder(Cell::class)
@@ -53,6 +54,7 @@ public function binderProvider()
5354
['-123.456'],
5455
['#REF!'],
5556
[new DateTime()],
57+
[new DateTimeImmutable()],
5658
];
5759
}
5860

0 commit comments

Comments
 (0)