Page MenuHomePhabricator

Implement day as ordinal number (for #time)
Open, Needs TriagePublic


Feature request from

Unlike PHP's date function, MediaWiki does not support jS in format strings (used by e.g. #time in ParserFunctions) for the day as an ordinal number. There are likely more use cases for formatting numbers as ordinals (e.g. T95553), so localization of ordinal numbers should first become part of the core's internationalization.

Format string token discussion

In PHP, j corresponds to the day and S to the ordinal suffix in English. They are two distinct tokens. As different languages have different ways of formatting ordinal numbers, MediaWiki may have to treat it as one. There are currently no two-letter tokens (except MediaWiki's own tokens starting with x), so a different one may have to be introduced in MediaWiki (e.g. J).

Acceptance criteria:

  • {{#time: J F Y | 2000-01-20 }} outputs "20th January 2000"
  • {{#time: J F Y | 2000-01-20 | cs }} outputs "20. ledna 2000"

Event Timeline

I didn't realize it comes from PHP. If so, then jS is definitely better.

definitely better

Actually, PHP's date function treats jS as two tokens: j for the day and S for the suffix. Since we want to support localization and different languages format ordinals differently, it should perhaps be treated as one. In this case, a single-letter token or one starting with x would be better. I will update the task description.

matej_suchanek renamed this task from Implement day as ordinal number in #time to Implement day as ordinal number (for #time).Jul 26 2020, 9:06 AM
matej_suchanek updated the task description. (Show Details)

I'll try to implement S for English ordinals, for the time being, and make it overloadable.

Change 616321 had a related patch set uploaded (by Alex Mashin; owner: mashin):
[mediawiki/core@master] Enable S token in date format

Change 616325 had a related patch set uploaded (by Alex Mashin; owner: mashin):
[mediawiki/extensions/Wikibase@master] Enable S token in date format

T260699 demonstrates a use case for this in Sorani Kurdish.

Some work is being done in T59903.