diff --git a/src/DateTimeFormatter.php b/src/DateTimeFormatter.php index bc973ded..690ae2f3 100644 --- a/src/DateTimeFormatter.php +++ b/src/DateTimeFormatter.php @@ -71,7 +71,7 @@ public function filter($value) */ protected function normalizeDateTime($value) { - if (empty($value)) { + if ($value === '' || $value === null) { return $value; } elseif (is_int($value)) { $dateTime = new DateTime('@' . $value); diff --git a/test/DateTimeFormatterTest.php b/test/DateTimeFormatterTest.php index 58e237f2..0fc081e8 100644 --- a/test/DateTimeFormatterTest.php +++ b/test/DateTimeFormatterTest.php @@ -42,6 +42,22 @@ public function testFormatterDoesNotFormatAnEmptyString() $this->assertEquals('', $result); } + public function testFormatterDoesNotFormatNull() + { + $filter = new DateTimeFormatter(); + $result = $filter->filter(null); + $this->assertEquals(null, $result); + } + + public function testFormatterFormatsZero() + { + date_default_timezone_set('UTC'); + + $filter = new DateTimeFormatter(); + $result = $filter->filter(0); + $this->assertEquals('1970-01-01T00:00:00+0000', $result); + } + public function testDateTimeFormatted() { date_default_timezone_set('UTC');