Yii version: 2.0.15.1
PHP version: 7.1
Operating system: Windows 10
The "English ordinal suffix" is not being output when specifying date format with the php: prefix.
Config as follows:
'formatter' => [
'class' => 'yii\i18n\Formatter',
'dateFormat' => 'php:D jS M Y',
],
<?php echo Yii::$app->formatter->asDate('2018-04-06'); ?>
Outputs: Fri 6 Apr 2018
Should output: Fri 6th Apr 2018
The application language is set to en-GB and I have the php-intl extension installed.
Looks like the ordinal suffix is not supported by the ICU so it gets removed.
http://userguide.icu-project.org/formatparse/datetime
'dateFormat' => 'php:D jS M Y',
this is manual for php format of date string http://php.net/manual/en/function.date.php
j | Day of the month without leading zeros | 1 to 31
S | English ordinal suffix for the day of the month, 2 characters | st, nd, rd or th. Works well with j
The php date format gets converted to an ICU format which removes unsupported format characters.
BaseFormatConverter
The php date format gets converted to an ICU format which removes unsupported format characters.
BaseFormatConverter
called in
https://github.com/yiisoft/yii2/blob/1d336963a553936380acfe1eeb64bb0b1c910457/framework/i18n/Formatter.php#L749-L751
so... ICU can't process something like 'S'?
Unfortunately not, to ICU an S is a fractional second.
How about throw exception about wrong configuration in this case?
or non use ICU?
Might be worth updating the docs with the formats that are not supported.
[
'S' => '', // English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j
'w' => '', // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday)
't' => '', // Number of days in the given month 28 through 31
'L' => '', // Whether it's a leap year, 1 if it is a leap year, 0 otherwise.
'B' => '', // Swatch Internet time 000 through 999
'u' => '', // Microseconds. Example: 654321
'I' => '', // Whether or not the date is in daylight saving time, 1 if Daylight Saving Time, 0 otherwise.
'Z' => '', // Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. -43200 through 50400
'U' => '', // Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
]
Why can't we have it so that when using the php: prefix, it uses the native php date() function to process?
Why can't we have it so that when using the php: prefix, it uses the native php date() function to process?
at least for the case
[
'S' => '', // English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j
'w' => '', // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday)
't' => '', // Number of days in the given month 28 through 31
'L' => '', // Whether it's a leap year, 1 if it is a leap year, 0 otherwise.
'B' => '', // Swatch Internet time 000 through 999
'u' => '', // Microseconds. Example: 654321
'I' => '', // Whether or not the date is in daylight saving time, 1 if Daylight Saving Time, 0 otherwise.
'Z' => '', // Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. -43200 through 50400
'U' => '', // Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
]
Why can't we have it so that when using the php: prefix, it uses the native php date() function to process?
because we want to support formatting dates for other locales as well, there is no such thing as the "English ordinal suffix" in other languages so I guess that's why its not part of intl.