Back to results · bugfix/ergo-run-1/REPORT.md
# Bug report investigation
All eight reports were reproduced with `PYTHONPATH=src`. Seven turned out to be
real bugs; report 4 describes documented, intentional behavior.
## Report 1: Month-end payment date is a day early — REAL BUG
**Symptom:** `date(2023, 12, 31) + relativedelta(months=2)` gave `2024-02-28`
instead of `2024-02-29`.
**Cause:** In `relativedelta.__add__` (`src/dateutil/relativedelta.py`), the
number of days in the target month was computed with
`calendar.monthrange(other.year, month)` — using the *original* date's year
instead of the computed target `year`. When adding months crosses into a
different leap year (2023 → 2024), February was clamped to 28 days even though
the target year 2024 has 29. This also caused a `ValueError: day is out of
range for month` in cases like `date(2024, 12, 31) + relativedelta(months=2)`.
**Fix:** Use the computed target `year`:
`calendar.monthrange(year, month)[1]`.
## Report 2: Midnight bookings show up at lunchtime — REAL BUG
**Symptom:** `parse("12:15 AM")` produced `12:15:00` (noon); `"12:15 PM"`
also produced `12:15`.
**Cause:** `parser._adjust_ampm()` (`src/dateutil/parser/_parser.py`) only
added 12 hours when `hour < 12 and ampm == 1` (PM). It never handled the
12-hour-clock wrap for 12 AM, so hour 12 stayed at 12 for AM.
**Fix:** Handle the 12 o'clock case explicitly: 12 AM becomes 0 (midnight),
while 12 PM stays 12. (`if hour < 12 and ampm == 1: hour += 12` plus
`elif hour == 12 and ampm == 0: hour = 0`.)
## Report 3: "Last Friday of the month" meeting is a week early — REAL BUG
**Symptom:** `rrule(MONTHLY, byweekday=FR(-1))` from January 2026 yielded
23 January, 20 February, 20 March instead of 30 January, 27 February,
27 March.
**Cause:** In `_iterinfo.rebuild()` (`src/dateutil/rrule.py`), the negative
nth-weekday branch computed the starting day as `i = last + n*7`. Since
`last` is already the final day of the month, multiplying `n=-1` by 7 moves
a full week *before* the last day, so the result lands one week early.
The docstring examples for `MO(-2)` and `(SU(1), SU(-1))` were affected too.
**Fix:** Start from the last day for `n=-1`:
`i = last + (n + 1)*7`.
## Report 4: Adding one month to 31 January gives the wrong date — NOT A BUG
**Symptom:** `date(2026, 1, 31) + relativedelta(months=1)` gives
`2026-02-28`.
**Why this is correct:** The documented contract of `relativedelta`
(`docs/relativedelta.rst`) is: "If the result falls on a day after the last one
of the month, the last day of the month is used instead." January has no
"31st + 1 month" counterpart in February, so the result is clamped to
28 February 2026. The customer's proposed result (3 March) would be ordinary
28-day addition, not calendar-month addition, and would contradict the
library's documented semantics and the analogous `date(2003, 1, 31) +
relativedelta(months=+1) == date(2003, 2, 28)` example.
**Fix:** None. No code changed.
## Report 5: Daily reminder stops one day early — REAL BUG
**Symptom:** `rrule(DAILY, dtstart=2026-03-08, until=2026-03-10)` yielded
8 and 9 March only; 10 March was missing.
**Cause:** In `rrule._iter()` (`src/dateutil/rrule.py`), the non-`bysetpos`
branch stopped when `res >= until`, excluding an occurrence exactly equal
to `until`. The `until` documentation says: "The last recurrence in the rule
is the greatest datetime that is less than or equal to the value specified
in the `until` parameter." The `bysetpos` branch already used `>`, so the
two paths were inconsistent.
**Fix:** Change the comparison to `res > until`, making `until` inclusive
as documented. Verified against the docs' "Daily until December 24, 1997"
example (still ends 23 December because occurrences are at 09:00, after
midnight on the 24th).
## Report 6: Orthodox Easter is on the wrong day — REAL BUG
**Symptom:** `easter(2025, EASTER_ORTHODOX)` gave 21 April instead of
20 April; `easter(2026, ...)` gave 13 April instead of 12 April.
**Cause:** In `easter()` (`src/dateutil/easter.py`), the Julian→Gregorian
conversion for the Orthodox method used `... - (y//100 - 16)//5`. The
standard Meeus Julian algorithm uses integer division by 4 here; dividing
by 5 over-corrects by a day in many years.
**Fix:** Change `//5` to `//4`:
`e = e + y//100 - 16 - (y//100 - 16)//4`.
Verified against an independent Julian computus + Julian-to-Gregorian
conversion for every year 1800–2199 (0 mismatches) and against published
Orthodox Easter dates 2018–2027. Western Easter and the raw Julian method
are unaffected.
## Report 7: Week numbers give dates in the wrong week — REAL BUG
**Symptom:** `isoparse("2021-W01-1")` gave `2020-12-28` instead of
`2021-01-04`; other week dates (e.g. `2026-W10-3`) happened to work.
**Cause:** `isoparser._calculate_weekdate()`
(`src/dateutil/parser/isoparser.py`) derived ISO week 1 from the Monday of
the week containing 1 January. Under ISO-8601, week 1 is the week containing
4 January (the first Thursday), so whenever 1 January falls late in the week
(Friday–Sunday) the computed week is one week too early. In 2021,
1 January is a Friday, hence the seven-day error; in 2026 it is a Thursday,
which is why that case looked fine.
**Fix:** Anchor the calculation on 4 January:
`jan_4 = date(year, 1, 4)` and subtract `jan_4.isocalendar()[2] - 1` days.
Verified by a round-trip sweep of every valid ISO week/day for years
1990–2030 against `date.fromisocalendar()` (all matched). Week 53 in years
that have no ISO week 53 remains accepted (pre-existing permissive behavior,
not part of this report).
## Report 8: Wrong time zone at the moment the clocks change — REAL BUG
**Symptom:** With `tz.gettz("America/New_York")`, 03:00 on 8 March 2026 was
reported as EST (UTC-5) instead of EDT (UTC-4); 02:00 on 1 November 2026 was
reported as EDT instead of EST. One minute past the transition was correct.
**Cause:** `tzfile._find_trans()` (`src/dateutil/tz/_tzfile.py`) located the
active transition with `bisect.bisect_left(lt, ts) - 1`. `bisect_left`
returns the index of the transition exactly equal to `ts`, so subtracting 1
selected the *previous* offset for the exact transition instant, making the
new offset take effect one second late.
**Fix:** Use `bisect.bisect_right(lt, ts) - 1`, so a transition whose local
time equals `ts` is included and the new offset applies exactly at the
transition instant. Fold behavior, imaginary-time detection
(`resolve_imaginary`), ambiguity detection, and UTC conversion were
regression-checked and remain consistent with `zoneinfo`.
## Verification
A standalone check script (removed after use) exercised all eight reports,
the doc examples for `relativedelta`, `rrule` (`FR(1)`, `MO(-2)`,
`SU(1)/SU(-1)`, `bysetpos`, `until`, `count`), parser AM/PM variants, ISO
week round-trips, and timezone transitions including Lord Howe's 30-minute
DST shifts. All checks passed. `git diff` contains only the six source
changes described above; no test files or other files were modified.