You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix naturaltime overflow for large durations - #456
naturaltime(timedelta(days=4_000_000)) raises OverflowError: date value out of range even though the duration is valid. The function constructs a calendar date that it does not need to format timedelta or numeric-seconds inputs.
Format those inputs directly, preserving timedelta sign, numeric rounding and the future argument. Add regressions for signed large durations, timedelta bounds and numeric future overrides. This concerns naturaltime; the adjacent #448 addresses precisedelta.
Validation: 751 tests passed, 112 translation tests skipped on Windows Python 3.13.14 using a proper editable install; full mypy and changed-file hooks pass. Independent review and 176 focused naturaltime tests pass. The all-files hook run has a local cached validate-pyproject missing-schema error; the same pinned validator installed directly validates pyproject.toml successfully.
Even a one-second duration can hit this calendar-arithmetic problem when when is at a datetime endpoint. I added a 25-line test-only companion on this branch, with no implementation changes.
Two useful guards: small durations should still format with datetime.min and datetime.max references, and the default tense should stay different for negative timedeltas versus numeric seconds. The eight cases cover both references and four signed input forms, without a frozen clock.
I ran the unchanged cases against the complete time, number, and i18n source modules on Windows/Python 3.14.4. All eight pass with this branch. On the base, four raise the expected OverflowError in _date_and_delta; the other four pass as controls.
This is component verification, not a package-build result: I used an import namespace to avoid inventing the Git snapshot's missing generated _version.py. The package root initializer, full suite, translations, aware-datetime paths, prek/mypy and version matrix weren't run. The offered file passes the repo-configured Ruff lint/format checks. From a properly installed checkout with the file added, the command is pytest -q tests/test_naturaltime_reference_bounds.py. Take whichever cases help.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
naturaltime(timedelta(days=4_000_000))raisesOverflowError: date value out of rangeeven though the duration is valid. The function constructs a calendar date that it does not need to format timedelta or numeric-seconds inputs.Format those inputs directly, preserving timedelta sign, numeric rounding and the
futureargument. Add regressions for signed large durations, timedelta bounds and numeric future overrides. This concernsnaturaltime; the adjacent #448 addressesprecisedelta.Validation: 751 tests passed, 112 translation tests skipped on Windows Python 3.13.14 using a proper editable install; full mypy and changed-file hooks pass. Independent review and 176 focused
naturaltimetests pass. The all-files hook run has a local cachedvalidate-pyprojectmissing-schema error; the same pinned validator installed directly validatespyproject.tomlsuccessfully.