Fix: Date.Value() timezone day-shift with PostgreSQL simple protocol#323
Open
dannyota wants to merge 1 commit intogo-gorm:masterfrom
Open
Fix: Date.Value() timezone day-shift with PostgreSQL simple protocol#323dannyota wants to merge 1 commit intogo-gorm:masterfrom
dannyota wants to merge 1 commit intogo-gorm:masterfrom
Conversation
- Date.Value() now returns "YYYY-MM-DD" string instead of time.Time to prevent database drivers from applying timezone conversions that shift the date by a day. - Date.Scan() handles time.Time, string, and []byte inputs for compatibility with all database drivers. - Add GormDBDataType() for explicit provider column types. - Test asserts date components only (year/month/day), not timezone. Fixes go-gorm#309 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
55bbc9a to
43fa972
Compare
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.
What did this pull request do?
Date.Value()now returns the date as a formatted string ("YYYY-MM-DD") instead oftime.Time, preventing database drivers from applying timezone conversions that shift the date by a day.Additionally:
Date.Scan()now handlestime.Time,string, and[]byteinputs for compatibility with all database drivers. Values scanned from strings are always parsed as UTC.Date.GormDBDataType()added to return explicit column types per dialect (DATEfor mysql/postgres/sqlserver,datefor sqlite).Dateis a calendar date and timezone is not part of its semantics.User Case Description
When using
datatypes.Datewith PostgreSQL andPreferSimpleProtocol: true, dates were shifted back by one day. The pgx driver's text serialization applies a UTC conversion (UTC().Truncate(time.Microsecond)) ontime.Timevalues, which causes a day-shift for timezones ahead of UTC.Fixes #309.