Skip to content

Fix: Date.Value() timezone day-shift with PostgreSQL simple protocol#323

Open
dannyota wants to merge 1 commit intogo-gorm:masterfrom
dannyota:fix-date-timezone-value
Open

Fix: Date.Value() timezone day-shift with PostgreSQL simple protocol#323
dannyota wants to merge 1 commit intogo-gorm:masterfrom
dannyota:fix-date-timezone-value

Conversation

@dannyota
Copy link

@dannyota dannyota commented Feb 7, 2026

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Date.Value() now returns the date as a formatted string ("YYYY-MM-DD") instead of time.Time, preventing database drivers from applying timezone conversions that shift the date by a day.

Additionally:

  • Date.Scan() now handles time.Time, string, and []byte inputs 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 (DATE for mysql/postgres/sqlserver, date for sqlite).
  • Test updated to assert only date components (year/month/day), since Date is a calendar date and timezone is not part of its semantics.

User Case Description

When using datatypes.Date with PostgreSQL and PreferSimpleProtocol: true, dates were shifted back by one day. The pgx driver's text serialization applies a UTC conversion (UTC().Truncate(time.Microsecond)) on time.Time values, which causes a day-shift for timezones ahead of UTC.

Fixes #309.

- 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>
@dannyota dannyota force-pushed the fix-date-timezone-value branch from 55bbc9a to 43fa972 Compare February 7, 2026 14:02
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.

datatypes.Date sends wrong date when postgres.Config{ PreferSimpleProtocol: true }

1 participant

Comments