fix(show): render Created/Started/Updated in local timezone (#5980)

* fix(show): render Created/Started/Updated in local timezone

bd show printed these stored-UTC timestamps as bare dates without
converting, so if it's already tomorrow in UTC, the whole calendar day
was wrong.

Storage is unchanged and still UTC, as is --json.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>

* test(show): stop swapping time.Local in TimestampsRenderLocal

TestFormatIssueMetadata_TimestampsRenderLocal assigned the process-global
time.Local to pin a Pacific zone. Every time.Now() in the process reads that
variable, including goroutines no test can synchronize with: a net/http
connection from the serve test winding down after it returns, and the event
collector Dolt starts at package init. The swap is a data race, and -race
reports it whenever the unsynchronized read is still in the detector's
history: Bazel prcore shard 9 on this PR, and the test run alone (3/3).

Hand the stamp over in a zone twelve hours ahead of time.Local instead, so
its own digits fall on the next calendar day on any machine and only a
conversion to local time prints the right date. No global is written, so
the test runs in parallel like its neighbors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Gas City Merge Queue <merge-queue@gascity.local>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.local>
This commit is contained in:
Michael Hackner 2026-09-30 08:46:43 -07:00 • committed by GitHub
commit 98ab920417
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 39 additions and 4 deletions

View file

@ -302,7 +302,7 @@ func init() {
showCmd.Flags().Bool("children", false, "Show only the children of this issue")
showCmd.Flags().String("as-of", "", "Show issue as it existed at a specific commit hash or branch (requires Dolt; commit hashes must be the full 32-character hash from 'bd history', not a prefix)")
showCmd.Flags().StringArray("id", nil, "Issue ID (use for IDs that look like flags, e.g., --id=gt--xyz)")
showCmd.Flags().Bool("local-time", false, "Show timestamps in local time instead of UTC")
showCmd.Flags().Bool("local-time", false, "Show timestamps in local time instead of UTC (date-only fields are always local)")
showCmd.Flags().BoolP("watch", "w", false, "Watch for changes and auto-refresh display")
showCmd.Flags().Bool("current", false, "Show the currently active issue (in-progress, hooked, or last touched)")
showCmd.Flags().Bool("include-dependents", false, "Stream full dependent issues in JSON output (--json only; may be slow on hub beads)")

View file

@ -110,11 +110,11 @@ func formatIssueMetadata(issue *types.Issue) string {
// Line 2: Created · Updated · Due/Defer
timeParts := []string{}
timeParts = append(timeParts, fmt.Sprintf("Created: %s", issue.CreatedAt.Format("2006-01-02")))
timeParts = append(timeParts, fmt.Sprintf("Created: %s", issue.CreatedAt.Local().Format("2006-01-02")))
if issue.StartedAt != nil {
timeParts = append(timeParts, fmt.Sprintf("Started: %s", issue.StartedAt.Format("2006-01-02")))
timeParts = append(timeParts, fmt.Sprintf("Started: %s", issue.StartedAt.Local().Format("2006-01-02")))
}
timeParts = append(timeParts, fmt.Sprintf("Updated: %s", issue.UpdatedAt.Format("2006-01-02")))
timeParts = append(timeParts, fmt.Sprintf("Updated: %s", issue.UpdatedAt.Local().Format("2006-01-02")))
if issue.DueAt != nil {
timeParts = append(timeParts, fmt.Sprintf("Due: %s", issue.DueAt.Local().Format("2006-01-02")))

View file

@ -4,6 +4,7 @@ import (
"encoding/json"
"strings"
"testing"
"time"
"github.com/charmbracelet/x/ansi"
"github.com/steveyegge/beads/internal/types"
@ -142,6 +143,40 @@ func TestFormatIssueMetadata_CreatedByLabel(t *testing.T) {
}
}
// TestFormatIssueMetadata_TimestampsRenderLocal guards the rule that the
// metadata block reports timestamps on the reader's calendar, as the Due and
// Deferred entries on the same line already did.
//
// Created/Started/Updated are stored in UTC. Printing those digits as a bare
// date put the whole day wrong if it's already tomorrow in UTC.
//
// The stamp is handed over in a zone twelve hours ahead of time.Local, so its
// own digits fall on the next day on any machine, a UTC CI box included, and
// only a conversion to local time prints the right date. time.Local is never
// assigned: every time.Now() in the process reads it, including in goroutines
// no test can synchronize with (a served connection winding down after its
// test, the collector Dolt starts at package init), so a swap trips -race even
// with this test run alone.
func TestFormatIssueMetadata_TimestampsRenderLocal(t *testing.T) {
t.Parallel()
// 18:30 on 2026-08-23 here is 06:30 on 2026-08-24 twelve hours east — the
// same instant on two different calendar days, which is the whole bug.
local := time.Date(2026, 8, 23, 18, 30, 0, 0, time.Local)
_, offset := local.Zone()
stamp := local.In(time.FixedZone("local+12h", offset+12*60*60))
issue := &types.Issue{
ID: "test-tz", Title: "t", IssueType: types.TypeTask,
CreatedAt: stamp, UpdatedAt: stamp, StartedAt: &stamp,
}
out := ansi.Strip(formatIssueMetadata(issue))
for _, want := range []string{"Created: 2026-08-23", "Started: 2026-08-23", "Updated: 2026-08-23"} {
if !strings.Contains(out, want) {
t.Errorf("expected %q in output (the stamp's own digits put the date a day ahead), got:\n%s", want, out)
}
}
}
func TestFormatIssueCustomMetadata_Nil(t *testing.T) {
t.Parallel()
issue := &types.Issue{}