Repository navigation
Conversation
…lid ISO-8601 markers The timeFormatISO template func discarded the location loaded from the site-configured time zone (the same pattern apache#1659 fixed in day.Format) and formatted the server-local wall clock under a literal "Z", so every server-rendered <time datetime="..."> attribute carried the wrong instant labeled as UTC. The JSON-LD DateCreated values were built in the server zone as well, and the same-year decision in translatorTimeFormat compared years in the server zone instead of the display zone. Add day.Location and day.FormatISO as the shared zone-aware renderer, route timeFormatISO through it, drop the dead LoadLocation call, make the same-year decision in the display zone, and render the JSON-LD dates with .In(day.Location(siteInfo.Interface.TimeZone)). Fixes apache#1669
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 #1669
Root cause
The server-rendered dates ignore the site-configured time zone in three places (verified on
dev; see #1669 for the full report and the executed repro):timeFormatISO(internal/base/server/http_funcmap.go) calledtime.LoadLocation(tz)and discarded the loaded location — the same pattern fix(day): render unix timestamps in the time zone the caller asked for #1659 fixed inday.Format— then formatted in the server's local zone with the layout2006-01-02T15:04:05.000Z, where the trailingZis a literal. Every server-rendered<time datetime="...">(question detail ×4, comment, question list, tag detail) carried the server-local wall clock labeled as UTC.DateCreatedfields (internal/controller/template_controller.go) were built withtime.Unix(...)in the server zone, so the schema.org data carried the deployment's zone instead ofsiteInfo.Interface.TimeZone.translatorTimeFormatcompared calendar years in the server zone, not the display zone: two instants sharing a year in Tokyo sit on opposite sides of New Year in Los Angeles.Proposed changes
pkg/day: extract the shared zone resolverLocation(tz)(empty/unknown → server local, the semantics fix(day): render unix timestamps in the time zone the caller asked for #1659 established) and addFormatISO(unix, tz)rendering a real ISO-8601 marker (+09:00, orZonly for UTC).Formatnow usesLocationtoo (behavior unchanged on dev).http_funcmap.go:timeFormatISOdelegates today.FormatISO; the deadLoadLocationcall is removed; the year-boundary decision moves intosameYearInZone(a, b, tz)and is made in the display zone.template_controller.go: the JSON-LDDateCreatedvalues are rendered with.In(day.Location(siteInfo.Interface.TimeZone)).Verification
All commands run with Go 1.25.14 (linux/amd64) on the
devbranch with these changes applied.go test ./pkg/day/ -v—TestFormat,TestFormatTimezone(5 subtests),TestFormatUnknownTimezoneFallsBackToLocal(3 subtests),TestLocation,TestFormatISO(5 subtests) — all PASS,ok github.com/apache/answer/pkg/day 0.368s.go test ./internal/base/server/ -v—TestTimeFormatISO(4 subtests),TestTimeFormatISOFallsBackToLocalForUnknownZone(3 subtests),TestSameYearInZone— all PASS,ok github.com/apache/answer/internal/base/server 0.040s.TZ=Asia/Shanghai): beforetimeFormatISO("Asia/Tokyo", 1700000000) = 2023-11-15T06:13:20.000Z, after2023-11-15T07:13:20.000+09:00.go build ./...clean;go test ./internal/... ./pkg/... ./plugin/... ./cmd/...passes everywhere exceptinternal/repo/repo_testandplugin/plugin_test, which panic on pristine dev too (the sandboxed sqlite cannot write: "attempt to write a readonly database") — pre-existing environment limitation, unrelated to this change.Changelog
<time datetime>attributes and JSON-LD dates in the site time zone with valid ISO-8601 markers, instead of the server-local wall clock labeled as UTC