Opened 8 years ago
Last modified 6 years ago
#39991 new defect (bug)
jQuery UI Datepicker Localization Error with PHP date 'S'
Reported by: | devonto | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 4.6 |
Component: | Script Loader | Keywords: | has-patch needs-refresh |
Focuses: | Cc: |
Description
When localising the datepicker, the UK default WordPress date format is not converted correctly to jQuery UI's format.
The default PHP format for the UK is jS F Y
The script-loader.php function wp_localize_jquery_ui_datepicker()
converts this to dS MM YY
, however the S
is invalid and an ordinal suffix cannot be created with the datepicker.
There is no easy solution to add in the ordinal suffix, but a better solution than printing the stray S
is to strip this out by modifying the str_replace()
function call to do so.
// Convert the PHP date format into jQuery UI's format. $datepicker_date_format = str_replace( array( 'd', 'j', 'l', 'z', // Day. 'F', 'M', 'n', 'm', // Month. 'Y', 'y', // Year. 'S' // Invalid ), array( 'dd', 'd', 'DD', 'o', 'MM', 'M', 'm', 'mm', 'yy', 'y', '' ), get_option( 'date_format' ) );
Attachments (1)
Change History (8)
#3
@
8 years ago
Thanks @devonto!
It's worth noting that 'S' isn't really invalid. See #22225 for some history.
#4
@
8 years ago
Hi @swissspidy - for jQuery's datepicker, the S is invalid. This bug is only relating to formatting of dates using datepicker.
All available characters are shown here:
#5
@
8 years ago
- Focuses javascript removed
- Keywords has-patch added; needs-patch needs-unit-tests removed
- Milestone changed from Awaiting Review to Future Release
- Version changed from 4.7.2 to 4.6
OK, then let's go with "not allowed" in that specific case then.
Hey there,
Thanks for your report and the proposed fix! Would you mind creating a patch file for it? See https://make.wordpress.org/core/handbook/tutorials/working-with-patches/.
A unit test displaying the wrong behaviour would be great too, if possible.