From 7c3823b5f8400b1f105ae5e1d317f76badf6f480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80=20=D0=91=D1=8B=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=B2?= Date: Wed, 11 Nov 2026 18:54:23 +0500 Subject: [PATCH] Fix Hungarian humanize output with only_distance Use the existing future timeframe forms for standalone distances, including multi-part descriptions and zero values. Preserve the inflected past forms when relative wording is included. --- arrow/locales.py | 24 ++++++++++++++++++++ tests/test_locales.py | 53 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/arrow/locales.py b/arrow/locales.py index 757df480d..c651882dd 100644 --- a/arrow/locales.py +++ b/arrow/locales.py @@ -3924,6 +3924,30 @@ class HungarianLocale(Locale): meridians = {"am": "de", "pm": "du", "AM": "DE", "PM": "DU"} + def describe( + self, + timeframe: TimeFrameLiteral, + delta: Union[float, int] = 0, + only_distance: bool = False, + ) -> str: + if only_distance: + form = self.timeframes[timeframe] + if isinstance(form, Mapping): + return form["future"].format(trunc(abs(delta))) + return super().describe(timeframe, delta, only_distance) + + def describe_multi( + self, + timeframes: Sequence[Tuple[TimeFrameLiteral, Union[int, float]]], + only_distance: bool = False, + ) -> str: + if only_distance: + return " ".join( + self.describe(timeframe, delta, only_distance=True) + for timeframe, delta in timeframes + ) + return super().describe_multi(timeframes, only_distance) + def _format_timeframe(self, timeframe: TimeFrameLiteral, delta: int) -> str: form = self.timeframes[timeframe] diff --git a/tests/test_locales.py b/tests/test_locales.py index 3d7120e36..c57755ee1 100644 --- a/tests/test_locales.py +++ b/tests/test_locales.py @@ -1358,6 +1358,59 @@ def test_weekday(self): @pytest.mark.usefixtures("lang_locale") class TestHungarianLocale: + @pytest.mark.parametrize( + "timeframe, delta, expected", + [ + ("minute", -1, "egy perc"), + ("minutes", -2, "2 perc"), + ("hour", -1, "egy óra"), + ("hours", -2, "2 óra"), + ("day", -1, "egy nap"), + ("days", -2, "2 nap"), + ("week", -1, "egy hét"), + ("weeks", -2, "2 hét"), + ("month", -1, "egy hónap"), + ("months", -2, "2 hónap"), + ("year", -1, "egy év"), + ("years", -17, "17 év"), + ("days", 0, "0 nap"), + ("now", 0, "éppen most"), + ], + ) + def test_describe_only_distance(self, timeframe, delta, expected): + assert self.locale.describe(timeframe, delta, only_distance=True) == expected + assert self.locale.describe(timeframe, -delta, only_distance=True) == expected + + def test_describe_multi_only_distance(self): + timeframes = [("days", -2), ("hours", 0), ("minutes", -3)] + assert ( + self.locale.describe_multi(timeframes, only_distance=True) + == "2 nap 0 óra 3 perc" + ) + assert ( + self.locale.describe_multi(timeframes) + == "2 nappal 0 órával 3 perccel ezelőtt" + ) + assert timeframes == [("days", -2), ("hours", 0), ("minutes", -3)] + + @pytest.mark.parametrize("locale", ["hu", "hu-hu", "hu_HU"]) + def test_humanize_only_distance(self, locale): + other = arrow.Arrow(2020, 6, 1) + earlier = other.shift(years=-17) + assert earlier.humanize(other, locale=locale, only_distance=True) == "17 év" + assert earlier.humanize(other, locale=locale) == "17 évvel ezelőtt" + earlier = other.shift(days=-2, hours=-3) + assert ( + earlier.humanize( + other, locale=locale, only_distance=True, granularity=["day", "hour"] + ) + == "2 nap 3 óra" + ) + assert ( + earlier.humanize(other, locale=locale, granularity=["day", "hour"]) + == "2 nappal 3 órával ezelőtt" + ) + def test_format_timeframe(self): # Now assert self.locale._format_timeframe("now", 0) == "éppen most"