-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #846 from boekkooi/datetime-immutable
Support \DateTimeImmutable and fixes timezone not being set correctly
- Loading branch information
Showing
2 changed files
with
71 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
namespace APY\DataGridBundle\Tests\Grid\Column; | ||
|
||
use APY\DataGridBundle\Grid\Column\DateTimeColumn; | ||
|
||
class DateTimeColumnTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @dataProvider provideDisplayInput | ||
*/ | ||
public function testCorrectDisplayOut($value, $expectedOutput, $timeZone = null) | ||
{ | ||
$column = new DateTimeColumn(); | ||
$column->setFormat('Y-m-d H:i:s'); | ||
|
||
if ($timeZone !== null) { | ||
$column->setTimezone($timeZone); | ||
} | ||
|
||
$this->assertEquals( | ||
$expectedOutput, | ||
$column->getDisplayedValue($value) | ||
); | ||
} | ||
|
||
public function testDisplayValueForDateTimeImmutable() | ||
{ | ||
if (PHP_VERSION_ID < 50500) { | ||
$this->markTestSkipped('\\DateTimeImmutable was introduced in PHP 5.5'); | ||
} | ||
|
||
$now = new \DateTimeImmutable(); | ||
|
||
$column = new DateTimeColumn(); | ||
$column->setFormat('Y-m-d H:i:s'); | ||
$this->assertEquals( | ||
$now->format('Y-m-d H:i:s'), | ||
$column->getDisplayedValue($now) | ||
); | ||
} | ||
|
||
public function testDateTimeZoneForDisplayValueIsTheSameAsTheColumn() | ||
{ | ||
$column = new DateTimeColumn(); | ||
$column->setFormat('Y-m-d H:i:s'); | ||
$column->setTimezone('UTC'); | ||
|
||
$now = new \DateTime('2000-01-01 01:00:00', new \DateTimeZone('Europe/Amsterdam')); | ||
|
||
$this->assertEquals( | ||
'2000-01-01 00:00:00', | ||
$column->getDisplayedValue($now) | ||
); | ||
} | ||
|
||
public function provideDisplayInput() | ||
{ | ||
$now = new \DateTime(); | ||
|
||
return array( | ||
array($now, $now->format('Y-m-d H:i:s')), | ||
array('2016/01/01 12:13:14', '2016-01-01 12:13:14'), | ||
array(1, '1970-01-01 00:00:01', 'UTC') | ||
); | ||
} | ||
} |