Skip to content

Truncate sub-microsecond ticks when formatting TimeSpan as interval - #3932

Open
AtakanUk wants to merge 1 commit into
npgsql:mainfrom
AtakanUk:fix-interval-sub-microsecond
Open

AtakanUk wants to merge 1 commit into
npgsql:mainfrom
AtakanUk:fix-interval-sub-microsecond

Conversation

@AtakanUk

@AtakanUk AtakanUk commented Oct 4, 2026

Copy link
Copy Markdown

Fixes #3926. FormatTimeSpanAsInterval decided whether to emit a fractional part using tick precision, but formatted it with microsecond precision (FFFFFF). This produced a trailing . for values with only sub-microsecond ticks. The value is now truncated to microseconds before formatting, which matches how FFFFFF already truncates. Added a JSON round-trip test covering the cases from the issue.

Copilot AI balanced review requested due to automatic review settings October 4, 2026 16:10

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 review overview

🟢 Approval recommended

The fix correctly handles positive and negative sub-microsecond values with comprehensive regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes invalid JSON interval strings by truncating TimeSpan values to PostgreSQL’s microsecond precision before formatting.

Changes:

  • Truncates sub-microsecond ticks during interval formatting.
  • Adds SQL literal and JSON round-trip regression coverage, including negative values.
File Description
src/​EFCore.PG/​Storage/​Internal/​Mapping/​NpgsqlIntervalTypeMapping.cs Normalizes intervals to microsecond precision before formatting.
test/​EFCore.PG.Tests/​Storage/​NpgsqlTypeMappingTest.cs Tests valid serialization and round-tripping across precision boundaries.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

TimeSpan with sub-microsecond ticks is serialized to an invalid JSON interval string

2 participants