parent
cd575afe68
commit
b599d10eb6
|
@ -10,8 +10,3 @@ uk_tz = pytz.timezone("Europe/London")
|
||||||
def uk_time(d: date, t: time) -> datetime:
|
def uk_time(d: date, t: time) -> datetime:
|
||||||
"""Combine time and date for UK timezone."""
|
"""Combine time and date for UK timezone."""
|
||||||
return uk_tz.localize(datetime.combine(d, t))
|
return uk_tz.localize(datetime.combine(d, t))
|
||||||
|
|
||||||
|
|
||||||
def uk_midnight(d: date) -> datetime:
|
|
||||||
"""Midnight UK time."""
|
|
||||||
return uk_time(d, datetime.min.time())
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ from . import (
|
||||||
thespacedevs,
|
thespacedevs,
|
||||||
travel,
|
travel,
|
||||||
uk_holiday,
|
uk_holiday,
|
||||||
uk_midnight,
|
uk_tz,
|
||||||
waste_schedule,
|
waste_schedule,
|
||||||
)
|
)
|
||||||
from .types import Event, Holiday
|
from .types import Event, Holiday
|
||||||
|
@ -125,6 +125,11 @@ def get_holidays(country: str, start_date: date, end_date: date) -> list[Holiday
|
||||||
return found
|
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(
|
def dates_from_rrule(
|
||||||
rrule: str, start: date, end: date
|
rrule: str, start: date, end: date
|
||||||
) -> typing.Sequence[datetime | 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"])
|
all_day = not any(param in rrule for param in ["BYHOUR", "BYMINUTE", "BYSECOND"])
|
||||||
|
|
||||||
return [
|
return [
|
||||||
i.date() if all_day else i
|
i.date() if all_day else uk_tz.localize(i)
|
||||||
for i in dateutil.rrule.rrulestr(rrule, dtstart=uk_midnight(start)).between(
|
for i in dateutil.rrule.rrulestr(rrule, dtstart=midnight(start)).between(
|
||||||
uk_midnight(start), uk_midnight(end)
|
midnight(start), midnight(end)
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue