[!!!][TASK] Set f:format.date format to system default 56/27456/7
authorFelix Kopp <felix-source@phorax.com>
Sat, 8 Feb 2014 13:12:24 +0000 (14:12 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 8 Feb 2014 21:02:23 +0000 (22:02 +0100)
TYPO3 configuration knows a global date format configuration
within the installation tool. See TYPO3_CONF_VARS/SYS/ddmmyy.

Use this global format as the default for all fluid based date
format outputs if not overwritten in place.

Change-Id: I508d7f61f63760aa1301f52663c432feeb539bf4
Resolves: #55790
Releases: 6.2
Reviewed-on: https://review.typo3.org/27456
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Marcin Sągol
Tested-by: Marcin Sągol
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
NEWS.md
typo3/sysext/fluid/Classes/ViewHelpers/Format/DateViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/DateViewHelperTest.php

diff --git a/NEWS.md b/NEWS.md
index a36b97d..4347027 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -194,6 +194,12 @@ Example:
   and not
     <img src="fileadmin/xxxx.jpg" alt="Alt-Attribute" title="Alt-Attribute" />
 
+* Date view helper uses configured default format
+
+The fluid date view helper now uses $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']
+as fallback format instead of hardcoded Y-m-d if no explicit format is given as
+argument. This may change the output of dates from Y-m-d to d-m-y.
+
 ### System categories
 
 * Activated by default
index eb3438b..9141065 100644 (file)
@@ -90,7 +90,11 @@ class DateViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
         * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
         * @api
         */
-       public function render($date = NULL, $format = 'Y-m-d') {
+       public function render($date = NULL, $format = '') {
+               if ($format === '') {
+                       $format = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] ?: 'Y-m-d';
+               }
+
                if ($date === NULL) {
                        $date = $this->renderChildren();
                        if ($date === NULL) {
index 0ee31a2..f721f1f 100644 (file)
@@ -33,6 +33,7 @@ class DateViewHelperTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                        'LC_TIME' => setlocale(LC_TIME, 0),
                );
                $this->timezone = @date_default_timezone_get();
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] = 'Y-m-d';
        }
 
        public function tearDown() {
@@ -81,6 +82,26 @@ class DateViewHelperTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
         * @test
+        */
+       public function viewHelperUsesDefaultIfNoSystemFormatIsAvailable() {
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] = '';
+               $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\Format\DateViewHelper();
+               $actualResult = $viewHelper->render('@1391876733');
+               $this->assertEquals('2014-02-08', $actualResult);
+       }
+
+       /**
+        * @test
+        */
+       public function viewHelperUsesSystemFormat() {
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] = 'l, j. M y';
+               $viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\Format\DateViewHelper();
+               $actualResult = $viewHelper->render('@1391876733');
+               $this->assertEquals('Saturday, 8. Feb 14', $actualResult);
+       }
+
+       /**
+        * @test
         * @expectedException \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
         */
        public function viewHelperThrowsExceptionIfDateStringCantBeParsed() {