python_bot/handlers/time_new_year.py
2023-06-22 18:55:27 +03:00

29 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from aiogram import types
from create_bot import dp
import datetime
@dp.message_handler(commands=["time"])
async def send_time(message: types.Message):
new_year = datetime.datetime(2024, 12, 31) # дата нового года
ct = datetime.datetime.now() # дата/время
cd = datetime.datetime.now().strftime("%d/%m/%Y") # дата (д,м,г)
ct1 = ct+datetime.timedelta(hours=15) # +14 часов от сервера
ct2 = ct1.strftime('%H:%M') # форматирует дату/время просто во время(ч, м)
date_difference = (new_year - ct).days # отнимает от нг текущее время и получаем разницу в днях
days = ['день', 'дня', 'дней']
if date_difference % 10 == 1 and date_difference % 100 != 11:
p = 0
elif 2 <= date_difference % 10 <= 4 and (date_difference % 100 < 10 or date_difference % 100 >= 20):
p = 1
else:
p = 2
num = (str(date_difference) + ' ' + days[p])
await message.reply(f'Сегодня {cd} \nВремя: {ct2} \nДо Нового Года осталось {num}')
# def register_handlers_time(dp: Dispatcher):
# dp.register_message_handler(send_time)