36 lines
1009 B
Python
36 lines
1009 B
Python
import datetime
|
|
import zoneinfo
|
|
|
|
from helpers.models import User
|
|
|
|
|
|
campus_timdelta = {
|
|
"Москва": 3,
|
|
"Санкт-Петербург": 3,
|
|
"Нижний Новгород": 3,
|
|
"Пермь": 5
|
|
}
|
|
|
|
def now(user: User):
|
|
today = datetime.datetime.now() + datetime.timedelta(hours=campus_timdelta[user.campus])
|
|
return today
|
|
|
|
|
|
def get_next_daily_notify_time(user: User, time_now: datetime.datetime | None = None) -> datetime.datetime:
|
|
if time_now is None:
|
|
time_now = now(user)
|
|
hours, minutes = map(int, user.daily_notify_time.split(":"))
|
|
next_time = datetime.datetime(
|
|
year=time_now.year,
|
|
month=time_now.month,
|
|
day=time_now.day,
|
|
hour=hours,
|
|
minute=minutes
|
|
)
|
|
print('now time is', time_now)
|
|
print('user wants to notify at', hours, minutes)
|
|
if time_now.hour * 60 + time_now.minute > hours * 60 + minutes:
|
|
print('go to next day')
|
|
next_time = next_time + datetime.timedelta(days=1)
|
|
return next_time
|