diff --git a/cmd/bd/show.go b/cmd/bd/show.go index c8c4db8d6..e2609cf8a 100644 --- a/cmd/bd/show.go +++ b/cmd/bd/show.go @@ -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)") diff --git a/cmd/bd/show_format.go b/cmd/bd/show_format.go index 408f2dae2..4c2198198 100644 --- a/cmd/bd/show_format.go +++ b/cmd/bd/show_format.go @@ -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"))) diff --git a/cmd/bd/show_format_metadata_test.go b/cmd/bd/show_format_metadata_test.go index 21eaacbbe..4c8502a1f 100644 --- a/cmd/bd/show_format_metadata_test.go +++ b/cmd/bd/show_format_metadata_test.go @@ -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{}