From cd6fbd886c0a39e9dbe15fc89a4ea3638271090a Mon Sep 17 00:00:00 2001 From: Danny Adair Date: Wed, 10 Sep 2025 01:05:51 +1200 Subject: [PATCH] Add support for New Zealand (en-nz) date/time formats (#5449) - Implement en-NZ specific formatting in daterange.py - Create en_NZ/formats.py with NZ-compliant formats --- src/pretix/helpers/daterange.py | 10 ++++ src/pretix/helpers/formats/en_NZ/__init__.py | 21 ++++++++ src/pretix/helpers/formats/en_NZ/formats.py | 50 ++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 src/pretix/helpers/formats/en_NZ/__init__.py create mode 100644 src/pretix/helpers/formats/en_NZ/formats.py diff --git a/src/pretix/helpers/daterange.py b/src/pretix/helpers/daterange.py index 1c1fde0315..6ad12ebe35 100644 --- a/src/pretix/helpers/daterange.py +++ b/src/pretix/helpers/daterange.py @@ -64,6 +64,16 @@ def daterange(df, dt, as_html=False): return format_html(base_format, _date(df, "j."), mark_safe(until.strip()), _date(dt, "j. F Y")) elif df.year == dt.year: return format_html(base_format, _date(df, "j. F"), until, _date(dt, "j. F Y")) + elif lng == "en-nz": + if df.year == dt.year and df.month == dt.month and df.day == dt.day: + # Mon, 15 January 2024 + return format_html(base_format, _date(df, "D, j F Y")) + elif df.year == dt.year and df.month == dt.month: + # 1 – 3 January 2024 + return format_html(base_format, _date(df, "j"), until, _date(dt, "j F Y")) + elif df.year == dt.year: + # 1 January – 3 April 2024 + return format_html(base_format, _date(df, "j F"), until, _date(dt, "j F Y")) elif lng.startswith("en"): if df.year == dt.year and df.month == dt.month and df.day == dt.day: return format_html(base_format, _date(df, "D, N jS, Y")) diff --git a/src/pretix/helpers/formats/en_NZ/__init__.py b/src/pretix/helpers/formats/en_NZ/__init__.py new file mode 100644 index 0000000000..9fd5bdc500 --- /dev/null +++ b/src/pretix/helpers/formats/en_NZ/__init__.py @@ -0,0 +1,21 @@ +# +# This file is part of pretix (Community Edition). +# +# Copyright (C) 2014-2020 Raphael Michel and contributors +# Copyright (C) 2020-2021 rami.io GmbH and contributors +# +# This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General +# Public License as published by the Free Software Foundation in version 3 of the License. +# +# ADDITIONAL TERMS APPLY: Pursuant to Section 7 of the GNU Affero General Public License, additional terms are +# applicable granting you additional permissions and placing additional restrictions on your usage of this software. +# Please refer to the pretix LICENSE file to obtain the full terms applicable to this work. If you did not receive +# this file, see . +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +# details. +# +# You should have received a copy of the GNU Affero General Public License along with this program. If not, see +# . +# diff --git a/src/pretix/helpers/formats/en_NZ/formats.py b/src/pretix/helpers/formats/en_NZ/formats.py new file mode 100644 index 0000000000..ed26c5d766 --- /dev/null +++ b/src/pretix/helpers/formats/en_NZ/formats.py @@ -0,0 +1,50 @@ +# +# This file is part of pretix (Community Edition). +# +# Copyright (C) 2014-2020 Raphael Michel and contributors +# Copyright (C) 2020-2021 rami.io GmbH and contributors +# +# This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General +# Public License as published by the Free Software Foundation in version 3 of the License. +# +# ADDITIONAL TERMS APPLY: Pursuant to Section 7 of the GNU Affero General Public License, additional terms are +# applicable granting you additional permissions and placing additional restrictions on your usage of this software. +# Please refer to the pretix LICENSE file to obtain the full terms applicable to this work. If you did not receive +# this file, see . +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +# details. +# +# You should have received a copy of the GNU Affero General Public License along with this program. If not, see +# . +# + +# Date according to https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date +# Following NZ government guidance from https://www.digital.govt.nz/standards-and-guidance/design-and-ux/content-design-guidance/writing-style/numbers +DATE_FORMAT = "j F Y" # 12 December 2015 +DATETIME_FORMAT = "j F Y, g:ia" # 12 December 2015, 5:30pm +TIME_FORMAT = "g:ia" # 5:30pm +YEAR_MONTH_FORMAT = "F Y" # December 2015 +MONTH_DAY_FORMAT = "j F" # 12 December +SHORT_DATE_FORMAT = "j F Y" # same as DATE_FORMAT per guidance +SHORT_DATETIME_FORMAT = "j F Y, g:ia" +WEEKDAY_FORMAT = "l" # Monday +WEEKDAY_DATE_FORMAT = "l, j F Y" # Friday, 23 November 2018 +WEEK_FORMAT = "\\W W, o" # ISO week: "W 52, 2024" +WEEK_DAY_FORMAT = "D, j M" # Abbrev weekday and month: "Mon, 5 Feb" +SHORT_MONTH_DAY_FORMAT = "j/n" # Numeric day/month: "5/2" + +# Parsing inputs; keep d/m/Y and ISO +DATE_INPUT_FORMATS = [ + "%d/%m/%Y", + "%Y-%m-%d", + "%d/%m/%y", +] + +TIME_INPUT_FORMATS = [ + "%I:%M%p", # 5:30pm + "%H:%M:%S", + "%H:%M:%S.%f", + "%H:%M", +]