From eaef5b8a734c41c2e25810b1c7d8fa4352f0d395 Mon Sep 17 00:00:00 2001 From: John Coffey Date: Mon, 19 Oct 2026 09:40:43 -0700 Subject: [PATCH] lastmod: git dates commits in the site's timezone Today was taken in the site's timezone but a commit's date in its committer's, so a page built in the evening before its commit could get a different date from the same page built after it. --- internal/site/gitdates_test.go | 8 +++++++- internal/site/load.go | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/site/gitdates_test.go b/internal/site/gitdates_test.go index a558962..86587cc 100644 --- a/internal/site/gitdates_test.go +++ b/internal/site/gitdates_test.go @@ -52,7 +52,7 @@ func TestGitLastmod(t *testing.T) { t.Fatal(err) } want := map[string]string{ - "a.md": "2026-05-07", // the second commit, in its own zone + "a.md": "2026-05-08", // the second commit, 23:30 at -07:00, in the site's UTC "docs/b.md": "2026-10-19", // changed, not committed "new.md": "2026-10-19", // not added yet "c.md": "2020-01-02", // updated: wins @@ -69,6 +69,12 @@ func TestGitLastmod(t *testing.T) { t.Errorf("pages not found: %v", want) } + // In a site in Arizona, the same commit is the day it was made there. + put("site.yaml", "name: T\nurl: https://example.org\nlastmod: git\ntimezone: America/Phoenix\n") + if s, err = Load(dir, Options{Now: now}); err != nil || s.PageFrom("a.md").Lastmod().Format("2006-01-02") != "2026-05-07" { + t.Errorf("Phoenix: %v %v", err, s.PageFrom("a.md").Lastmod()) + } + // Without the setting, or outside git, there are no commit dates. put("site.yaml", "name: T\nurl: https://example.org\n") if s, _ = Load(dir, Options{Now: now}); s.PageFrom("a.md").Lastmod().IsZero() == false { diff --git a/internal/site/load.go b/internal/site/load.go index 6dcc014..c958720 100644 --- a/internal/site/load.go +++ b/internal/site/load.go @@ -188,7 +188,10 @@ func Load(dir string, opt Options) (*Site, error) { today = time.Date(today.Year(), today.Month(), today.Day(), 0, 0, 0, 0, s.Location) dates := gitDates(dir, today) for _, p := range s.Pages { - p.Committed = dates[p.Source] + // In the site's timezone, like today: a commit at 23:30 in + // Arizona is the next day in a UTC site, and an uncommitted + // change built then must get the same date as its commit. + p.Committed = dates[p.Source].In(s.Location) if _, edited := opt.Overrides[p.Source]; edited { p.Committed = today // unsaved in the editor: not committed yet } -- 2.54.0