Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Allow DateTimeFormatter to format zero.
Browse files Browse the repository at this point in the history
This addresses the note raised in issue #4393 after merge that zero is a
valid UNIX timestamp.
  • Loading branch information
akrabat committed May 3, 2013
1 parent dd12afa commit 19817ef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/Zend/Filter/DateTimeFormatter.php
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions tests/ZendTest/Filter/DateTimeFormatterTest.php
Expand Up @@ -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');
Expand Down

0 comments on commit 19817ef

Please sign in to comment.