package playtime import ( "testing" "time" ) // Days and hour buckets follow the viewer's time zone, not UTC. func TestLastDaysInZone(t *testing.T) { london, err := time.LoadLocation("Europe/London") if err != nil { t.Fatal(err) } // 00:30 UTC is 01:30 in London (BST): already the 4th there. now := time.Date(2026, 10, 4, 0, 30, 0, 0, time.UTC) days, start := lastDays(now, london, 30) if len(days) != 30 || days[0].Date != "2026-09-05" || days[29].Date != "2026-10-04" { t.Fatalf("days run %s to %s (%d)", days[0].Date, days[len(days)-1].Date, len(days)) } if want := time.Date(2026, 9, 5, 0, 0, 0, 0, london); !start.Equal(want) { t.Fatalf("start %v, want %v", start, want) } // 23:00 UTC on the 3rd is midnight on the 4th in London. hoursPerDay(days, []Bucket{ {Start: time.Date(2026, 10, 3, 23, 0, 0, 0, time.UTC), Seconds: 3600}, {Start: time.Date(2026, 10, 3, 22, 0, 0, 0, time.UTC), Seconds: 1800}, {Start: time.Date(2026, 8, 1, 12, 0, 0, 0, time.UTC), Seconds: 3600}, // before the window }, london) if days[29].Hours != 1 || days[28].Hours != 0.5 { t.Fatalf("4th %.1f h, 3rd %.1f h; want 1 and 0.5", days[29].Hours, days[28].Hours) } } func TestParseID(t *testing.T) { if n, err := ParseID("76561198164949547"); err != nil || n != 76561198164949547 { t.Fatalf("got %d, %v", n, err) } for _, bad := range []string{"", "0", "-1", "abc", "765611981649495470000"} { if _, err := ParseID(bad); err == nil { t.Errorf("%q parsed", bad) } } }