From a4be761699e423c04d3fc8f649d007c9e674569e Mon Sep 17 00:00:00 2001 From: Markus Klein Date: Wed, 26 Aug 2015 23:47:18 +0200 Subject: [PATCH] [BUGFIX] Correctly treat relative date specification in date-VH MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If now base time is given, a relative date must be based on the current time. A wrong check is fixed to make this working again. Resolves: #69335 Related: #68022 Releases: master Change-Id: I9a4133cc570939533576ec8b2fbe8fffe1103825 Reviewed-on: http://review.typo3.org/42885 Reviewed-by: Daniel Goerz Tested-by: Daniel Goerz Reviewed-by: Stephan Großberndt Reviewed-by: Josef Glatz Tested-by: Josef Glatz Reviewed-by: Andreas Fernandez Tested-by: Andreas Fernandez --- .../fluid/Classes/ViewHelpers/Format/DateViewHelper.php | 2 +- .../Tests/Unit/ViewHelpers/Format/DateViewHelperTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Format/DateViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Format/DateViewHelper.php index 8a35ee31106e..309e8ed29658 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Format/DateViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Format/DateViewHelper.php @@ -134,7 +134,7 @@ class DateViewHelper extends AbstractViewHelper implements CompilableInterface { } if (!$date instanceof \DateTime) { try { - $base = $base instanceof \DateTime ? $base->format('U') : strtotime((MathUtility::canBeInterpretedAsInteger($date) ? '@' : '') . $base); + $base = $base instanceof \DateTime ? $base->format('U') : strtotime((MathUtility::canBeInterpretedAsInteger($base) ? '@' : '') . $base); $dateTimestamp = strtotime((MathUtility::canBeInterpretedAsInteger($date) ? '@' : '') . $date, $base); $date = new \DateTime('@' . $dateTimestamp); $date->setTimezone(new \DateTimeZone(date_default_timezone_get())); diff --git a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/DateViewHelperTest.php b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/DateViewHelperTest.php index 74a6c4f0cb7b..7fa95cbe203f 100644 --- a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/DateViewHelperTest.php +++ b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/DateViewHelperTest.php @@ -145,6 +145,15 @@ class DateViewHelperTest extends UnitTestCase { $this->assertEquals('1980-12-12', $actualResult); } + /** + * @test + */ + public function relativeDateCalculationWorksWithoutBase() { + $this->subject->expects($this->never())->method('renderChildren'); + $actualResult = $this->subject->render('now', 'Y'); + $this->assertEquals(date('Y'), $actualResult); + } + /** * @test */ -- 2.20.1