Skip to content

Translate DateTime.Millisecond on SQLite without floating-point trunation - #39382

Merged
AndriySvyryd merged 1 commit into
dotnet:mainfrom
ilkertskn:fix/sqlite-datetime-millisecond-truncation
Oct 22, 2026
Merged

AndriySvyryd merged 1 commit into
dotnet:mainfrom
ilkertskn:fix/sqlite-datetime-millisecond-truncation

Conversation

@ilkertskn

Copy link
Copy Markdown
Contributor

The translation multiplied the REAL value of strftime('%f') by 1000 and took a truncating modulo, so values not exactly representable as a double lost a millisecond (e.g. 01.005 returned 4 instead of 5). Read the millisecond digits directly instead.

  • [ x] I've read the guidelines for contributing and seen the walkthrough
  • [ x] I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • [ x] The code builds and tests pass locally (also verified by our automated build checks)
  • [ x] Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

        Fixes #bugnumber
  • [x ] Tests for the changes have been added (for bug fixes / features)
  • [x ] Code follows the same patterns and style as existing code in this repo

…ation

The translation multiplied the REAL value of strftime('%f') by 1000 and
took a truncating modulo, so values not exactly representable as a double
lost a millisecond (e.g. 01.005 returned 4 instead of 5). Read the
millisecond digits directly instead.

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

No unresolved review issues were identified, and all readiness assessments approve the changes.

No open issues 🎉

What changed in this PR

This pull request fixes SQLite translation of DateTime.Millisecond by extracting millisecond digits directly from strftime('%f'), avoiding floating-point precision loss.

Changes:

  • Replaced floating-point multiplication and truncation with text-based extraction and integer conversion.
  • Updated affected SQLite SQL baselines.
  • Added regression coverage for values such as 1.005 seconds.
File Description
test/​EFCore.Sqlite.FunctionalTests/​Query/​Translations/​Temporal/​DateTimeTranslationsSqliteTest.cs Updates the temporal translation SQL baseline.
test/​EFCore.Sqlite.FunctionalTests/​Query/​NorthwindSelectQuerySqliteTest.cs Updates the millisecond projection SQL baseline.
test/​EFCore.Sqlite.FunctionalTests/​Query/​NorthwindMiscellaneousQuerySqliteTest.cs Updates composed-query baselines and adds floating-point precision regression coverage.
src/​EFCore.Sqlite.Core/​Query/​Internal/​Translators/​SqliteDateTimeMemberTranslator.cs Implements precise millisecond extraction for SQLite DateTime.Millisecond.

Review effort: Lite

@AndriySvyryd AndriySvyryd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution!

@AndriySvyryd
AndriySvyryd merged commit 37822a6 into dotnet:main Oct 22, 2026
19 of 20 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants