From a8ce3f65eeceec6bd6decabd475d2dd6edb82d78 Mon Sep 17 00:00:00 2001 From: Capybara-z Date: Thu, 3 Apr 2025 22:17:19 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=84=D0=BE=D1=80=D0=BC=D1=83=D0=BB=D1=8B?= =?UTF-8?q?=20=D1=81=D0=BA=D0=BB=D0=BE=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Добалвение формулы склонения - Адаптация клонение дней к новой формуле. --- handlers/utils.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/handlers/utils.py b/handlers/utils.py index b9c2dd5c..72b939ef 100644 --- a/handlers/utils.py +++ b/handlers/utils.py @@ -152,6 +152,12 @@ def format_time_until_deletion(seconds: int) -> str: return " и ".join(parts) if parts else "менее минуты" +def get_plural_form(num: int, form1: str, form2: str, form3: str) -> str: + n = abs(num) % 100 + if 10 < n < 20: + return form3 + return {1: form1, 2: form2, 3: form2, 4: form2}.get(n % 10, form3) + def format_days(days: int) -> str: """ Форматирует количество дней с правильным склонением. @@ -164,13 +170,7 @@ def format_days(days: int) -> str: """ if days <= 0: return "0 дней" - - if days % 10 == 1 and days % 100 != 11: - return f"{days} день" - elif days % 10 in [2, 3, 4] and days % 100 not in [12, 13, 14]: - return f"{days} дня" - else: - return f"{days} дней" + return f"{days} {get_plural_form(days, 'день', 'дня', 'дней')}" async def edit_or_send_message(