Repository navigation
fix: translate start_of_day/2 for time zone expressions, timestamps and dates - #293
Open
agustin2606 wants to merge 1 commit into
Open
agustin2606 wants to merge 1 commit into
agustin2606 wants to merge 1 commit into
Conversation
…nd dates The time zone was always pinned as a parameter, so a zone read from a column failed. Literal DateTime/Date values took the UTC date instead of the date in the time zone. `timestamp` and `date` values went through the formula meant for `timestamptz`, which applied the offset the wrong way.
2 of 7 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #289
start_of_day/2in the data layer now returns the same instant as Ash's own evaluation, for any time zone expression and fortimestamp,timestamptzand date values.Problem
Only a
timestamptzvalue with a literal time zone gave the right answer.Cause
In the
StartOfDayclause ofAshSql.Expr, the time zone was always pinned as a parameter, so an expression like a column was never translated. LiteralDateTime/Datevalues used the UTC date instead of the date in the time zone.timestampanddatevalues went throughtimezone(zone, date_trunc('day', timezone(zone, value))), which is only right fortimestamptz.Fix
DateTime/Datewith a literal zone: computed withAsh.Query.Function.StartOfDay.evaluate/1.utc_datetime/naive_datetime(cast totimestamp) are converted withtimezone('UTC', value)first; dates are cast totimestampand placed in the zone.timestamptzand untyped values (such asfragment("now()")) keep the existing SQL.Testing
ash_sql has no database tests, so the data layer tests are in ash-project/ash_postgres#931: 7 cases from the issue's table plus a date. Without this change 5 fail; with it, they and the rest of
calculation_test.exspass.Contributor checklist
Leave anything that you believe does not apply unchecked.