Fix the seven day window for a signups chart

Review the AI's codeMedium15 min

Your task

You asked an AI for a query that counts signups on each of the last 7 days. It ran and returned rows, but a query that runs can still count the wrong days. Before the numbers go on a dashboard, your team recomputes them from the raw signup timestamps and compares.

An assistant wrote daily_signup_counts(timestamps, end_day). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • timestamps: one string per signup, usually a date and a time such as 2026-06-20 09:00:00 or 2026-06-20T09:00:00. Any string can appear.
  • end_day: the last day of the window, as text.
  • Return a list of exactly 7 counts, oldest day first.

Rules the tests check:

  • end_day must be a real date in the exact form YYYY-MM-DD: 10 characters, - as the 5th and 8th, digits 0 to 9 everywhere else, a month from 1 to 12 and a day that exists in that month. If it is not, return seven zeros.
  • February has 29 days in a leap year. A leap year is divisible by 4, except a year divisible by 100, which is a leap year only when it is also divisible by 400.
  • The window is the 7 calendar days that end on end_day: from 6 days before it up to end_day itself. Index 0 is the oldest day and index 6 is end_day. Counting back crosses month ends and year ends on the real calendar.
  • A timestamp counts for a day when its first 10 characters equal that day written as YYYY-MM-DD. Only the first 10 characters matter, whatever follows them.
  • A timestamp shorter than 10 characters, or whose first 10 characters are not a day in the window, counts for nothing.

Examples

daily_signup_counts(timestamps: list[str], end_day: str) -> list[int]
Example 1
Inputdaily_signup_counts(["2026-06-20 09:00:00", "2026-06-20T23:59:59", "2026-06-18 12:00:00"], "2026-06-20")
Output[0, 0, 0, 0, 1, 0, 2]
Example 2
Inputdaily_signup_counts([], "2026-06-20")
Output[0, 0, 0, 0, 0, 0, 0]