Skip to content

Fix month/year range parsing overflow on month-end dates#539

Merged
arran4 merged 1 commit intomainfrom
codex/add-edge-case-tests-and-fix-issues
Feb 20, 2026
Merged

Fix month/year range parsing overflow on month-end dates#539
arran4 merged 1 commit intomainfrom
codex/add-edge-case-tests-and-fix-issues

Conversation

@arran4
Copy link
Owner

@arran4 arran4 commented Feb 20, 2026

Motivation

  • TimeParser.parseRange produced incorrect start dates for month/year ranges when the current day did not exist in the target month (e.g., subtracting one month from Mar 31), causing overflows instead of clamping to the last valid day.
  • The code needed to preserve time-of-day while safely handling month and year rollovers and leap-day behavior.
  • An edge-case regression test was added to capture these month-end and leap-year scenarios.

Description

  • Added helper functions _subtractMonths, _subtractYears, and _daysInMonth to lib/utils/time_parser.dart to centralize correct date arithmetic and clamp day-of-month to the last valid day of the target month.
  • Replaced ad-hoc DateTime arithmetic in both the duration-based (last N month/year) and phrase-based (last month, last year) branches of parseRange to use the new helpers and preserve time components.
  • Added an edge-case test should clamp day for month and year range phrases in test/time_parser_test.dart that verifies correct clamping for last 1 month and last 1 year with preserved time-of-day.

Testing

  • Attempted dart format . but it failed in this environment because dart is not installed, so formatting could not be verified here.
  • Attempted flutter analyze but it failed in this environment because flutter is not installed, so static analysis could not be run here.
  • Attempted dart test . but it failed in this environment because dart is not installed, so the new unit test was not executed here; CI should run the test suite and is expected to pass with the changes.

Codex Task

@github-actions github-actions bot mentioned this pull request Feb 20, 2026
@arran4 arran4 merged commit 10b6704 into main Feb 20, 2026
4 checks passed
@arran4 arran4 deleted the codex/add-edge-case-tests-and-fix-issues branch February 20, 2026 01:25
arran4 added a commit that referenced this pull request Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant