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
Ordinal suffix token does not work in wp.date.format
#15221
Comments
This is odd, the tests in 054c5d3 pass, but the bug is reproducible in the console. |
Hi @iandunn, @tellthemachines and I were looking into this issue. It's a tough one to solve! It seems as though the locale dictates what's output by the format function. In the test environment the locale defaults to In the browser it's whatever the user selects in their admin settings. The odd part is that even when we tested setting the locale in the browser to something like 'English (UK) (which should include the ordinal according to the settings), the ordinal still wasn't present after running the format function. The locale is initially set by the script loader here: Which is handled by the date package here: gutenberg/packages/date/src/index.js Lines 36 to 83 in 7e3b2ab
The moment library has some hard to follow docs that don't shed much light. @youknowriad - I had a look at the git blame, it seems as though this code was originally copied from the core codebase by you, is that correct? It'd be great to find someone who has an understanding of how this is supposed to work. |
That is correct, the idea is to try to map the WordPress PHP l10n config with the format expected by moment. |
Not sure how to fix this. What we found so far: Running Hypothesis: moment doesn't recognise the locale string or is unable to translate it to default Questions:
I'm running around in circles, so decided to stop work on this ticket for now :( |
Another |
OK peeps I finally understood what's going on here. The problem is that the What we can do to fix this:
I'm happy to help fix this issue but would be good to have some opinions on what's the priority here, because loading in a bunch of moment locales could affect performance quite a bit. |
How complex would that be? Can this definition be "generated" somehow from the php configs like we do for the strings...? |
We would need to have a different regex for each language that supports ordinal suffixes, like moment has. When we define our custom locales in |
A random though: I think the @wordpress/date format function is designed to match php behavior, if we don't have the orginal suffixes support in php, why are we trying to support them in JS as well? I mean it would be good but I wouldn't consider that a bug unless it's supported in php too? |
That's the thing, we do have suffix support in PHP. If you go to WP admin General Settings > Date Format, choose Custom and add the string |
|
Soooo if the idea is having parity of support between PHP and JS, perhaps we can go with the quick-fix-it-just-for-English option? 😁 |
console.log( format( 'l, F jS', Date.now() ) );
Expected:
Friday, April 26th
Actual:
Friday, April 26
The text was updated successfully, but these errors were encountered: