Back to results · bugfix/opus-5-5-run-1/REPORT.md
# Bug report investigation
Seven of the eight reports were real bugs and are fixed. Report 4 is not a bug, so I did not change any code for it.
| # | Report | Real bug? | File changed |
|---|---|---|---|
| 1 | Month-end payment a day early | Yes | `src/dateutil/relativedelta.py` |
| 2 | 12:15 AM read as 12:15 PM | Yes | `src/dateutil/parser/_parser.py` |
| 3 | "Last Friday" a week early | Yes | `src/dateutil/rrule.py` |
| 4 | 31 Jan + 1 month = 28 Feb | **No** | none |
| 5 | Daily rule drops the `until` day | Yes | `src/dateutil/rrule.py` |
| 6 | Orthodox Easter a day late | Yes | `src/dateutil/easter.py` |
| 7 | ISO week dates a week early | Yes | `src/dateutil/parser/isoparser.py` |
| 8 | Wrong zone at the exact moment clocks change | Yes | `src/dateutil/tz/_tzfile.py` |
## Report 1: Month-end payment date is a day early (real bug)
**Cause:** In `relativedelta.__add__`, the date is limited to the last day of the target month with `calendar.monthrange(other.year, month)`. That uses the **start date's year**, not the target year. So 2023-12-31 + 2 months looked up February **2023** (28 days) instead of February 2024 (29 days). The error only shows up when adding months moves the date into a different year.
**Fix:** Use the target year: `calendar.monthrange(year, month)`.
## Report 2: "12:15 AM" read as 12:15 PM (real bug)
**Cause:** `parser._adjust_ampm` added 12 hours for PM times before noon, but it never turned 12 AM into hour 0.
**Fix:** Added `elif hour == 12 and ampm == 0: hour = 0`. Now "12:15 AM" is 00:15, "12 AM" is 00:00, and "12:15 PM" and "1:15 AM" give the same results as before.
## Report 3: "Last Friday of the month" a week early (real bug)
**Cause:** In `rrule`'s `_iterinfo.rebuild`, the starting point for negative nth weekdays (such as `FR(-1)`) was `last + n*7`. For n = -1 that starts a week before the end of the month, so the rule picked the second-to-last Friday, and every other negative n was off by one week too.
**Fix:** Changed it to `last + (n+1)*7`, which matches the formula used for positive n. I checked this against a brute-force calculation for n = ±1 to ±4 and every weekday, for both MONTHLY and YEARLY rules.
## Report 4: One month after 31 January should be 3 March (not a bug)
`relativedelta(months=+1)` is documented to move to the same day of the next month. If that day doesn't exist, it uses the last day of the month instead of rolling over into the next month. So 2026-01-31 + 1 month = 2026-02-28 is the intended result. No change. Someone who wants "31 days later" should use `relativedelta(days=+31)` or `timedelta`.
## Report 5: Daily reminder stops one day early (real bug)
**Cause:** `until` is inclusive (RFC 5545, and the docs say so), and the `bysetpos` code path treats it that way with `res > until`. The normal code path used `res >= until`, so an occurrence falling exactly on `until` was dropped.
**Fix:** Changed it to `res > until`. Occurrences after `until` are still excluded.
## Report 6: Orthodox Easter a day late (real bug)
**Cause:** In `easter()`, method 2 (Orthodox) converts the Julian date to the Gregorian calendar by adding the gap between the two calendars: `10 + y//100 - 16 - (y//100 - 16)//5`. The divisor should be 4, because the Gregorian calendar skips 3 leap days in every 400 years. With 5, the result was one day too late for 2000–2099 (and wrong in other centuries too).
**Fix:** Changed `//5` to `//4`. Results now: 2025-04-20, 2026-04-12, 2024-05-05, 2023-04-16, 2000-04-30. All of these are Sundays and match the published Orthodox Easter dates. Western and Julian Easter are unchanged.
## Report 7: ISO week dates in the wrong week (real bug)
**Cause:** `isoparser._calculate_weekdate` found ISO week 1 by taking the Monday of the week that contains **1 January**. Under ISO 8601, week 1 is the week that contains **4 January**. The two are the same when 1 January falls on Monday through Thursday (which is why 2026-W10-3 worked). When 1 January falls on Friday, Saturday or Sunday (like 2021), every week was one week early.
**Fix:** Count from 4 January instead. I checked that `isoparse("%Y-W%W-%d")` round-trips through `date.isocalendar()` for 1990–2039.
## Report 8: Wrong time zone at the exact moment clocks change (real bug)
**Cause:** `tzfile._find_trans` looked up the local time in the list of transition times with `bisect.bisect_left(...) - 1`. When a time is exactly equal to a transition, that picks the period *before* the transition. So 03:00 on 8 March 2026 (the first valid time after the spring-forward gap) was shown as EST, and 02:00 on 1 November 2026 was shown as EDT.
**Fix:** Use `bisect.bisect_right(...) - 1`, so a transition takes effect at its own moment. The UTC-to-local path (`fromutc`) already used `bisect_right`. I checked the gap and fold times in New York for 2026 (from the transition table) and 2045 (from the TZ rule string), and round-tripped UTC → local → UTC every 15 minutes across both 2026 transitions.
## How I checked
I wrote my own test scripts (run with `PYTHONPATH=src`). They reproduce each report and compare the results against brute-force calculations:
- `relativedelta` month arithmetic for every month-end start date from 1999 to 2029, adding from -25 to +25 months
- nth-weekday rules
- ISO week round-trips
- Orthodox Easter always landing on a Sunday
- 12-hour clock parsing edge cases
- time zone round-trips
All of them pass.