51 lines
1.4 KiB
Go

package dashboard
import (
"testing"
"time"
)
func TestDailyDateUsesStatisticTimezone(t *testing.T) {
riyadh := mustLoadLocation(t, "Asia/Riyadh")
eventTime := time.Date(2026, 5, 26, 21, 30, 0, 0, time.UTC)
got := DailyDate(eventTime, riyadh)
if got.Format("2006-01-02") != "2026-05-27" {
t.Fatalf("DailyDate = %s, want Riyadh day 2026-05-27", got.Format("2006-01-02"))
}
if got.Location() != riyadh {
t.Fatalf("DailyDate location = %s, want %s", got.Location(), riyadh)
}
}
func TestPeriodWindowsUseStatisticTimezone(t *testing.T) {
riyadh := mustLoadLocation(t, "Asia/Riyadh")
eventTime := time.Date(2026, 5, 26, 21, 30, 0, 0, time.UTC)
windows := PeriodWindows(eventTime, riyadh)
if windows[0].Type != PeriodDay || windows[0].Key != "2026-05-27" {
t.Fatalf("day window = %+v, want key 2026-05-27", windows[0])
}
}
func TestSamePeriodUsesStatisticTimezone(t *testing.T) {
riyadh := mustLoadLocation(t, "Asia/Riyadh")
left := time.Date(2026, 5, 26, 21, 10, 0, 0, time.UTC)
right := time.Date(2026, 5, 27, 20, 50, 0, 0, time.UTC)
if !SamePeriod(left, right, PeriodWindow{Type: PeriodDay}, riyadh) {
t.Fatal("SamePeriod should match events in the same Riyadh day")
}
}
func mustLoadLocation(t *testing.T, name string) *time.Location {
t.Helper()
location, err := time.LoadLocation(name)
if err != nil {
t.Fatalf("load location %s: %v", name, err)
}
return location
}