Show economist double issues (weeks 25 and 51)

Closes: #62
This commit is contained in:
Edward Betts 2023-11-20 07:51:35 -03:00
parent bd3649a6c7
commit 71e9ce4af8

View file

@ -2,27 +2,36 @@
from datetime import date, time, timedelta
from dateutil.relativedelta import TH, relativedelta
from . import uk_time
from .types import Event
def publication_dates(start_date: date, end_date: date) -> list[Event]:
"""List of Economist publication dates."""
# Define the publication day (Thursday) and non-publication weeks
publication_day = 3 # Thursday (0 - Monday, 1 - Tuesday, ..., 6 - Sunday)
# Define the list of weeks when The Economist is not published
non_publication_weeks = [26, 52]
double_issue = {
25: "Summer",
51: "Christmas",
}
current_date = start_date
publication_dates = []
t = time(19, 0)
while current_date <= end_date:
if (
current_date.weekday() == publication_day
and current_date.isocalendar().week not in non_publication_weeks
):
publication_dates.append(uk_time(current_date, t))
current_date += timedelta(days=1)
start_thursday = start_date + relativedelta(weekday=TH(+1))
end_thursday = end_date + relativedelta(weekday=TH(+1))
days = (end_thursday - start_thursday).days
return [Event(name="economist", date=pub_date) for pub_date in publication_dates]
events: list[Event] = []
for offset in range(0, days, 7):
pub_date = start_thursday + timedelta(days=offset)
week = pub_date.isocalendar().week
if week in non_publication_weeks:
continue
e = Event(name="economist", date=uk_time(pub_date, t))
if week in double_issue:
e.title = double_issue[week] + " double issue"
events.append(e)
return events