Feature: #100187 - ICU-based date and time formatting¶
See forge#100187
Description¶
TYPO3 now supports rendering date and time based on formats/patterns defined by the International Components for Unicode standard (ICU).
TYPO3 previously only supported rendering of dates based on the PHP-native
functions date()
and strftime()
.
However, date()
can only format dates with english texts, such as
"December" as non-localized values, the C-based strftime()
function works
only with the locale defined in PHP and availability in the underlying operating
system.
In addition, ICU-based date and time formatting is much more flexible in
rendering, as it ships with default patterns for date and time (namely
FULL
, LONG
, MEDIUM
and SHORT
) which are based on the given locale.
This means, that when the locale en-US
is given, the short date is rendered
as mm/dd/yyyy
whereas de-AT
uses the dd.mm.yyyy
syntax automatically,
without having to define a custom pattern just by using the SHORT default
pattern.
In addition, the patterns can be adjusted more fine-grained, and can easily deal with TimeZones for output when DateTime objects are handed in.
TYPO3 also adds prepared custom patterns:
FULLDATE
(likeFULL
, but only the date information)FULLTIME
(likeFULL
, but only the time information)LONGDATE
(likeLONG
, but only the date information)LONGTIME
(likeLONG
, but only the time information)MEDIUMDATE
(likeMEDIUM
, but only the date information)MEDIUMTIME
(likeMEDIUM
, but only the time information)SHORTDATE
(likeSHORT
, but only the date information)SHORTTIME
(likeSHORT
, but only the time information)
See https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax for more information on the patterns.
Impact¶
A new stdWrap feature called formattedDate
is added, and the new formatting
can also be used in Fluid's <f:format.date>
ViewHelper.
The locale is typically fetched from the Site languages' locale (stdWrap or ViewHelper), or the backend users' language (in Backend context) for the ViewHelper usages.
Examples for stdWrap:
page.10 = TEXT
page.10.value = 1998-02-20 3:00:00
# see all available options https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax
page.10.formattedDate = FULL
# optional, if a different locale is wanted other than the Site Language's locale
page.10.formattedDate.locale = de-DE
will result in "Freitag, 20. Februar 1998 um 03:00:00 Koordinierte Weltzeit".
page.10 = TEXT
page.10.value = -5 days
page.10.formattedDate = FULL
page.10.formattedDate.locale = fr-FR
will result in "jeudi 9 mars 2023 à 21:40:49 temps universel coordonné".
Examples for Fluid <f:format.date>
ViewHelper:
<f:format.date pattern="dd. MMMM yyyy" locale="de-DE">{date}</f:format.date>
will result in "20. Februar 1998".
As soon as the pattern
attribute is used, the format
attribute
is disregarded.
Both new ViewHelper arguments are optional.