local-time: the panel in the container's zone, named on Settings

Agreed by the owner on 2026-10-13 (the local day, no "UTC" beside a
time); the zone is the container's TZ in .env and Settings only shows it,
his "Да" of 2026-10-17. Mockups c205106.

Every time the panel shows is formatted in time.Local and says no zone:
the logs' Time and the DMARC Received columns, a message's timeline,
Overview's "Updated", Health's certificate and renewal, the filter lists,
DMARC reports and windows, the auto limit's last recalculation. Stored
instants stay UTC. The days counted are the zone's: delivery_log_days and
sender_check_days key their rows by the local date, the sender check cuts
downtime at local midnights (byDay), the log filters' days run from local
midnight to local midnight. Notification mail and the test message write
the zone's abbreviation after a time - they are read away from the panel.
DMARC's one-day window label stays the reporter's (UTC) day.

Settings box 05, Time zone, read-only: the name (UTC without TZ), its
offset, and a TZ the image cannot load said to leave the times in UTC
(time/zoneinfo_unix.go, initLocal) rather than named. TZ is passed by the
compose file ("${TZ:-}"), in .env.example and the guide's table; tzdata is
named in the image (supervisor's python3.13 brings it today). Postfix
takes TZ through import_environment, so mail.log's stamps are the same
zone, which closes the trap the roadmap wrote down: the tailer has always
read them in time.Local.

Tests: a TestMain runs view, handlers, store and cmd/panel in UTC whatever
the machine's zone (as logtail's); TestSettingsShowsTheTimeZone,
TestTimesAreTheContainersZone, TestByDayInTheContainersZone, a Moscow day
in TestQueryInboundSpamFilters; envdoc's pattern takes two-letter names.
e2e time_zone_is_the_containers recreates the stand with
TZ=Europe/Moscow: date says MSK, Settings names the zone and UTC+03:00, a
test message's page gives its time and its mail.log lines in Moscow's.
go vet + go test (26 packages) and make e2e on the test server for this
tree.

Docs: guide (§ Settings, the TZ row, the days of Health and the logs),
architecture, schema-migrations, help (word for word with the mockup),
CHANGELOG [Unreleased] § Added, roadmap row done with the decision.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mix
2026-10-17 01:34:28 +03:00
co-authored by Claude Opus 5.5
parent c205106418
commit bdeb01681d
58 changed files with 484 additions and 117 deletions
+1
View File
@@ -31,6 +31,7 @@ type Config struct {
TLSServedCertFile string
TLSReloadInterval time.Duration
SMTPBanner string
TimeZone string
SignSocket string
SignLocalSocket string
JournalSocket string
+1 -1
View File
@@ -316,7 +316,7 @@ func formatAutoUpdated(t time.Time) string {
if t.IsZero() {
return ""
}
return t.UTC().Format("2006-01-02 15:04 UTC")
return t.Local().Format("2006-01-02 15:04")
}
// detailFlash maps a fixed redirect flag to a fixed message, so status text
@@ -133,10 +133,12 @@ func TestDMARCReportShowsPolicyAndRecords(t *testing.T) {
has(t, "report", body,
`<h1 class="title is-4">Outlook.com · `, `<a href="/outbound/dmarc">DMARC reports</a> /`, `<a href="/outbound/dmarc/domains/1">example.org</a> /`,
"<span class=\"tag is-success is-light\">1\u00a0903 pass</span>", `<span class="tag is-warning is-light">7 fail</span>`,
`5f1c9a0e7b2d4e61a3`, `noreply-dmarc@outlook.example`, ` UTC</dd>`,
`5f1c9a0e7b2d4e61a3`, `noreply-dmarc@outlook.example`,
`none / none / 100`, `<dd class="sp-mono">r / r</dd>`, `dmarc-reports@mail.example.org`,
`<h2>Records</h2>`, `Parsed from the aggregate XML`, `203.0.113.25`, `198.51.100.44`,
`<span class="tag is-danger is-light">fail</span>`, `<span class="tag is-success is-light">pass</span>`)
// The times are the container's zone's, and say no zone (local-time).
lacks(t, "report", body, ` UTC</dd>`)
}
// DMARC is a feature of the deployment: with ingest off none of its pages
@@ -199,8 +199,8 @@ func (h *Handlers) HandleDMARCReport(w http.ResponseWriter, r *http.Request) {
ID: rep.ID, Reporter: rep.Reporter, ReportID: rep.ReportID, Domain: rep.Domain, DomainID: d.ID,
Contact: rep.ContactEmail, Pass: rep.PassCount, Fail: rep.FailCount,
Window: formatDMARCWindow(rep.PeriodBegin, rep.PeriodEnd),
Period: rep.PeriodBegin.UTC().Format(stamp) + " – " + rep.PeriodEnd.UTC().Format(stamp) + " UTC",
Received: rep.ReceivedAt.UTC().Format("2006-01-02 15:04") + " UTC",
Period: rep.PeriodBegin.Local().Format(stamp) + " – " + rep.PeriodEnd.Local().Format(stamp),
Received: rep.ReceivedAt.Local().Format("2006-01-02 15:04"),
PolicyP: rep.PolicyP, PolicySP: rep.PolicySP, PolicyPct: rep.PolicyPct,
PolicyADKIM: rep.PolicyADKIM, PolicyASPF: rep.PolicyASPF, Recipient: rep.Recipient,
Hub: true,
@@ -74,7 +74,7 @@ func TestHealthPageRendersEveryCheck(t *testing.T) {
out := renderHealth(t, h, healthReading(), "")
for _, want := range []string{
"panel", "fatal", "exited too quickly",
"mail.example.com", "203.0.113.10 → no PTR record", "2026-11-08 09:14 UTC",
"mail.example.com", "203.0.113.10 → no PTR record", "2026-11-08 09:14",
`action="/server/health/reload"`, `action="/server/health/recheck"`,
`hx-get="/server/health/fragment"`,
`<span class="tag is-danger is-light">error</span>`, // postfix, and the reverse DNS box
@@ -164,9 +164,9 @@ func TestHealthPageNamesARenewalWaiting(t *testing.T) {
c.Cert = cert
out := renderHealth(t, h, c, "")
for _, want := range []string{
"<dt>Expires</dt>", "2026-11-08 09:14 UTC",
"<dt>Renewal expires</dt>", "2027-01-31 08:02 UTC",
"<dt>Renewal mounted</dt>", "2026-10-15 03:12 UTC",
"<dt>Expires</dt>", "2026-11-08 09:14",
"<dt>Renewal expires</dt>", "2027-01-31 08:02",
"<dt>Renewal mounted</dt>", "2026-10-15 03:12",
"Postfix still serves the certificate above.",
} {
if !strings.Contains(out, want) {
@@ -529,7 +529,7 @@ func TestFilterListsWhereTheyGo(t *testing.T) {
}
body = s.get(s.h.HandleFilterLists, "/inbound/filter-lists", globalPrincipal).Body.String()
has(t, "filter on", body, `<span class="tag is-success is-light">applied</span>`,
`rspamd, from map files it rereads within seconds of a change`, `<dt>Last written</dt><dd>2026-09-11 08:40 UTC</dd>`,
`rspamd, from map files it rereads within seconds of a change`, `<dt>Last written</dt><dd>2026-09-11 08:40</dd>`,
`/data/antispam/`)
lacks(t, "filter on", body, `not applied`, `Nothing — the spam filter is off`, `INBOUND_ANTISPAM_MILTER`)
}
+2 -1
View File
@@ -387,7 +387,8 @@ func (h *Handlers) outLogPage(r *http.Request) (*view.OutLog, error) {
}
form := view.OutLogFilter{Domain: filter.Domain, App: filter.AppLogin, Status: filter.Status}
// The days, as on the Inbound log: from the first's midnight to the end of
// the last, UTC; a day that does not parse is no narrowing.
// the last, in the container's zone; a day that does not parse is no
// narrowing.
if t, err := time.Parse(logDay, q.Get("from")); err == nil {
form.From, filter.Since = t.Format(logDay), t
}
@@ -60,6 +60,7 @@ func (h *Handlers) renderServerSettings(w http.ResponseWriter, r *http.Request,
page.WithNotifications(on, notify.From(h.cfg.Hostname))
mail := h.serverMail(false)
page.WithMail(mail.records, view.FormatAge(mail.checked, time.Now()))
page.WithTimeZone(h.cfg.TimeZone, time.Local, time.Now())
// The inbound field exists while there is an inbound journal to keep.
if h.cfg.InboundEnabled {
page.WithInbound(strconv.Itoa(form.inbound))
+5 -5
View File
@@ -194,9 +194,9 @@ func (h *Handlers) HandleTestMessage(w http.ResponseWriter, r *http.Request) {
return
}
const subject = "SelfPost test message"
now := time.Now().UTC()
now := time.Now()
body := "A test message from SelfPost at " + h.cfg.Hostname + ", sent from Server › Health on " +
now.Format("2006-01-02 at 15:04 UTC") + ".\n\nIt came from this server, signed with the DKIM key of its own name. " +
now.Format("2006-01-02 at 15:04 MST") + ".\n\nIt came from this server, signed with the DKIM key of its own name. " +
"Its page in the panel's Outbound log shows what this mail server answered.\n"
row, err := h.store.InsertTestMessage(h.cfg.Hostname, from, to, subject)
if err != nil {
@@ -290,7 +290,7 @@ func healthPage(m view.Meta, c healthReadings, flash string) *view.Health {
cert := c.Cert
page.Certificate.End = view.Verdict(string(cert.Status))
if !cert.NotAfter.IsZero() {
page.CertFacts = append(page.CertFacts, view.Fact{Label: "Expires", Value: view.Plain(cert.NotAfter.UTC().Format("2006-01-02 15:04 UTC")), Mono: true})
page.CertFacts = append(page.CertFacts, view.Fact{Label: "Expires", Value: view.Plain(cert.NotAfter.Local().Format("2006-01-02 15:04")), Mono: true})
}
if len(cert.Names) > 0 {
names := view.Fact{Label: "Names", Value: view.Plain(strings.Join(cert.Names, ", ")), Mono: true}
@@ -304,8 +304,8 @@ func healthPage(m view.Meta, c healthReadings, flash string) *view.Health {
}
if r := cert.Renewal; r != nil {
page.CertFacts = append(page.CertFacts,
view.Fact{Label: "Renewal expires", Value: view.Plain(r.NotAfter.UTC().Format("2006-01-02 15:04 UTC")), Mono: true},
view.Fact{Label: "Renewal mounted", Value: view.Plain(r.Mounted.UTC().Format("2006-01-02 15:04 UTC")), Mono: true})
view.Fact{Label: "Renewal expires", Value: view.Plain(r.NotAfter.Local().Format("2006-01-02 15:04")), Mono: true},
view.Fact{Label: "Renewal mounted", Value: view.Plain(r.Mounted.Local().Format("2006-01-02 15:04")), Mono: true})
}
page.CertDetail, page.CertProblem = cert.Detail, cert.Status != health.StatusOK
+28
View File
@@ -0,0 +1,28 @@
package handlers
import (
"os"
"testing"
"time"
)
// TestMain runs the tests in UTC, whatever the zone of the machine they run
// on: the panel shows times and counts days in time.Local, the container's
// zone (TZ), and the fixtures are written in UTC. The tests of another zone
// set it themselves (inZone).
func TestMain(m *testing.M) {
time.Local = time.UTC
os.Exit(m.Run())
}
// inZone runs the rest of the test in the zone name, as a container started
// with TZ=name; the test must not be parallel.
func inZone(t *testing.T, name string) {
t.Helper()
loc, err := time.LoadLocation(name)
if err != nil {
t.Skipf("no zone %s here: %v", name, err)
}
time.Local = loc
t.Cleanup(func() { time.Local = time.UTC })
}