Attempted a fix for #8

This commit is contained in:
2024-05-30 17:47:23 +02:00
committed by Profitroll
parent de483cd450
commit b5bfbcd375
7 changed files with 62 additions and 49 deletions

View File

@@ -1,5 +1,5 @@
import logging
from datetime import datetime, timedelta
from datetime import datetime, timezone
from bson import json_util
from libbot.pyrogram.classes import PyroClient
@@ -9,13 +9,12 @@ from classes.location import Location
from classes.pyrouser import PyroUser
from modules.database import col_users
from modules.database_api import col_entries
from modules.utils import from_utc
logger = logging.getLogger(__name__)
async def remind(app: PyroClient) -> None:
utcnow = datetime.utcnow()
utcnow = datetime.now(timezone.utc)
logger.debug("Performing reminder lookup for %s (UTCNOW)", utcnow)
@@ -40,12 +39,16 @@ async def remind(app: PyroClient) -> None:
try:
location: Location = await app.get_location(user.location.id) # type: ignore
except ValueError:
logger.warning("Skipping reminder for %s due to invalid location", user.id)
continue
user_date = from_utc(
datetime.utcnow() + timedelta(days=user.offset),
user.location.timezone.zone,
).replace(hour=0, minute=0, second=0, microsecond=0)
try:
user_date = user.get_reminder_date()
except AttributeError:
logger.warning(
"Skipping reminder for %s due to missing attributes", user.id
)
continue
entries = await col_entries.find(
{

View File

@@ -6,7 +6,9 @@ from pytz import timezone as pytz_timezone
def to_utc(date: datetime, timezone: Union[str, None] = None) -> datetime:
"""Move timezone unaware datetime object to UTC timezone and return it.
"""*DEPRECATED AND WILL BE REMOVED IN FUTURE RELEASES*
Move timezone unaware datetime object to UTC timezone and return it.
### Args:
* date (`datetime`): Datetime to be converted.
@@ -20,7 +22,9 @@ def to_utc(date: datetime, timezone: Union[str, None] = None) -> datetime:
def from_utc(date: datetime, timezone: Union[str, None] = None) -> datetime:
"""Move timezone unaware datetime object to the timezone specified and return it.
"""*DEPRECATED AND WILL BE REMOVED IN FUTURE RELEASES*
Move timezone unaware datetime object to the timezone specified and return it.
### Args:
* date (`datetime`): Datetime to be converted.