From b599d10eb6054cac8c20a2718cce13082b05f61f Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Tue, 26 Dec 2023 19:29:07 +0000 Subject: [PATCH] Fix for wrong event times during DST Closes: #87 --- agenda/__init__.py | 5 ----- agenda/data.py | 13 +++++++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/agenda/__init__.py b/agenda/__init__.py index ea2b6df..baf8813 100644 --- a/agenda/__init__.py +++ b/agenda/__init__.py @@ -10,8 +10,3 @@ uk_tz = pytz.timezone("Europe/London") def uk_time(d: date, t: time) -> datetime: """Combine time and date for UK timezone.""" return uk_tz.localize(datetime.combine(d, t)) - - -def uk_midnight(d: date) -> datetime: - """Midnight UK time.""" - return uk_time(d, datetime.min.time()) diff --git a/agenda/data.py b/agenda/data.py index f48e2eb..ce677f5 100644 --- a/agenda/data.py +++ b/agenda/data.py @@ -32,7 +32,7 @@ from . import ( thespacedevs, travel, uk_holiday, - uk_midnight, + uk_tz, waste_schedule, ) from .types import Event, Holiday @@ -125,6 +125,11 @@ def get_holidays(country: str, start_date: date, end_date: date) -> list[Holiday return found +def midnight(d: date) -> datetime: + """Convert from date to midnight on that day.""" + return datetime.combine(d, datetime.min.time()) + + def dates_from_rrule( rrule: str, start: date, end: date ) -> typing.Sequence[datetime | date]: @@ -132,9 +137,9 @@ def dates_from_rrule( all_day = not any(param in rrule for param in ["BYHOUR", "BYMINUTE", "BYSECOND"]) return [ - i.date() if all_day else i - for i in dateutil.rrule.rrulestr(rrule, dtstart=uk_midnight(start)).between( - uk_midnight(start), uk_midnight(end) + i.date() if all_day else uk_tz.localize(i) + for i in dateutil.rrule.rrulestr(rrule, dtstart=midnight(start)).between( + midnight(start), midnight(end) ) ]