diff --git a/NEWS.md b/NEWS.md index a36b97df33328b527ee84a51f29c1ef9262ff9d9..4347027f859569484cd87e64ab49386c0457a83d 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 eb3438bc01c8bb193127b01a55bb81a7e7c7819f..914106527762f489d26e678d21773728818be286 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 0ee31a27c7d06fa13cf16ad3df2fc88babc3cfdd..f721f1fbe23801e0eb2c8c8c5b9c668723ffcdb4 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