-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix month number ordinal suffix not working when formatting dates #39569
Conversation
{ monthNumber: 1, expected: 'st' }, | ||
{ monthNumber: 2, expected: 'nd' }, | ||
{ monthNumber: 3, expected: 'rd' }, | ||
{ monthNumber: 4, expected: 'th' }, | ||
{ monthNumber: 5, expected: 'th' }, | ||
{ monthNumber: 6, expected: 'th' }, | ||
{ monthNumber: 7, expected: 'th' }, | ||
{ monthNumber: 8, expected: 'th' }, | ||
{ monthNumber: 9, expected: 'th' }, | ||
{ monthNumber: 10, expected: 'th' }, | ||
{ monthNumber: 11, expected: 'th' }, | ||
{ monthNumber: 12, expected: 'th' }, | ||
{ monthNumber: 13, expected: 'th' }, | ||
{ monthNumber: 14, expected: 'th' }, | ||
{ monthNumber: 15, expected: 'th' }, | ||
{ monthNumber: 16, expected: 'th' }, | ||
{ monthNumber: 17, expected: 'th' }, | ||
{ monthNumber: 18, expected: 'th' }, | ||
{ monthNumber: 19, expected: 'th' }, | ||
{ monthNumber: 20, expected: 'th' }, | ||
{ monthNumber: 21, expected: 'st' }, | ||
{ monthNumber: 22, expected: 'nd' }, | ||
{ monthNumber: 23, expected: 'rd' }, | ||
{ monthNumber: 24, expected: 'th' }, | ||
{ monthNumber: 25, expected: 'th' }, | ||
{ monthNumber: 26, expected: 'th' }, | ||
{ monthNumber: 27, expected: 'th' }, | ||
{ monthNumber: 28, expected: 'th' }, | ||
{ monthNumber: 29, expected: 'th' }, | ||
{ monthNumber: 30, expected: 'th' }, | ||
{ monthNumber: 31, expected: 'st' }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I got these right 😅
Size Change: +70 B (0%) Total Size: 1.16 MB
ℹ️ View Unchanged
|
I think so, and that would make things more complicated. For example, if a similar date style is used in Georgian, it might have prefix instead of suffix. Probably this will get more complicated as more languages are involved. |
Is there a particular date format that WordPress supports for the prefixes? Or do you use It does mention in the docs that the
|
Sorry for the confusion. I meant a general localization of similar styles. e.g., P.S. I'm no l10n expert, just wanted to share few examples 😄 |
It's a little bit complicated 😀 The
https://www.php.net/manual/en/datetime.format.php WordPress uses https://developer.wordpress.org/reference/functions/wp_date/ But, strangely, Note that the formats themselves are also localised. That is, we call e.g. I changed my site's language to a few different langauges (German, French, Spanish, Russian) and noticed that none of them use So, in my verdict, we don't need |
I think that we should fix the root bug here which is that running There are two existing issues for this: #15221 @tellthemachines posted a really good explanation of why this bug happens in #15221 (comment). My preferred fix is this one proposed in https://core.trac.wordpress.org/ticket/51142:
We would need to make this change in Core. |
I'll close this in favour of the outlined fix in the comment above 👍 |
It was a little more involved than my above comment implied 😅 but opened a fix in #39670. |
What?
Fixes #39567
As explained on the issue, the Post Date block wasn't displaying the month number ordinal (the 'st' after 1, or 'nd' after 2 etc.) when a date format includes
jS
(https://wordpress.org/support/article/formatting-date-and-time/).I'm not sure why it was broken, the function seems to use moment-js (which ironically doesn't format
jS
), a deprecated library that's rather complicated.How?
This might be a naive fix, but I've written a very basic function that outputs the correct ordinal. This should in theory be a microscopic shuffle towards reducing the dependency on moment-js.
I don't know if the suffixes need to be localized or if this planet only has one kind of suffix.
Testing Instructions
jS
for the month numberScreenshots or screencast