mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-06 21:25:04 +03:00
e535df0374
tzdata 2026f cancelled Cuba's November 2026 DST fallback, so on hosts with current tzdata (macOS) 2026-11-01 has no repeated midnight: TestNextWeeklyRenewal_RepeatedMidnight failed and the subscription calendar cases passed without exercising the repeated midnight. Move both to 2020-11-01, a Sunday fallback on the 1st that every tzdata version agrees on. The weekly case still catches a 168-hour advance.
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package service
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestNextWeeklyRenewal_RepeatedMidnight(t *testing.T) {
|
|
loc, err := time.LoadLocation("America/Havana")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// A past transition: tzdata 2026f cancelled Cuba's November 2026 fallback,
|
|
// so a future one makes the result depend on the host's tzdata version.
|
|
for _, tt := range []struct{ expiry, want string }{
|
|
{"2020-10-25T00:00:00-04:00", "2020-11-01T00:00:00-04:00"},
|
|
{"2020-11-01T00:00:00-04:00", "2020-11-08T00:00:00-05:00"},
|
|
{"2020-11-01T00:00:00-05:00", "2020-11-08T00:00:00-05:00"},
|
|
} {
|
|
from, err := time.Parse(time.RFC3339, tt.expiry)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := nextWeeklyRenewal(from, 7, loc).Format(time.RFC3339)
|
|
if got != tt.want {
|
|
t.Fatalf("next Sunday after %s = %s, want %s", tt.expiry, got, tt.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestNextWeeklyRenewal_SkippedDates(t *testing.T) {
|
|
for _, tt := range []struct {
|
|
zone, from, want string
|
|
weekday int
|
|
}{
|
|
{"America/Havana", "2026-03-01T00:00:00-05:00", "2026-03-08T01:00:00-04:00", 7},
|
|
{"Pacific/Apia", "2011-12-23T00:00:00-10:00", "2012-01-06T00:00:00+14:00", 5},
|
|
} {
|
|
t.Run(tt.zone, func(t *testing.T) {
|
|
loc, err := time.LoadLocation(tt.zone)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
from, err := time.Parse(time.RFC3339, tt.from)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := nextWeeklyRenewal(from, tt.weekday, loc).Format(time.RFC3339)
|
|
if got != tt.want {
|
|
t.Fatalf("next weekly cutoff = %s, want %s", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|