Skip to content

Fix NodaTime BCE year extraction - #4110

Closed
roji wants to merge 1 commit into
mainfrom
roji-nodatime-bce-year-fix
Closed

roji wants to merge 1 commit into
mainfrom
roji-nodatime-bce-year-fix

Conversation

@roji

@roji roji commented Oct 25, 2026

Copy link
Copy Markdown
Member

PostgreSQL has no year zero, whereas NodaTime uses astronomical year numbering. Correct date/time .Year extraction with a CASE that adds one to negative PostgreSQL years, so new LocalDate(-100, 12, 31).Year returns -100 and ISO year zero returns 0.

Applies to LocalDate, LocalDateTime, and ZonedDateTime, including explicit time-zone conversion. Period.Years remains unchanged.

Adds sync/async regression coverage for years -100, 0, and 1, plus negative interval years, and updates the existing positive-year SQL baselines. All 233 NodaTime translation tests pass using an isolated PostgreSQL testcontainer.

Partially addresses #4089. This PR is based directly on main and deliberately excludes the LocalDate subtraction / age() change in #4109, allowing this fix to be backported independently.

Correct negative PostgreSQL date/time years to NodaTime astronomical numbering without changing Period.Years or LocalDate subtraction.

Partially addresses #4089.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 25, 2026 09:09
@roji

roji commented Oct 25, 2026

Copy link
Copy Markdown
Member Author

Folded back into #4109

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

Static review found no blocking issues in the narrowly scoped correction or its regression coverage; tests were not independently executed.

No open issues 🎉

What changed in this PR

Corrects NodaTime calendar-year extraction to match astronomical year numbering, including BCE dates and year zero. This addresses the year-extraction portion of #4089 independently of the subtraction change in #4109.

Changes:

  • Adds one to negative PostgreSQL calendar years while leaving Period.Years unchanged.
  • Adds sync/async regression coverage for years -100, 0, and 1, including explicit time-zone conversion and negative interval years.
  • Updates existing positive-year SQL baselines.
File Description
test/​EFCore.PG.FunctionalTests/​Query/​Translations/​NodaTime/​ZonedDateTimeTranslationsTest.cs Tests astronomical years in UTC and an explicit time zone; updates SQL expectations.
test/​EFCore.PG.FunctionalTests/​Query/​Translations/​NodaTime/​PeriodTranslationsTest.cs Verifies negative interval years remain unchanged.
test/​EFCore.PG.FunctionalTests/​Query/​Translations/​NodaTime/​LocalDateTranslationsTest.cs Tests astronomical date years and updates SQL expectations.
test/​EFCore.PG.FunctionalTests/​Query/​Translations/​NodaTime/​LocalDateTimeTranslationsTest.cs Tests astronomical timestamp years and updates SQL expectations.
src/​EFCore.PG.NodaTime/​Query/​Internal/​NpgsqlNodaTimeMemberTranslatorPlugin.cs Corrects calendar-year extraction without changing interval-year extraction.

Review effort: Balanced

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