MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / TestFormatInstantNeverLocal

Function TestFormatInstantNeverLocal

internal/cli/zone_test.go:8–25  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestFormatInstantNeverLocal(t *testing.T) {
9 t.Setenv("TZ", "UTC")
10 old := time.Local
11 time.Local = time.FixedZone("Machine", 9*3600)
12 t.Cleanup(func() { time.Local = old; SetDisplayLocationResolver(nil) })
13 instant := time.Date(2026, 1, 15, 18, 30, 0, 0, time.UTC)
14 for _, resolver := range []func() *time.Location{nil, func() *time.Location { return nil }} {
15 SetDisplayLocationResolver(resolver)
16 if got := FormatInstant(instant, "15:04"); got != "18:30" {
17 t.Fatalf("UTC fallback = %s", got)
18 }
19 }
20 ny, _ := time.LoadLocation("America/New_York")
21 SetDisplayLocationResolver(func() *time.Location { return ny })
22 if got := FormatInstant(instant, "15:04"); got != "13:30" {
23 t.Fatalf("user time = %s", got)
24 }
25}
26
27func TestRelativeTimeOldDateInZone(t *testing.T) {
28 t.Setenv("TZ", "UTC")

Callers

nothing calls this directly

Calls 3

FormatInstantFunction · 0.85
FatalfMethod · 0.80

Tested by

no test coverage detected