Attempt to work around timezones

This commit is contained in:
2023-09-24 23:47:09 +02:00
parent b0f76f4c49
commit 3fa2f5a800
13 changed files with 99 additions and 36 deletions

View File

@@ -2,25 +2,25 @@ import logging
from datetime import datetime, timedelta, timezone
from libbot.pyrogram.classes import PyroClient
from pytz import timezone as pytz_timezone
from classes.enums import GarbageType
from classes.location import Location
from classes.pyrouser import PyroUser
from modules.database import col_entries, col_users
from modules.utils import from_utc
logger = logging.getLogger(__name__)
async def remind(app: PyroClient) -> None:
now = datetime.now()
utcnow = datetime.utcnow()
users = await col_users.find(
{"time_hour": now.hour, "time_minute": now.minute}
{"time_hour": utcnow.hour, "time_minute": utcnow.minute}
).to_list()
for user_db in users:
user = PyroUser(**user_db)
user = await PyroUser.from_dict(**user_db)
if not user.enabled or user.location is None:
continue
@@ -30,12 +30,10 @@ async def remind(app: PyroClient) -> None:
except ValueError:
continue
user_date = (
datetime.now(pytz_timezone(location.timezone)).replace(
second=0, microsecond=0
)
+ timedelta(days=user.offset)
).replace(tzinfo=timezone.utc)
user_date = from_utc(
datetime(1970, 1, 1, user.time_hour, user.time_minute),
user.location.timezone.zone,
)
entries = await col_entries.find(
{