python_bot/handlers/time_new_year.py

27 lines
1.2 KiB
Python
Raw Normal View History

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