package web import ( "testing" "time" ) func TestGreeting(t *testing.T) { london, err := time.LoadLocation("Europe/London") if err != nil { t.Fatal(err) } at := func(h, m int) time.Time { return time.Date(2026, 7, 1, h, m, 0, 0, time.UTC) } for _, c := range []struct { now time.Time loc *time.Location want string }{ {at(0, 0), time.UTC, "Hello, Paul."}, {at(4, 59), time.UTC, "Hello, Paul."}, {at(5, 0), time.UTC, "Good morning, Paul."}, {at(11, 59), time.UTC, "Good morning, Paul."}, {at(12, 0), time.UTC, "Good afternoon, Paul."}, {at(17, 59), time.UTC, "Good afternoon, Paul."}, {at(18, 0), time.UTC, "Good evening, Paul."}, {at(23, 59), time.UTC, "Good evening, Paul."}, {at(8, 0), london, "Good morning, Paul."}, // 09:00 BST {at(17, 0), london, "Good evening, Paul."}, // 18:00 BST {at(23, 30), london, "Hello, Paul."}, // 00:30 BST next day {at(8, 0), nil, "Good morning, Paul."}, // no zone: as given } { if got := greeting(c.now, c.loc, "Paul"); got != c.want { t.Errorf("greeting(%s, %v) = %q, want %q", c.now.Format(time.RFC3339), c.loc, got, c.want) } } }