From b836bcdc7030ec57dfca6fb3959b278ba09403ee Mon Sep 17 00:00:00 2001 From: Capybara-z Date: Thu, 3 Apr 2025 10:26:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=81=D0=BA=D0=BB=D0=BE=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4?= =?UTF-8?q?=D0=BD=D0=B5=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Добавлена функция склонения дней. --- handlers/utils.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/handlers/utils.py b/handlers/utils.py index 75171ac4..b9c2dd5c 100644 --- a/handlers/utils.py +++ b/handlers/utils.py @@ -152,6 +152,27 @@ def format_time_until_deletion(seconds: int) -> str: return " и ".join(parts) if parts else "менее минуты" +def format_days(days: int) -> str: + """ + Форматирует количество дней с правильным склонением. + + Args: + days (int): Количество дней. + + Returns: + 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} дней" + + async def edit_or_send_message( target_message: Message, text: str,