Bug 10547 - strftime Feature Request - day of month as 1st, 2nd, 3rd...
Summary: strftime Feature Request - day of month as 1st, 2nd, 3rd...
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Ulrich Drepper
Depends on:
Reported: 2009-08-22 05:24 UTC by clubsoda
Modified: 2017-04-21 08:33 UTC (History)
4 users (show)

See Also:
Last reconfirmed:
fweimer: security-


Note You need to log in before you can comment on or make changes to this bug.
Description clubsoda 2009-08-22 05:24:23 UTC
It would be great to have the option to display a date with its 
ordinal suffix, e.g. 22nd August, especially now that these 
display options carry through to the panel clock in GUIs such as 

I raised this possibility with the coreutils team but was advised that they are
reluctant to add format modifiers where no precedent exists in the C libraries.

Kind Regards,
Comment 1 Ulrich Drepper 2009-10-30 04:55:04 UTC
Not going to happen.  This doesn't work well (at all?) with
internationalization.  You could create your own locale with the alt_digits
appropriately defined and then %Od or so to print the day.  Not sure this works,
though, nobody tried that.
Comment 2 Rafal Luzynski 2017-04-13 23:40:18 UTC
I suggest reopening this bug instead of filing a similar one which I was going to do.

As suggested in this bug report: https://bugzilla.gnome.org/show_bug.cgi?id=768192 there is a broader need for another way to format the day of the month.  I hesitate to use the word "alternative" because someone might say that the alternative format specifiers already exist, for example "%Od" (this is for alternative digits, for example Roman or Eastern Arabic, also alternative digits are for all numeric outputs, not just days) or "%Ed" (unsupported, I'm not sure what would it mean).  The output would be:

- the ordinal day number as required in English (1st, 2nd, …) or Friulian (1ⁿ, 2, 3,…) or maybe in more languages,
- optionally preceded by a required preposition (Friulian: al 1ⁿ, ai 2, ai 3…),
- or anything else, as required by specific locales.

Other languages would output a regular decimal number, or would rather not use this new format specifier.

Browsing the stftime(3) man page I can see that the nearest unused format specifier is "%f".  So, for example:

- "%B %f" would output "April 14th" (or "April 1st") in English;
- "%f di %B" would output "ai 14 di Avrîl (or "al 1ⁿ di Avrîl) in Friulian.

A similar solution is here: https://github.com/samsonjs/strftime and it introduces "%o" but says explicitly that it outputs ordinal numbers (while here I say it can be ordinal or anything else, as required by a specific language) and it is implemented for English only.
Comment 3 fios 2017-04-21 08:33:56 UTC
This fix is also needed for my locale (Scottish Gaelic) and would follow the same pattern as English:

1 = 1d
2 = 2na
3 = 3s

Note that the CLDR does not support coding this either, so the CLDR data isn't 100% reliable here.