Make WordPress Core

Opened 7 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:


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(
			'd', 'j', 'l', 'z', // Day.
			'F', 'M', 'n', 'm', // Month.
			'Y', 'y',           // Year.
			'S'		    // Invalid
			'dd', 'd', 'DD', 'o',
			'MM', 'M', 'm', 'mm',
			'yy', 'y',
		get_option( 'date_format' )

Attachments (1)

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

Download all attachments as: .zip

Change History (8)

#1 @swissspidy
7 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

A unit test displaying the wrong behaviour would be great too, if possible.

7 years ago


#2 @devonto
7 years ago

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

#3 @swissspidy
7 years ago

Thanks @devonto!

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

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