Improved event time loading #410
All checks were successful
Deploy dev on push / on-push-deploy_sh-edraft (push) Successful in 5m12s
Deploy staging on push / on-push-deploy_sh-edraft (push) Successful in 3m40s

This commit is contained in:
Sven Heidemann 2023-12-02 15:15:38 +01:00
parent af3084ad36
commit 8a76b46165
2 changed files with 13 additions and 32 deletions

View File

@ -74,7 +74,8 @@ class EventService:
active_event.participants.append(user)
def _append_interval(self, interval: ScheduledEventIntervalEnum, ts: datetime) -> datetime:
if ts >= datetime.now():
now = datetime.now().replace(tzinfo=ZoneInfo("Europe/Berlin"))
if ts >= now:
return ts
if interval == ScheduledEventIntervalEnum.daily:
@ -90,7 +91,7 @@ class EventService:
elif interval == ScheduledEventIntervalEnum.yearly:
ts = ts + timedelta(days=365)
while ts < datetime.now():
while ts < now:
ts = self._append_interval(interval, ts)
return ts
@ -114,12 +115,18 @@ class EventService:
kwargs["channel"] = guild.get_channel(scheduled_event.channel_id)
if scheduled_event.start_time is not None:
scheduled_event.start_time = self._append_interval(scheduled_event.interval, scheduled_event.start_time)
kwargs["start_time"] = scheduled_event.start_time.replace(tzinfo=ZoneInfo("Europe/Berlin"))
start_time = self._append_interval(
scheduled_event.interval, scheduled_event.start_time.replace(tzinfo=ZoneInfo("Europe/Berlin"))
)
kwargs["start_time"] = start_time
scheduled_event.start_time = scheduled_event.start_time.replace(tzinfo=None)
if scheduled_event.end_time is not None:
scheduled_event.end_time = self._append_interval(scheduled_event.interval, scheduled_event.end_time)
kwargs["end_time"] = scheduled_event.end_time.replace(tzinfo=ZoneInfo("Europe/Berlin"))
end_time = self._append_interval(
scheduled_event.interval, scheduled_event.end_time.replace(tzinfo=ZoneInfo("Europe/Berlin"))
)
kwargs["end_time"] = end_time
scheduled_event.end_time = scheduled_event.end_time.replace(tzinfo=None)
kwargs["entity_type"] = scheduled_event.entity_type
if scheduled_event.location is not None:

View File

@ -1,26 +0,0 @@
# -*- coding: utf-8 -*-
"""
bot sh-edraft.de Discord bot
~~~~~~~~~~~~~~~~~~~
Discord bot for customers of sh-edraft.de
:copyright: (c) 2022 - 2023 sh-edraft.de
:license: MIT, see LICENSE for more details.
"""
__title__ = "modules.base.thread"
__author__ = "Sven Heidemann"
__license__ = "MIT"
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
__version__ = "1.2.2"
from collections import namedtuple
# imports
VersionInfo = namedtuple("VersionInfo", "major minor micro")
version_info = VersionInfo(major="1", minor="2", micro="2")