error on usage start
This commit is contained in:
@@ -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()
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user