Skip to content

fix(day): render unix timestamps in the time zone the caller asked for - #1659

Open
NUAAwqy wants to merge 1 commit into
apache:mainfrom
NUAAwqy:fix/day-format-ignores-timezone
Open

NUAAwqy wants to merge 1 commit into
apache:mainfrom
NUAAwqy:fix/day-format-ignores-timezone

Conversation

@NUAAwqy

@NUAAwqy NUAAwqy commented Oct 30, 2026

Copy link
Copy Markdown

Fixes #

Proposed Changes

  • pkg/day.Format now applies the tz argument it already loaded with time.Time.In; before, time.LoadLocation(tz) was called and its result dropped, so every rendered date was the server's local zone.
  • An empty or unresolvable zone keeps the previous local-time behaviour, so nothing shifts when the site time zone is missing.
  • Adds a table-driven TestFormatTimezone (UTC / Tokyo / New York / Kolkata / Los Angeles) plus a fallback test.

Additional Info

Reproducer: Format(1700000000, "YYYY-MM-DD HH:mm", "Asia/Tokyo") returned 2023-11-14 22:13
instead of 2023-11-15 07:13. This is the helper behind the translatorTimeFormat email/UI
templates and behind the "suspended until" text that passes "UTC" explicitly
(internal/schema/user_schema.go:202). No new dependency; go mod tidy and
golangci-lint v2.6.2 (make lint) are clean.

day.Format takes an IANA time zone name, loads it and then throws the
result away: the returned string was always produced in the server local
zone. Every caller passes the zone explicitly -- the email/HTML templates
via the timeFormat helpers, and schema/user_schema.go even hardcodes
"UTC" for the suspended-until notice -- so dates were shown shifted
whenever the container zone differed from the configured one.

Apply the loaded location with time.Time.In, and keep the previous local
behaviour when the zone is empty or unknown so that a bad value cannot
silently shift an instant.

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.

1 participant