Skip to content

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

Open
NUAAwqy wants to merge 2 commits into
apache:devfrom
NUAAwqy:fix/day-format-ignores-timezone
Open

NUAAwqy wants to merge 2 commits into
apache:devfrom
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.
@LinkinStars
LinkinStars changed the base branch from main to dev November 3, 2026 08:58
@LinkinStars

Copy link
Copy Markdown
Member

Thanks for the fix. Could you update the existing TestFormat expectation to use UTC? It passes "UTC" to Format but calculates the expected value in the host’s local zone, so this change makes the test fail when the test host is outside UTC.

@LinkinStars LinkinStars self-assigned this Nov 3, 2026
The test passes "UTC" to Format but calculated the expected value with
time.Local, so it failed on hosts outside UTC (as requested by @LinkinStars).
@NUAAwqy

NUAAwqy commented Nov 4, 2026

Copy link
Copy Markdown
Author

Done — the existing TestFormat expectation is now computed in UTC (time.Unix(sec, 0).UTC().Format(...)) instead of the host's local zone, so the test no longer depends on the test host's TZ. The unknown-zone fallback test keeps using time.Local on purpose, since that is the behavior it asserts. 1ebdd5f

1 similar comment
@NUAAwqy

NUAAwqy commented Nov 4, 2026

Copy link
Copy Markdown
Author

Done — the existing TestFormat expectation is now computed in UTC (time.Unix(sec, 0).UTC().Format(...)) instead of the host's local zone, so the test no longer depends on the test host's TZ. The unknown-zone fallback test keeps using time.Local on purpose, since that is the behavior it asserts. 1ebdd5f

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.

2 participants