make working hours, weekdays configurable by impl ntg
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user