Repository navigation
Preserve numeric locale when encoding Unix timestamps - #253
Merged
lelit merged 1 commit intoOct 31, 2026
Merged
Conversation
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.
Fixes #252.
Replace the two locale-switching Unix timestamp formatting blocks with
PyOS_double_to_string(timestamp, 'f', 6, ...). Keep the existing trailing-zero trimming and one fractional digit. Free the returned buffer after writing, and handle allocation failure.This avoids keeping
setlocale()'s borrowed result across anothersetlocale()call, and does not change the process-wide locale at all. The separate integer-only and time-object paths are unchanged. No independent timestamp-precision change is proposed.Tests cover date and datetime values through all six function/Encoder string and stream routes, checking both JSON output and the caller's later locale-aware formatting. The comma-decimal cases use an available German locale and skip if none is installed; C-locale controls always run. Added Unix date/datetime cases to the existing debug reference-leak tests.
Validation:
LOCPATH.--with-pydebug: 1,243 passed, 2 expected failures, including all reference-leak tests._staticdirectory warning.stubtest rapidjson: passed.For Python 3.10 only, I omitted the documentation dependency
sphinx==8.2.3from the test environment because it requires Python 3.11+. The pinned test dependencies were otherwise unchanged. The doctests and stub test above ran on Python 3.14, matching the current CI test version.