Fix announcement timezones

pull/136/head v3.0.1
stijndcl 2022-10-05 21:04:06 +02:00
parent 27accf61b7
commit d190185c12
3 changed files with 3 additions and 11 deletions

View File

@ -2,11 +2,11 @@ import re
from dataclasses import dataclass, field from dataclasses import dataclass, field
from datetime import datetime from datetime import datetime
from typing import Optional from typing import Optional
from zoneinfo import ZoneInfo
import async_timeout import async_timeout
import discord import discord
import feedparser import feedparser
import pytz
from aiohttp import ClientSession from aiohttp import ClientSession
from markdownify import markdownify as md from markdownify import markdownify as md
from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.ext.asyncio import AsyncSession
@ -16,7 +16,7 @@ from database.crud import ufora_announcements as crud
from database.schemas import UforaCourse from database.schemas import UforaCourse
from didier.data.embeds.base import EmbedBaseModel from didier.data.embeds.base import EmbedBaseModel
from didier.utils.discord.colours import ghent_university_blue from didier.utils.discord.colours import ghent_university_blue
from didier.utils.types.datetime import int_to_weekday from didier.utils.types.datetime import LOCAL_TIMEZONE, int_to_weekday
from didier.utils.types.string import leading from didier.utils.types.string import leading
__all__ = [ __all__ = [
@ -89,13 +89,7 @@ class UforaNotification(EmbedBaseModel):
# We will hereby cut it out and pray the timezone will always be UTC+0 # We will hereby cut it out and pray the timezone will always be UTC+0
published = self.content["published"].rsplit(" ", 1)[0] published = self.content["published"].rsplit(" ", 1)[0]
time_string = "%a, %d %b %Y %H:%M:%S" time_string = "%a, %d %b %Y %H:%M:%S"
dt = datetime.strptime(published, time_string).astimezone(pytz.timezone("Europe/Brussels")) dt = datetime.strptime(published, time_string).replace(tzinfo=ZoneInfo("GMT")).astimezone(LOCAL_TIMEZONE)
# Apply timezone offset in a hacky way
offset = dt.utcoffset()
if offset is not None:
dt += offset
return dt return dt
def _get_published(self) -> str: def _get_published(self) -> str:

View File

@ -9,7 +9,6 @@ pytest-env==0.6.2
sqlalchemy2-stubs==0.0.2a23 sqlalchemy2-stubs==0.0.2a23
types-beautifulsoup4==4.11.3 types-beautifulsoup4==4.11.3
types-python-dateutil==2.8.19 types-python-dateutil==2.8.19
types-pytz==2021.3.8
# Flake8 + plugins # Flake8 + plugins
flake8==4.0.1 flake8==4.0.1

View File

@ -10,5 +10,4 @@ markdownify==0.11.2
overrides==6.1.0 overrides==6.1.0
pydantic==1.9.1 pydantic==1.9.1
python-dateutil==2.8.2 python-dateutil==2.8.2
pytz==2022.1
sqlalchemy[asyncio]==1.4.37 sqlalchemy[asyncio]==1.4.37