[BUGFIX] BackendUtility::dateTimeAge must return correct values 65/47365/2
authorGeorg Ringer <georg.ringer@gmail.com>
Wed, 23 Mar 2016 05:08:56 +0000 (06:08 +0100)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Wed, 23 Mar 2016 08:20:38 +0000 (09:20 +0100)
If the 3rd parameter is set to 'date', the age must be returned as
date without any time information.

Resolves: #75235
Releases: master, 7.6
Change-Id: I7ebf76dc635f7dbca42c6486c585eb140832e6c4
Reviewed-on: https://review.typo3.org/47364
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
(cherry picked from commit 5c46ba68ad79034a5daf678b4a41a5882dcbaf60)
Reviewed-on: https://review.typo3.org/47365

typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php

index f3544ff..f099eb4 100755 (executable)
@@ -1624,7 +1624,7 @@ class BackendUtility
         }
         $label = static::getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears');
         $age = ' (' . self::calcAge($prefix * ($GLOBALS['EXEC_TIME'] - $tstamp), $label) . ')';
-        return $date === 'date' ? self::date($tstamp) : self::datetime($tstamp) . $age;
+        return ($date === 'date' ? self::date($tstamp) : self::datetime($tstamp)) . $age;
     }
 
     /**
index 3878420..8ca310b 100644 (file)
@@ -1060,4 +1060,18 @@ class BackendUtilityTest extends UnitTestCase
         );
         $this->assertEquals($expected, BackendUtility::getSpecConfParts($defaultExtras));
     }
+
+    /**
+     * @test
+     */
+    public function dateTimeAgeReturnsCorrectValues() {
+        /** @var ObjectProphecy|LanguageService $languageServiceProphecy */
+        $languageServiceProphecy = $this->prophesize(LanguageService::class);
+        $languageServiceProphecy->sL(Argument::cetera())->willReturn(' min| hrs| days| yrs| min| hour| day| year');
+        $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
+        $GLOBALS['EXEC_TIME'] = mktime(0, 0, 0, 3, 23, 2016);
+
+        $this->assertSame('24-03-16 00:00 (-1 day)', BackendUtility::dateTimeAge($GLOBALS['EXEC_TIME'] + 86400));
+        $this->assertSame('24-03-16 (-1 day)', BackendUtility::dateTimeAge($GLOBALS['EXEC_TIME'] + 86400, 1, 'date'));
+    }
 }