{% macro format_date(date, short) %} {# Set locale #} {%- if lang != config.default_language %} {% set date_locale = trans(key="date_locale" | safe, lang=lang) %} {% else %} {% set date_locale = "en_GB" %} {% endif %} {% if config.extra.long_date_format and not short %} {{ date | date(format=config.extra.long_date_format, locale=date_locale) }} {% elif not config.extra.short_date_format and date_locale == "en_GB" %} {% set day = date | date(format='%-d') | int %} {% if day in [11, 12, 13] %} {% set suffix = "th" %} {% else %} {% set last_digit = day % 10 %} {% if last_digit == 1 %} {% set suffix = "st" %} {% elif last_digit == 2 %} {% set suffix = "nd" %} {% elif last_digit == 3 %} {% set suffix = "rd" %} {% else %} {% set suffix = "th" %} {% endif %} {% endif %} {# Return the date. #} {{ date | date(format="%-d") }}{{ suffix }} {% if short == true %} {{ date | date(format="%b %Y") }} {% else %} {{ date | date(format="%B %Y") }} {% endif %} {% elif short %} {{ date | date(format="%d %b %Y", locale=date_locale) }} {% endif %} {% endmacro %}