Skip to content

Commit

Permalink
[BUGFIX] Date ViewHelper should use strftime() method
Browse files Browse the repository at this point in the history
When having a % in the format,
the strftime() method should be used
from the DateFormatter.

Resolves: #100350
Related: #95872
Releases: main
Change-Id: I376382c22e11cef4e826c3cefcf114abbf6034f6
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/78323
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Oliver Klee <typo3-coding@oliverklee.de>
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
bmack authored and sbuerk committed Mar 29, 2023
1 parent 47cfbaa commit 17fde56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Expand Up @@ -197,7 +197,7 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl
if (str_contains($format, '%')) {
// @todo: deprecate this syntax in TYPO3 v13.
$locale = $arguments['locale'] ?? self::resolveLocale($renderingContext);
return (new DateFormatter())->format($date, $format, $locale);
return (new DateFormatter())->strftime($format, $date, $locale);
}
return $date->format($format);
}
Expand Down
Expand Up @@ -64,6 +64,16 @@ public function viewHelperRespectsCustomFormat(): void
self::assertSame('01.02.1980', (new TemplateView($context))->render());
}

/**
* @test
*/
public function viewHelperAcceptsStrftimeFormat(): void
{
$context = $this->get(RenderingContextFactory::class)->create();
$context->getTemplatePaths()->setTemplateSource('<f:format.date format="%Y-%m-%d">1980-02-01</f:format.date>');
self::assertSame('1980-02-01', (new TemplateView($context))->render());
}

/**
* @test
*/
Expand Down

0 comments on commit 17fde56

Please sign in to comment.