// Package callwindow enforces the fixed legal window for SIP outbound dialing. package callwindow import ( "fmt" "time" ) const ( LocationName = "Asia/Shanghai" OpenHour = 9 CloseHour = 20 ) var shanghai = time.FixedZone(LocationName, 8*60*60) // Allowed reports whether SIP outbound dialing is permitted at now. The // boundary is [09:00, 20:00) in Asia/Shanghai; the input's instant, not its // presentation timezone, is authoritative. func Allowed(now time.Time) bool { local := now.In(shanghai) minutes := local.Hour()*60 + local.Minute() return minutes >= OpenHour*60 && minutes < CloseHour*60 } // Check returns a stable, actionable error when outbound dialing is closed. func Check(now time.Time) error { local := now.In(shanghai) if Allowed(now) { return nil } return fmt.Errorf("SIP outbound dialing is closed at %s; allowed window is %02d:00-%02d:00 %s", local.Format("2006-01-02 15:04:05 -0700"), OpenHour, CloseHour, LocationName) }