[BUGFIX] Correctly treat relative date specification in date-VH 85/42885/3
authorMarkus Klein <markus.klein@typo3.org>
Wed, 26 Aug 2015 21:47:18 +0000 (23:47 +0200)
committerAndreas Fernandez <typo3@scripting-base.de>
Thu, 27 Aug 2015 06:25:39 +0000 (08:25 +0200)
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 <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Stephan GroƟberndt <stephan@grossberndt.de>
Reviewed-by: Josef Glatz <jousch@gmail.com>
Tested-by: Josef Glatz <jousch@gmail.com>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/fluid/Classes/ViewHelpers/Format/DateViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/DateViewHelperTest.php

index 8a35ee3..309e8ed 100644 (file)
@@ -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()));
index 74a6c4f..7fa95cb 100644 (file)
@@ -148,6 +148,15 @@ class DateViewHelperTest extends UnitTestCase {
        /**
         * @test
         */
+       public function relativeDateCalculationWorksWithoutBase() {
+               $this->subject->expects($this->never())->method('renderChildren');
+               $actualResult = $this->subject->render('now', 'Y');
+               $this->assertEquals(date('Y'), $actualResult);
+       }
+
+       /**
+        * @test
+        */
        public function baseArgumentIsConsideredForRelativeDate() {
                $this->subject->expects($this->never())->method('renderChildren');
                $actualResult = $this->subject->render('-1 year', 'Y', '2017-01-01');