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 {
|
func (ntg NTGVision) workingHours(now time.Time) bool {
|
||||||
// TODO assert M-F 9-4 EST
|
// TODO assert M-F 9-4 EST
|
||||||
now = now.In(time.FixedZone("EST", -5*60*60))
|
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())
|
working := config.Get().Brokers.NTG.Working
|
||||||
switch now.Weekday() {
|
logtr.Debugf("ntg.workingHours: now=%s, weekday=%v, hour=%v (ok=%+v)", now.String(), now.Weekday(), now.Hour(), working)
|
||||||
case time.Sunday, time.Saturday:
|
if ok := func() bool {
|
||||||
|
for _, hr := range working.Hours {
|
||||||
|
if now.Hour() == hr {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}(); !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
switch now.Hour() {
|
if ok := func() bool {
|
||||||
case 9, 10, 11, 12, 13, 14, 15, 16:
|
for _, weekday := range working.Weekdays {
|
||||||
default:
|
if now.Weekday() == time.Weekday(weekday) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}(); !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,17 @@
|
||||||
package broker
|
package broker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"local/truckstop/config"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWorkingHoursNTG(t *testing.T) {
|
func TestWorkingHoursNTG(t *testing.T) {
|
||||||
|
os.Setenv("CONFIG", "../config.json")
|
||||||
|
if err := config.Refresh(nil); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
ntg := NTGVision{}
|
ntg := NTGVision{}
|
||||||
if !ntg.workingHours(time.Date(2022, 1, 27, 12, 0, 0, 0, time.FixedZone("MST", -7*60*60))) {
|
if !ntg.workingHours(time.Date(2022, 1, 27, 12, 0, 0, 0, time.FixedZone("MST", -7*60*60))) {
|
||||||
t.Fatal("noon MST not ok")
|
t.Fatal("noon MST not ok")
|
||||||
|
|
|
||||||
|
|
@ -80,8 +80,8 @@
|
||||||
"RadiusMiles": 200,
|
"RadiusMiles": 200,
|
||||||
"NTG": {
|
"NTG": {
|
||||||
"Working": {
|
"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],
|
"Hours": [6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
||||||
"Weekdays": [0, 1, 2, 3, 4, 5, 6]
|
"Weekdays": [1, 2, 3, 4, 5]
|
||||||
},
|
},
|
||||||
"Enabled": false,
|
"Enabled": false,
|
||||||
"JobInfo": true,
|
"JobInfo": true,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue