Skip to content

Commit

Permalink
Add DateTimeImmutable support
Browse files Browse the repository at this point in the history
  • Loading branch information
Einenlum committed Jul 11, 2016
1 parent ad6e513 commit c44c151
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Expand Up @@ -12,8 +12,6 @@ env:
- TWIG_VERSION=""

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
Expand Down
8 changes: 4 additions & 4 deletions DateTimeFormatter.php
Expand Up @@ -3,7 +3,7 @@
namespace Knp\Bundle\TimeBundle;

use Symfony\Component\Translation\TranslatorInterface;
use Datetime;
use DatetimeInterface;

class DateTimeFormatter
{
Expand All @@ -22,12 +22,12 @@ public function __construct(TranslatorInterface $translator)
/**
* Returns a formatted diff for the given from and to datetimes
*
* @param Datetime $from
* @param Datetime $to
* @param DateTimeInterface $from
* @param DateTimeInterface $to
*
* @return string
*/
public function formatDiff(Datetime $from, Datetime $to)
public function formatDiff(DateTimeInterface $from, DateTimeInterface $to)
{
static $units = array(
'y' => 'year',
Expand Down
5 changes: 3 additions & 2 deletions Templating/Helper/TimeHelper.php
Expand Up @@ -5,6 +5,7 @@
use Symfony\Component\Templating\Helper\Helper;
use Knp\Bundle\TimeBundle\DateTimeFormatter;
use DateTime;
use DateTimeInterface;

class TimeHelper extends Helper
{
Expand Down Expand Up @@ -37,11 +38,11 @@ public function diff($from, $to = null)
*
* @param mixed $datetime
*
* @return DateTime
* @return DateTimeInterface
*/
public function getDatetimeObject($datetime = null)
{
if ($datetime instanceof DateTime) {
if ($datetime instanceof DateTimeInterface) {
return $datetime;
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/DateTimeFormatterTest.php
Expand Up @@ -8,7 +8,7 @@ class DateTimeFormatterTest extends \PHPUnit_Framework_TestCase

public function setUp()
{
$translator = $this->getMock('Symfony\Component\Translation\Translator', array(), array(), '', false);
$translator = $this->createMock('Symfony\Component\Translation\Translator', array(), array(), '', false);
$translator->expects($this->any())
->method('trans')
->will($this->returnArgument(0));
Expand Down Expand Up @@ -38,7 +38,7 @@ public function testFormatDiff()
);

foreach ($tests as $test) {
$from = new \Datetime(date('Y-m-d H:i:s', strtotime($test[0])));
$from = new \DatetimeImmutable(date('Y-m-d H:i:s', strtotime($test[0])));
$to = new \Datetime(date('Y-m-d H:i:s', strtotime($test[1])));

$this->assertEquals($test[2], $this->formatter->formatDiff($from, $to));
Expand Down
2 changes: 1 addition & 1 deletion Tests/Templating/Helper/TimeHelperTest.php
Expand Up @@ -8,7 +8,7 @@ class TimeHelperTest extends \PHPUnit_Framework_TestCase

public function setUp()
{
$this->helper = new TimeHelper($this->getMock('Knp\Bundle\TimeBundle\DateTimeFormatter', array(), array(), '', false));
$this->helper = new TimeHelper($this->createMock('Knp\Bundle\TimeBundle\DateTimeFormatter', array(), array(), '', false));
}

public function testGetDatetimeObject()
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -18,7 +18,7 @@
],

"require": {
"php": ">=5.3.3",
"php": ">=5.5",
"symfony/dependency-injection": "~2.3|~3.0",
"symfony/templating": "~2.3|~3.0",
"symfony/translation": "~2.3|~3.0",
Expand Down

0 comments on commit c44c151

Please sign in to comment.