Make WordPress Core

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's profile 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)

39991.patch (511 bytes) - added by devonto 8 years ago.
Patch

Download all attachments as: .zip

Change History (8)

#1 @swissspidy
8 years ago

  • Keywords needs-patch needs-unit-tests added

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.

@devonto
8 years ago

Patch

#2 @devonto
8 years ago

Patch file created, but unable to create a unit test at the moment.

#3 @swissspidy
8 years ago

Thanks @devonto!

It's worth noting that 'S' isn't really invalid. See #22225 for some history.

#4 @devonto
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:

http://api.jqueryui.com/datepicker/#utility-formatDate

#5 @swissspidy
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.

This ticket was mentioned in Slack in #core by webdevmattcrom. View the logs.


6 years ago

#7 @desrosj
6 years ago

  • Keywords needs-refresh added
Note: See TracTickets for help on using tickets.