From fe6b780e12700cc10600e557288b17b5cf25d886 Mon Sep 17 00:00:00 2001 From: Adam Moussa <166072409+amoussa1229@users.noreply.github.com> Date: Wed, 8 Apr 2026 13:36:34 -0400 Subject: [PATCH] Fix weekly schedule starting from today instead of Monday (#18) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The handler passed `now` as start_date, so mid-week runs showed 14 days from today instead of Mon–Sun x2. Also, day names were derived from a static index (DAY_ORDER[i%7]) which assumed index 0 = Monday — when start_date wasn't Monday, Saturday and Sunday were mislabeled as Monday and Tuesday. Fix: pass this week's Monday from the handler, and derive day names from the actual date via strftime instead of a static list. Fixes #17 --- src/blocks.py | 3 +-- src/weekly_post.py | 7 ++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/blocks.py b/src/blocks.py index 4ce3234..db3d056 100644 --- a/src/blocks.py +++ b/src/blocks.py @@ -5,7 +5,6 @@ from zoneinfo import ZoneInfo EASTERN = ZoneInfo("America/New_York") -DAY_ORDER = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] WEEKEND_DAYS = {"Saturday", "Sunday"} @@ -47,7 +46,7 @@ def build_week_schedule(schedule, start_date: datetime | None = None) -> list[di lines.append("") # visual separator between weeks date = start_date + timedelta(days=i) date_str = date.strftime("%Y-%m-%d") - day_name = DAY_ORDER[i % 7] + day_name = date.strftime("%A") is_today = date_str == today_str # Weekend day shift (8am–5pm) diff --git a/src/weekly_post.py b/src/weekly_post.py index 2695d6b..100a334 100644 --- a/src/weekly_post.py +++ b/src/weekly_post.py @@ -172,10 +172,11 @@ def handler(event, context): # Email pay summary to payroll _send_pay_email(week_label, pay_record) - # --- Two-week schedule --- - blocks = build_week_schedule(schedule, start_date=now) + # --- Two-week schedule (always starts on Monday of this week) --- + this_monday = now - timedelta(days=now.weekday()) + blocks = build_week_schedule(schedule, start_date=this_monday) - end_date = now + timedelta(days=13) + end_date = this_monday + timedelta(days=13) slack.chat_postMessage( channel=channel_id, blocks=blocks,