Skip to content

Add formatting of "st", "nd", "rd", and "th" suffixes for day numbers? #281

Open
@rask

Description

Would it be possible to introduce a new format argument for st, nd, and rd for each respective day number? At least the current documentation has notion of this being available.

  • June 1st
  • August 2nd
  • December 3rd
  • November 5th
  • July 22nd
  • ...

I know this is not implemented in strftime/strptime, is purely stylistic, a burden to localize, and is relatively simple to do with a few match arms on the implementors end.

But this would be really nice to have, especially when using things like templating languages that use chrono for date formatting (e.g. Tera+Gutenberg) but don't expose any chrono logic as is.

Here is an example of what I need to do in Tera/Gutenberg to achieve suffixes:

{% macro nicedate(date) %}
    {% set daynum = date | date(format="%d") %}

    {% if daynum == "1" or daynum == "21" or daynum == "31" %}
    {% set suffix = "st" %}
    {% elif daynum == "2" or daynum == "22" %}
    {% set suffix = "nd" %}
    {% elif daynum == "3" or daynum == "23" %}
    {% set suffix = "rd" %}
    {% else %}
    {% set suffix = "th" %}
    {% endif %}

    {{ daynum }}<sup>{{ suffix }}</sup> {{ date | date(format="%B, %Y at %H:%M") }}
{% endmacro nicedate %}

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions