Skip to content

fix: use locale-independent digits in temporal toString - #107

Merged
sshanks-kx merged 1 commit into
KxSystems:masterfrom
belowzeroff:fix/tostring-locale-independence
Jul 31, 2026
Merged

fix: use locale-independent digits in temporal toString#107
sshanks-kx merged 1 commit into
KxSystems:masterfrom
belowzeroff:fix/tostring-locale-independence

Conversation

@belowzeroff

Copy link
Copy Markdown
Contributor

Summary

Month, Minute, Second and Timespan render their value through DecimalFormat constructed with the JVM default locale. Under locales whose default digits are not 09 (Arabic, Persian, Bengali, …) toString() emits non-ASCII digits, corrupting the canonical textual form of these kdb+ temporal atoms:

default locale Month(22) expected
en-US 2001-11 2001-11
ar-EG ٢٠٠١-١١ 2001-11
fa-IR ۲۰۰۱-۱۱ 2001-11
bn-IN ২০০১-১১ 2001-11

The same affects Minute (٠٠:٢٢), Second and Timespan. This breaks logging, display, CSV export and any downstream parsing/comparison of these strings for users running under such a locale.

Change

Format the helpers i2() / i9() (used by all four temporal toString() methods) with DecimalFormatSymbols.getInstance(Locale.ROOT), so the output is always ASCII regardless of the JVM default locale. Formatting semantics are otherwise unchanged.

Testing

Added testTemporalToStringLocaleIndependent, which pins the rendered digits under an Arabic-Indic locale (restoring the previous default afterwards). Full suite green (86 tests, no regressions).

Month, Minute, Second and Timespan render their value via DecimalFormat with
the JVM default locale, so under locales whose default digits are not 0-9
(Arabic, Persian, Bengali, ...) toString emitted non-ASCII digits, e.g.
Month(22) -> "٢٠٠١-١١" instead of "2001-11". These are the canonical textual
forms of kdb+ temporal atoms and must always use ASCII digits.

Format i2()/i9() with DecimalFormatSymbols for Locale.ROOT so the output is
identical regardless of the JVM default locale. Add a test that pins the
digits under an Arabic-Indic locale.
@sshanks-kx
sshanks-kx merged commit f5b5ffe into KxSystems:master Jul 31, 2026
1 check 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.

2 participants