From c360cabdce0a678e6aef43996c323f9c2ddd4cf7 Mon Sep 17 00:00:00 2001 From: andig Date: Thu, 30 Nov 2023 10:53:13 +0500 Subject: [PATCH] Tariff: split custom tariff into 1h slots --- tariff/tariff.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tariff/tariff.go b/tariff/tariff.go index ba759c4db..0333b69ec 100644 --- a/tariff/tariff.go +++ b/tariff/tariff.go @@ -51,12 +51,16 @@ func (t *Tariff) Rates() (api.Rates, error) { return nil, err } - res := api.Rates{ - { - Start: now.BeginningOfHour(), - End: now.BeginningOfHour().Add(48 * time.Hour), + res := make(api.Rates, 48) + start := now.BeginningOfHour() + + for i := 0; i < len(res); i++ { + slot := start.Add(time.Duration(i) * time.Hour) + res[i] = api.Rate{ + Start: slot, + End: slot.Add(time.Hour), Price: t.totalPrice(price), - }, + } } return res, nil