Files
silo-server/internal/catalog/air_schedule_test.go
T

72 lines
1.8 KiB
Go

package catalog
import (
"testing"
"time"
)
func TestInferAirTimezone_UsesNetworkBeforeCountry(t *testing.T) {
t.Parallel()
got := InferAirTimezone([]string{"BBC One"}, []string{"Japan"})
if got != "Europe/London" {
t.Fatalf("timezone = %q, want Europe/London", got)
}
}
func TestInferAirTimezone_UsesSingleTimezoneCountry(t *testing.T) {
t.Parallel()
got := InferAirTimezone(nil, []string{"South Korea"})
if got != "Asia/Seoul" {
t.Fatalf("timezone = %q, want Asia/Seoul", got)
}
}
func TestValidateAirTimezone(t *testing.T) {
t.Parallel()
if !ValidateAirTimezone("America/New_York") {
t.Fatal("expected America/New_York to be valid")
}
if ValidateAirTimezone("Eastern") {
t.Fatal("expected Eastern to be invalid")
}
}
func TestCalendarEventAirAt_ConvertsSourceTimezoneToUTC(t *testing.T) {
t.Parallel()
airDate := time.Date(2026, time.May, 28, 0, 0, 0, 0, time.UTC)
airTime := "23:30"
airTimezone := "Asia/Tokyo"
got := CalendarEventAirAt(airDate, &airTime, &airTimezone)
if got == nil {
t.Fatal("expected air_at")
}
want := time.Date(2026, time.May, 28, 14, 30, 0, 0, time.UTC)
if !got.Equal(want) {
t.Fatalf("air_at = %s, want %s", got.Format(time.RFC3339), want.Format(time.RFC3339))
}
}
func TestCalendarEventAirAt_UsesDSTForSourceDate(t *testing.T) {
t.Parallel()
airTime := "20:00"
airTimezone := "America/New_York"
winter := CalendarEventAirAt(time.Date(2026, time.January, 15, 0, 0, 0, 0, time.UTC), &airTime, &airTimezone)
summer := CalendarEventAirAt(time.Date(2026, time.July, 15, 0, 0, 0, 0, time.UTC), &airTime, &airTimezone)
if winter == nil || summer == nil {
t.Fatal("expected air_at values")
}
if winter.Hour() != 1 {
t.Fatalf("winter UTC hour = %d, want 1", winter.Hour())
}
if summer.Hour() != 0 {
t.Fatalf("summer UTC hour = %d, want 0", summer.Hour())
}
}