Skip to content

docs: sub-microsecond temporal text is three values, at most 1 µs apart - #175

Merged
CaffeinatedCoder merged 3 commits into
mainfrom
fix/sub-microsecond-literal
Oct 18, 2026
Merged

CaffeinatedCoder merged 3 commits into
mainfrom
fix/sub-microsecond-literal

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #126

Stacked on #173 (base fix/discrete-infinity-bound), which is stacked on #171.

Problem

A temporal literal with more than six fraction digits holds three values. The library keeps every digit its type can hold (100 ns BCL, 1 ns NodaTime). PostgreSQL reads the same text rounded half-to-even to the microsecond. The EF Core store writes it truncated toward 2000-01-01, as Npgsql binds a parameter. So [2026-01-01 10:00:00.1234567,) is .1234567 in memory, .123457 on the server read from that text, and .123456 stored.

The issue offered two options: round on parse, or document the divergence. Rounding on parse breaks a held promise. A value with sub-microsecond ticks (anything built from DateTime.Now) prints seven digits, and claim S08 says sub-second ticks survive the literal and JSON. With rounding, such a value would read back as a different value. Planting six-digit parsing fails 12 round-trip unit tests. It would also disagree with every parameter, which Npgsql truncates rather than rounds. The store rule (StoreTemporal / NodaStoreTemporal) already follows Npgsql. So this PR documents the divergence and pins it, and no behaviour changes.

Change

  • docs/architecture.md#domain-width-and-the-boundary: a Precision paragraph, with why parse doesn't round.
  • docs/serialization.md#dates-and-times-are-strict-iso-8601: the three values and the advice to round yourself when a value must equal the server's reading of its text (claim J37 quotes it). The NodaTime README says the same for nanoseconds.
  • DomainBoundaryDivergenceTests (integration) pins the three values against PostgreSQL 17, for DateTimeRange with seven digits (.1234567, .0000015) and LocalDateTimeRange with nine, and that the library's literal round-trips its digits.
  • LiteralCorpusProbeTests counts the sub-microsecond family on temporal kinds as this documented divergence. The 22 #126 candidates are removed.
  • Changelog: a Docs: line under 10.0.0 Fixed (root and core). No migration entry, since nothing changes.

Tests

  • Proven by planting: with IsoTemporal cutting the fraction to six digits, both new DomainBoundaryDivergenceTests rows fail ("the library keeps every 100 ns digit"), and 12 unit tests fail.
  • dotnet test: every project passes, both integration suites included (Docker, postgres:17).

🤖 Generated with Claude Code

#126 found that a temporal literal with more than six fraction digits
is one value in memory (100 ns BCL, 1 ns NodaTime), another on the
server reading the same text (rounded half-to-even to the microsecond),
and a third in the store (truncated toward 2000-01-01, as Npgsql binds).

Rounding on parse, the issue's first option, would break the library's
own round trip: a value with sub-microsecond ticks, anything built from
DateTime.Now, prints seven digits and would read back as a different
value (claim S08; 12 round-trip unit tests fail with it planted). It
would also disagree with every parameter, which Npgsql truncates. So
the divergence is documented, the issue's second option:
architecture.md#domain-width-and-the-boundary (Precision),
serialization.md (claim J37) and the NodaTime README.

DomainBoundaryDivergenceTests pins the three values against PostgreSQL
for DateTimeRange (seven digits) and LocalDateTimeRange (nine), and
that the library's literal round-trips them; LiteralCorpusProbeTests
counts the sub-microsecond family as that documented divergence, so the
22 #126 candidates go. Planting six-digit parsing fails the new test.

Closes #126

Found-By: OT
Defect-Class: LIT

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 10.0.0 milestone Oct 18, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working silent Answers wrongly without throwing — fixes go in the next major, never deferred found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) package/nodatime Affects CodoMetis.ValueRanges.NodaTime package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL area/literals Parse, TryParse and formatting package/core Affects CodoMetis.ValueRanges severity/low Cosmetic, message or documentation-level difference stacked Base is another open PR; merge in order, CI does not run until it targets main labels Oct 18, 2026
…iteral

# Conflicts:
#	docs/architecture.md
#	test/CodoMetis.ValueRanges.EFCore.PostgreSQL.IntegrationTests/DomainBoundaryDivergenceTests.cs
Base automatically changed from fix/discrete-infinity-bound to main October 18, 2026 14:39
@CaffeinatedCoder CaffeinatedCoder removed the stacked Base is another open PR; merge in order, CI does not run until it targets main label Oct 18, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit b9fedf1 into main Oct 18, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/sub-microsecond-literal branch October 18, 2026 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/literals Parse, TryParse and formatting bug Something isn't working found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) package/core Affects CodoMetis.ValueRanges package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/nodatime Affects CodoMetis.ValueRanges.NodaTime severity/low Cosmetic, message or documentation-level difference silent Answers wrongly without throwing — fixes go in the next major, never deferred

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A temporal literal with sub-microsecond digits is a different value than PostgreSQL reads from the same text

1 participant