⚡ Sangsakala Proxy 🏠 Home
Skip to content

Preserve numeric locale when encoding Unix timestamps - #253

Merged
lelit merged 1 commit into
python-rapidjson:masterfrom
parijat1222q:fix/unix-time-numeric-locale
Oct 31, 2026
Merged

lelit merged 1 commit into
python-rapidjson:masterfrom
parijat1222q:fix/unix-time-numeric-locale

Conversation

@parijat1222q

Copy link
Copy Markdown
Contributor

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 another setlocale() 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:

  • Original master: 12 comma-locale regressions fail; 12 C-locale controls pass.
  • Fixed CPython 3.14.8: 1,224 passed, 19 non-debug skips, 2 expected failures. All 24 locale regression/control cases ran, with a real libc comma-decimal locale enabled through a local LOCPATH.
  • CPython 3.14.8 --with-pydebug: 1,243 passed, 2 expected failures, including all reference-leak tests.
  • CPython 3.10/3.11: 1,230 passed, 19 skipped, 2 expected failures each. CPython 3.12/3.13/3.15: 1,224 passed, 19 skipped, 2 expected failures each.
  • Installed-package documentation doctests: 274 passed. Sphinx reports the existing missing _static directory warning.
  • Installed-package stubtest rapidjson: passed.

For Python 3.10 only, I omitted the documentation dependency sphinx==8.2.3 from 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.

@lelit
lelit merged commit 35b6987 into python-rapidjson:master Oct 31, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DM_UNIX_TIME serialization changes the caller numeric locale

2 participants