make working hours, weekdays configurable by impl ntg
parent
93d74fb9e1
commit
4a25e7dc0f
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue