From bb92edbba5a927298eaef7b649cd3dce96e77a85 Mon Sep 17 00:00:00 2001 From: Felix Kopp <felix-source@phorax.com> Date: Sat, 8 Feb 2014 14:12:24 +0100 Subject: [PATCH] [!!!][TASK] Set f:format.date format to system default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 | 6 ++++++ .../ViewHelpers/Format/DateViewHelper.php | 6 +++++- .../ViewHelpers/Format/DateViewHelperTest.php | 21 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index a36b97df3332..4347027f8595 100644 --- 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 diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Format/DateViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Format/DateViewHelper.php index eb3438bc01c8..914106527762 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Format/DateViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Format/DateViewHelper.php @@ -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) { diff --git a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/DateViewHelperTest.php b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/DateViewHelperTest.php index 0ee31a27c7d0..f721f1fbe238 100644 --- a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/DateViewHelperTest.php +++ b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/DateViewHelperTest.php @@ -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() { @@ -79,6 +80,26 @@ class DateViewHelperTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase { $this->assertEquals('', $actualResult); } + /** + * @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 -- GitLab