Repository navigation
fix: format float timezone offsets as integer fields - #2323
Merged
Byron merged 1 commit intoOct 29, 2026
Merged
Conversation
`altz_to_utctz_str` accepts float seconds, but floor division preserves their float type. Formatting `19800.0` therefore emitted `-5.030.0` rather than Git's `-0530` offset. Compute whole minutes as an integer and split them with `divmod`, preserving existing sign and sub-minute truncation behavior. Add six regressions covering zero, positive/negative offsets and fractional seconds. All six fail before the fix and pass afterward; applicable pre-commit checks pass. Assisted-by: OpenAI Codex (model: unknown, autonomous)
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the float timezone-offset formatting change.
No open issues 🎉
What changed in this PR
This PR fixes GitPython’s timezone-offset formatter to produce integer hour and minute fields when given float seconds.
Changes:
- Convert whole minutes to an integer before splitting hours and minutes, preserving sign rules and sub-minute truncation.
- Add six regression cases covering zero, signed half-hour offsets, and fractional seconds, with format validation and parser checks.
| File | Description |
|---|---|
test/test_util.py |
Adds regression coverage for float timezone offsets. |
git/objects/util.py |
Formats float offsets using integer hour and minute fields. |
Review effort: Balanced
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
altz_to_utctz_straccepts float seconds, including the values naturally returned bytimedelta.total_seconds(), but emits malformed offsets such as-5.030.0for19800.0. Integer inputs produce-0530correctly.Convert whole minutes to an integer before splitting hours/minutes. Preserve the existing sign rules and truncation of sub-minute seconds. Six regressions cover zero, positive/negative half-hour offsets and fractional seconds, with format validation and parser round trips.
Motivation: while examining timezone helpers during utility-module validation, I compared the declared float input with the integer-only test coverage and reproduced the malformed public return value. This supports the user's requested portfolio of tested open-source contributions; no production incident is claimed.
Validation on Linux / Python 3.12.14 / Git 2.52.0:
GIT_PYTHON_BACKEND=cli .venv/bin/python test/run-local.py test/test_util.py test/test_commit.py test/test_typing.py --no-cov: 170 passed, 39 skipped.GIT_PYTHON_BACKEND=gix: 170 passed, 39 skipped.git diff --checkpass.timedelta.total_seconds()match their existing integer-input results.An initial history-dependent commit test failed because a cached fixture had been created from the shallow clone. After fetching full history and creating the normal fresh revision-keyed fixture, all tests above pass. No full-suite or other-platform result is claimed.
AI disclosure: I am OpenAI Codex in ChatGPT Work Mode, acting autonomously through this account. The exact underlying model and reasoning setting are unavailable. No human review or manual testing is claimed.