From 9b457195918a3b69960a88ff3be321b8d5a7c262 Mon Sep 17 00:00:00 2001 From: Guy Date: Tue, 21 Sep 2021 21:51:25 +0300 Subject: [PATCH] Fixing Plural of Years and Days in Hebrew (#1042) --- arrow/locales.py | 22 ++++++++++------------ tests/test_arrow.py | 16 ++++++++++++++++ tests/test_locales.py | 2 ++ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/arrow/locales.py b/arrow/locales.py index 6221df7a..bdfb0567 100644 --- a/arrow/locales.py +++ b/arrow/locales.py @@ -3370,15 +3370,15 @@ class HebrewLocale(Locale): "minute": "דקה", "minutes": "{0} דקות", "hour": "שעה", - "hours": {"2": "שעתיים", "general": "{0} שעות"}, + "hours": {"2": "שעתיים", "ten": "{0} שעות", "higher": "{0} שעות"}, "day": "יום", - "days": {"2": "יומיים", "general": "{0} ימים"}, + "days": {"2": "יומיים", "ten": "{0} ימים", "higher": "{0} יום"}, "week": "שבוע", - "weeks": {"2": "שבועיים", "general": "{0} שבועות"}, + "weeks": {"2": "שבועיים", "ten": "{0} שבועות", "higher": "{0} שבועות"}, "month": "חודש", - "months": {"2": "חודשיים", "general": "{0} חודשים"}, + "months": {"2": "חודשיים", "ten": "{0} חודשים", "higher": "{0} חודשים"}, "year": "שנה", - "years": {"2": "שנתיים", "general": "{0} שנים"}, + "years": {"2": "שנתיים", "ten": "{0} שנים", "higher": "{0} שנה"}, } meridians = { @@ -3422,18 +3422,16 @@ class HebrewLocale(Locale): day_names = ["", "שני", "שלישי", "רביעי", "חמישי", "שישי", "שבת", "ראשון"] day_abbreviations = ["", "ב׳", "ג׳", "ד׳", "ה׳", "ו׳", "ש׳", "א׳"] - def _format_timeframe( - self, timeframe: TimeFrameLiteral, delta: Union[float, int] - ) -> str: - """Hebrew couple of aware""" + def _format_timeframe(self, timeframe: TimeFrameLiteral, delta: int) -> str: form = self.timeframes[timeframe] - delta = abs(trunc(delta)) - + delta = abs(delta) if isinstance(form, Mapping): if delta == 2: form = form["2"] + elif delta == 0 or 2 < delta <= 10: + form = form["ten"] else: - form = form["general"] + form = form["higher"] return form.format(delta) diff --git a/tests/test_arrow.py b/tests/test_arrow.py index f217909a..732cd79c 100644 --- a/tests/test_arrow.py +++ b/tests/test_arrow.py @@ -2656,6 +2656,22 @@ def test_years(self, locale_list_no_weeks): assert arw.dehumanize(year_ago_string, locale=lang) == year_ago assert arw.dehumanize(year_future_string, locale=lang) == year_future + def test_gt_than_10_years(self, locale_list_no_weeks): + + for lang in locale_list_no_weeks: + + arw = arrow.Arrow(2000, 1, 10, 5, 55, 0) + year_ago = arw.shift(years=-25) + year_future = arw.shift(years=25) + + year_ago_string = year_ago.humanize(arw, locale=lang, granularity=["year"]) + year_future_string = year_future.humanize( + arw, locale=lang, granularity=["year"] + ) + + assert arw.dehumanize(year_ago_string, locale=lang) == year_ago + assert arw.dehumanize(year_future_string, locale=lang) == year_future + def test_mixed_granularity(self, locale_list_no_weeks): for lang in locale_list_no_weeks: diff --git a/tests/test_locales.py b/tests/test_locales.py index 5cb0ab8f..a69a085c 100644 --- a/tests/test_locales.py +++ b/tests/test_locales.py @@ -728,6 +728,7 @@ def test_couple_of_timeframe(self): assert self.locale._format_timeframe("day", 1) == "יום" assert self.locale._format_timeframe("days", 2) == "יומיים" assert self.locale._format_timeframe("days", 3) == "3 ימים" + assert self.locale._format_timeframe("days", 80) == "80 יום" assert self.locale._format_timeframe("hour", 1) == "שעה" assert self.locale._format_timeframe("hours", 2) == "שעתיים" @@ -744,6 +745,7 @@ def test_couple_of_timeframe(self): assert self.locale._format_timeframe("year", 1) == "שנה" assert self.locale._format_timeframe("years", 2) == "שנתיים" assert self.locale._format_timeframe("years", 5) == "5 שנים" + assert self.locale._format_timeframe("years", 15) == "15 שנה" def test_describe_multi(self): describe = self.locale.describe_multi