(t *testing.T)
| 6 | ) |
| 7 | |
| 8 | func 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 | |
| 27 | func TestRelativeTimeOldDateInZone(t *testing.T) { |
| 28 | t.Setenv("TZ", "UTC") |
nothing calls this directly
no test coverage detected