diff --git a/broker/ntgvision.go b/broker/ntgvision.go index 9cfbc72..9ab49ef 100644 --- a/broker/ntgvision.go +++ b/broker/ntgvision.go @@ -224,14 +224,26 @@ func (ntg NTGVision) SearchZips(zips []string) ([]Job, error) { func (ntg NTGVision) workingHours(now time.Time) bool { // TODO assert M-F 9-4 EST now = now.In(time.FixedZone("EST", -5*60*60)) - logtr.Debugf("ntg.workingHours: %s: weekday=%v (sun=%v, sat=%v), hour=%v (ok=9..16)", now.String(), now.Weekday(), time.Sunday, time.Saturday, now.Hour()) - switch now.Weekday() { - case time.Sunday, time.Saturday: + working := config.Get().Brokers.NTG.Working + logtr.Debugf("ntg.workingHours: now=%s, weekday=%v, hour=%v (ok=%+v)", now.String(), now.Weekday(), now.Hour(), working) + if ok := func() bool { + for _, hr := range working.Hours { + if now.Hour() == hr { + return true + } + } + return false + }(); !ok { return false } - switch now.Hour() { - case 9, 10, 11, 12, 13, 14, 15, 16: - default: + if ok := func() bool { + for _, weekday := range working.Weekdays { + if now.Weekday() == time.Weekday(weekday) { + return true + } + } + return false + }(); !ok { return false } return true diff --git a/broker/ntgvision_test.go b/broker/ntgvision_test.go index 92119de..474a8a8 100644 --- a/broker/ntgvision_test.go +++ b/broker/ntgvision_test.go @@ -1,11 +1,17 @@ package broker import ( + "local/truckstop/config" + "os" "testing" "time" ) func TestWorkingHoursNTG(t *testing.T) { + os.Setenv("CONFIG", "../config.json") + if err := config.Refresh(nil); err != nil { + t.Fatal(err) + } ntg := NTGVision{} if !ntg.workingHours(time.Date(2022, 1, 27, 12, 0, 0, 0, time.FixedZone("MST", -7*60*60))) { t.Fatal("noon MST not ok") diff --git a/config.json b/config.json index 66e9990..1d3cffb 100644 --- a/config.json +++ b/config.json @@ -80,8 +80,8 @@ "RadiusMiles": 200, "NTG": { "Working": { - "Hours": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23], - "Weekdays": [0, 1, 2, 3, 4, 5, 6] + "Hours": [6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + "Weekdays": [1, 2, 3, 4, 5] }, "Enabled": false, "JobInfo": true,