diff --git a/models/common/planner.go b/models/common/planner.go index 3b15372..7312476 100755 --- a/models/common/planner.go +++ b/models/common/planner.go @@ -8,18 +8,22 @@ import ( ) func GetPlannerNearestStart(start time.Time, planned map[tools.DataType]map[string]pricing.PricedItemITF, request *tools.APIRequest) float64 { - near := float64(10000000000) // set a high value + near := float64(-1) // unset sentinel for _, items := range planned { // loop through the planned items for _, priced := range items { // loop through the priced items if priced.GetLocationStart() == nil { // if the start is nil, continue // skip the iteration } - newS := priced.GetLocationStart() // get the start - if newS.Sub(start).Seconds() < near { // if the difference between the start and the new start is less than the nearest start - near = newS.Sub(start).Seconds() + newS := priced.GetLocationStart() // get the start + diff := newS.Sub(start).Seconds() // get the difference + if near < 0 || diff < near { // if the difference is less than the nearest start + near = diff } } } + if near < 0 { + return 0 // no items found, start at the given start time + } return near }