Shopify / Shopify/liquid

Numeric ordinal contraction support

Open
#1,630 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

I would like to output 16th February 2022 when I write {{ order.created_at | date: "%e %B, %Y" }} instead of 16 February 2022 that it currently outputs.

The workaround is:

{% assign day = "now" | date: "%e"| modulo: 10 %}
{%- case day -%}
    {%- when 1 -%}
        {% assign suffix = 'st' %}
    {%- when 2 -%}
        {% assign suffix = 'nd' %}
    {%- when 3 -%}
        {% assign suffix = 'rd' %}
    {%- else -%}
        {% assign suffix = 'th' %}
{%- endcase -%}
{{ "now" | date: "%e[S] %B, %Y" | replace: '[S]',suffix }}

But it would be great to do it in the filter, is it possible to add?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the date filter used by {{ order.created_at | date: "%e %B, %Y" }} and how its format string is processed. Confirm the expected ordinal behavior, including the workaround's suffix cases, and consider the work complete when the filter can produce 16th February 2022 without template-side suffix logic.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.