Fix the inclusive day count for billing
Your task
A legacy billing helper subtracted two timestamps and divided by a day's milliseconds. An AI described it as an inclusive day count, but it returned 2 for January 1 to January 3, and daylight saving days broke it further. The replacement works on calendar dates only and counts both endpoints.
An assistant wrote inclusive_billing_days(start_date, end_date). It is in the editor. It has a bug. Find it and fix it.
Input and output:
start_date,end_date: dates as"YYYY-MM-DD"strings.- Return the number of billed days, counting both endpoints.
Rules the tests check:
- Each date must be exactly 10 characters: 4 digits,
-, 2 digits,-, 2 digits. Otherwise return 0. - Each year must be 1 or more, each month 1 to 12 and each day 1 to 31. Otherwise return 0.
- A day past the end of its month counts on into the next month, so
2026-04-31is the same day as2026-05-01. - Use the Gregorian calendar. A leap year is divisible by 4, except a year divisible by 100 is not a leap year unless it is also divisible by 400. So 2000 is a leap year, and 1900 and 2100 are not.
- If the end date is before the start date, return 0. Otherwise return the number of days from start to end, plus 1.
Examples
inclusive_billing_days(start_date: str, end_date: str) -> intExample 1
Input
inclusive_billing_days("2026-01-01", "2026-01-03")Output
3Example 2
Input
inclusive_billing_days("2026-01-01", "2026-01-01")Output
1