Skip to content

[6.x] Compare date query params against UTC-stored values - #19963

Open
nfourtythree wants to merge 1 commit into
6.xfrom
feature/6x-bugfix-query-where-date-param
Open

nfourtythree wants to merge 1 commit into
6.xfrom
feature/6x-bugfix-query-where-date-param

Conversation

@nfourtythree

Copy link
Copy Markdown
Contributor

Description

Query::whereDateParam() parsed the param in the system time zone and cast the Carbon instance straight to a string, but date columns are stored in UTC. So date filters were off by the time zone offset. With America/Los_Angeles, postDate('>= today') compared against 00:00:00 instead of 07:00:00. This affects every element query date param (postDate, before/after, dateCreated, lastLoginDate, Date fields, etc.) and the Filter panel's date condition rules.

The value now goes through Query::prepareDateForDb() after parsing. Strings without a zone are still read as system time, then converted to UTC.

The existing tests only passed because their factories wrote local-time values through Eloquent, which matched the bug. They now write via Query::prepareDateForDb(), as entry, asset and login saves do. QueryTest also gets a row at 11pm the previous day (local), plus a DateTime passed in another zone, to cover the offset.

@nfourtythree
nfourtythree requested review from riasvdv and a balanced review from Copilot October 13, 2026 17:30
@nfourtythree nfourtythree self-assigned this Oct 13, 2026

@riasvdv riasvdv 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.

I knew in my heart that I missed one or more of these 😅 let's hope it's one

@github-actions

Copy link
Copy Markdown

📚 Storybook previews

@craftcms/ui — open Storybook

No changed components detected in this Storybook.

resources/js — open Storybook

No changed components detected in this Storybook.

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

The focused normalization change is consistent with UTC persistence behavior and has appropriate regression coverage.

0 open findings

What changed in this PR

Normalizes date-query parameters to UTC before comparison with UTC-stored database values.

Changes:

  • Converts parsed date parameters using Query::prepareDateForDb().
  • Updates fixtures to persist UTC values.
  • Adds timezone-offset regression coverage.
File Description
src/​Support/​Query.php Normalizes date filters to UTC.
tests/​Feature/​Support/​QueryTest.php Covers local-day boundaries and zoned values.
tests/​Feature/​Element/​Queries/​Concerns/​User/​QueriesUserPropertiesTest.php Uses UTC login-date fixtures.
tests/​Feature/​Element/​Queries/​Concerns/​QueriesFieldsTest.php Uses UTC element timestamp fixtures.
tests/​Feature/​Element/​Queries/​Concerns/​Entry/​QueriesEntryDatesTest.php Uses UTC entry-date fixtures.

🧠 Review effort: Balanced


💡 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.

3 participants