Skip to content

Format NpgsqlRange<T> bounds culture-invariantly in ToString and Parse - #6738

Open
EnesKartal wants to merge 1 commit into
npgsql:mainfrom
EnesKartal:fix/range-tostring-culture-6730
Open

EnesKartal wants to merge 1 commit into
npgsql:mainfrom
EnesKartal:fix/range-tostring-culture-6730

Conversation

@EnesKartal

Copy link
Copy Markdown

NpgsqlRange<T>.ToString() formatted bounds with the current culture, so under de-DE a numrange printed as [1,5,2,25), and a daterange printed as [01.07.2026,04.07.2026], which PostgreSQL reads as other dates. This is what EF Core's ToQueryString() and parameter logs show (details in the issue).

Bounds are now formatted with the invariant culture, and DateTime, DateTimeOffset, DateOnly and TimeOnly bounds use the round-trip format (O).

There was no reply on the issue about the date format, so these behavior changes are worth a look. I'm happy to narrow the PR if you'd rather keep any of them out:

  • Date/time text changes under every culture. For example, under the invariant culture [07/01/2026,07/04/2026] becomes [2026-07-01,2026-07-04], and DateTime bounds keep their fraction digits. Anything that depends on the old text will see a difference.
  • Parse now uses the invariant culture too. I changed it so ToString output round-trips under any culture, which goes beyond what the issue asks for. As a result, Parse no longer accepts culture-specific text such as [1,5,2,25) under de-DE.
  • UTC DateTime bounds come back as local time. Round-tripping through ToString and Parse keeps the instant, but Kind changes from Utc to Local, because DateTimeConverter converts the Z value to local time.

Verification: RangeTests on net10.0 against PostgreSQL 18 (92 passed, 1 skipped), with this commit rebased on current main. I didn't run the rest of the suite. The new tests run under de-DE and cover decimal, DateTime, DateTimeOffset, DateOnly and TimeOnly.

Fixes #6730

Copilot AI balanced review requested due to automatic review settings November 1, 2026 22:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

This branch has not been deployed

No deployments
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.

NpgsqlRange<T>.ToString() formats bounds with the current culture, so EF Core's ToQueryString() and parameter logs show range text PostgreSQL misreads

2 participants