Skip to content

Commit

Permalink
adjusted missing return for fix yiisoft#6263
Browse files Browse the repository at this point in the history
  • Loading branch information
cebe committed Nov 28, 2014
1 parent 9ae538e commit ae1bd39
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion framework/i18n/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ protected function normalizeDatetimeValue($value, $checkTimeInfo = false)
// checking for DateTime and DateTimeInterface is not redundant, DateTimeInterface is only in PHP>5.5
if ($value === null || $value instanceof DateTime || $value instanceof DateTimeInterface) {
// skip any processing
return $value;
return $checkTimeInfo ? [$value, true] : $value;
}
if (empty($value)) {
$value = 0;
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/framework/i18n/FormatterDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public function testAsDate()
$this->assertSame(date('n/j/y', $value), $this->formatter->asDate($value, 'short'));
$this->assertSame(date('F j, Y', $value), $this->formatter->asDate($value, 'long'));

$value = new DateTime();
$this->assertSame(date('M j, Y', $value->getTimestamp()), $this->formatter->asDate($value));
$this->assertSame(date('Y/m/d', $value->getTimestamp()), $this->formatter->asDate($value, 'php:Y/m/d'));
$this->assertSame(date('m/d/Y', $value->getTimestamp()), $this->formatter->asDate($value, 'MM/dd/yyyy'));
$this->assertSame(date('n/j/y', $value->getTimestamp()), $this->formatter->asDate($value, 'short'));
$this->assertSame(date('F j, Y', $value->getTimestamp()), $this->formatter->asDate($value, 'long'));

// empty input
$this->assertSame('Jan 1, 1970', $this->formatter->asDate(''));
$this->assertSame('Jan 1, 1970', $this->formatter->asDate(0));
Expand All @@ -89,6 +96,10 @@ public function testAsTime()
$this->assertSame(date('g:i:s A', $value), $this->formatter->asTime($value));
$this->assertSame(date('h:i:s A', $value), $this->formatter->asTime($value, 'php:h:i:s A'));

$value = new DateTime();
$this->assertSame(date('g:i:s A', $value->getTimestamp()), $this->formatter->asTime($value));
$this->assertSame(date('h:i:s A', $value->getTimestamp()), $this->formatter->asTime($value, 'php:h:i:s A'));

// empty input
$this->assertSame('12:00:00 AM', $this->formatter->asTime(''));
$this->assertSame('12:00:00 AM', $this->formatter->asTime(0));
Expand All @@ -114,6 +125,10 @@ public function testAsDatetime()
$this->assertSame(date('M j, Y g:i:s A', $value), $this->formatter->asDatetime($value));
$this->assertSame(date('Y/m/d h:i:s A', $value), $this->formatter->asDatetime($value, 'php:Y/m/d h:i:s A'));

$value = new DateTime();
$this->assertSame(date('M j, Y g:i:s A', $value->getTimestamp()), $this->formatter->asDatetime($value));
$this->assertSame(date('Y/m/d h:i:s A', $value->getTimestamp()), $this->formatter->asDatetime($value, 'php:Y/m/d h:i:s A'));

// empty input
$this->assertSame('Jan 1, 1970 12:00:00 AM', $this->formatter->asDatetime(''));
$this->assertSame('Jan 1, 1970 12:00:00 AM', $this->formatter->asDatetime(0));
Expand Down

0 comments on commit ae1bd39

Please sign in to comment.