Compare commits

...

2 commits

2 changed files with 9 additions and 9 deletions

View file

@ -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())

View file

@ -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)
)
]