diff --git a/core/planner/helper_test.go b/core/planner/helper_test.go index c2759ea23..5f07a8698 100644 --- a/core/planner/helper_test.go +++ b/core/planner/helper_test.go @@ -9,9 +9,18 @@ import ( "github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/tariff" "github.com/samber/lo" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) +func TestSlitPrecondition(t *testing.T) { + clock := clock.NewMock() + rr := rates([]float64{1, 2, 3, 4}, clock.Now(), tariff.SlotDuration) + rates, precond := splitPreconditionSlots(rr, clock.Now().Add(3*tariff.SlotDuration)) + assert.Equal(t, rr[0:3], rates, "rates") + assert.Equal(t, rr[3:], precond, "precond") +} + func TestSlotHasSuccessor(t *testing.T) { plan := rates([]float64{20, 60, 10, 80, 40, 90}, time.Now(), time.Hour) diff --git a/core/planner/planner.go b/core/planner/planner.go index fe34af7f7..950394c03 100644 --- a/core/planner/planner.go +++ b/core/planner/planner.go @@ -208,7 +208,7 @@ func splitPreconditionSlots(rates api.Rates, preCondStart time.Time) (api.Rates, } // split slot - if !r.Start.After(preCondStart) { + if r.Start.Before(preCondStart) { // keep the first part of the slot res = append(res, api.Rate{ Start: r.Start,