diff options
| author | Alejandro Soto <alejandro@34project.org> | 2025-09-13 14:55:15 -0600 |
|---|---|---|
| committer | Alejandro Soto <alejandro@34project.org> | 2025-09-13 14:55:15 -0600 |
| commit | a2ea06d513a5802964f8f0ef5795cec7e548ed7b (patch) | |
| tree | 8afb58e3749d19bc46cffc6473f3059d647c515b /templates/macros/format_date.html | |
Squashed 'themes/tabi-lean/' content from commit 95c8796
git-subtree-dir: themes/tabi-lean
git-subtree-split: 95c879696445ede40daa7a30a88dae5dd74d5c0c
Diffstat (limited to 'templates/macros/format_date.html')
| -rw-r--r-- | templates/macros/format_date.html | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/templates/macros/format_date.html b/templates/macros/format_date.html new file mode 100644 index 0000000..f747fd1 --- /dev/null +++ b/templates/macros/format_date.html @@ -0,0 +1,59 @@ +{%- macro format_date(date, short, language_strings="") -%} + +{#- Set locale -#} +{%- set date_locale = macros_translate::translate(key="date_locale", default="en_GB", language_strings=language_strings) -%} + +{#- Check for language-specific date formats -#} +{%- set language_format = "" -%} +{%- if config.extra.date_formats -%} + {%- for format_config in config.extra.date_formats -%} + {%- if format_config.lang == lang -%} + {%- if short and format_config.short -%} + {%- set_global language_format = format_config.short -%} + {%- elif not short and format_config.long -%} + {%- set_global language_format = format_config.long -%} + {%- endif -%} + {%- endif -%} + {%- endfor -%} +{%- endif -%} + +{%- if language_format -%} + {{ date | date(format=language_format, locale=date_locale) }} +{%- elif config.extra.short_date_format and short -%} + {{ date | date(format=config.extra.short_date_format, locale=date_locale) }} +{%- elif 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 -%} +{%- else -%} + {%- if short -%} + {{ date | date(format="%-d %b %Y", locale=date_locale) }} + {%- else -%} + {{ date | date(format="%d %b %Y", locale=date_locale) }} + {%- endif -%} +{%- endif -%} + +{%- endmacro -%} |
