From 230220f0e15f7a8c9efc47b95c648850f0eac641 Mon Sep 17 00:00:00 2001 From: Michael Geers Date: Thu, 14 Nov 2024 08:39:57 +0100 Subject: [PATCH 1/4] Tariff: better rate matching error --- api/rates.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/api/rates.go b/api/rates.go index 578a59aa04..4d606bf7bb 100644 --- a/api/rates.go +++ b/api/rates.go @@ -1,7 +1,7 @@ package api import ( - "errors" + "fmt" "slices" "time" ) @@ -36,5 +36,9 @@ func (r Rates) Current(now time.Time) (Rate, error) { } } - return Rate{}, errors.New("no matching rate") + if len(r) == 0 { + return Rate{}, fmt.Errorf("no matching rate: no rates available") + } + return Rate{}, fmt.Errorf("no matching rate: now %s, %d rates (%s to %s)", + now.Format(time.RFC3339), len(r), r[0].Start.Format(time.RFC3339), r[len(r)-1].End.Format(time.RFC3339)) } From 86c028f12908f0dd53e8d0836c93edefecdf810a Mon Sep 17 00:00:00 2001 From: Michael Geers Date: Thu, 14 Nov 2024 08:58:49 +0100 Subject: [PATCH 2/4] review feedback --- api/rates.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/rates.go b/api/rates.go index 4d606bf7bb..24976400b4 100644 --- a/api/rates.go +++ b/api/rates.go @@ -37,8 +37,8 @@ func (r Rates) Current(now time.Time) (Rate, error) { } if len(r) == 0 { - return Rate{}, fmt.Errorf("no matching rate: no rates available") + return Rate{}, fmt.Errorf("no matching rate for: %s", now.Format(time.RFC3339)) } - return Rate{}, fmt.Errorf("no matching rate: now %s, %d rates (%s to %s)", + return Rate{}, fmt.Errorf("no matching rate for: %s, %d rates (%s to %s)", now.Format(time.RFC3339), len(r), r[0].Start.Format(time.RFC3339), r[len(r)-1].End.Format(time.RFC3339)) } From ea34536f9e56d77680b08dd53db43331ec6527f9 Mon Sep 17 00:00:00 2001 From: Michael Geers Date: Thu, 14 Nov 2024 11:32:27 +0100 Subject: [PATCH 3/4] Update api/rates.go Co-authored-by: andig --- api/rates.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/rates.go b/api/rates.go index 24976400b4..f7b3ee3f2f 100644 --- a/api/rates.go +++ b/api/rates.go @@ -37,7 +37,7 @@ func (r Rates) Current(now time.Time) (Rate, error) { } if len(r) == 0 { - return Rate{}, fmt.Errorf("no matching rate for: %s", now.Format(time.RFC3339)) + return Rate{}, fmt.Errorf("no matching rate for: %s", now.Local().Format(time.RFC3339)) } return Rate{}, fmt.Errorf("no matching rate for: %s, %d rates (%s to %s)", now.Format(time.RFC3339), len(r), r[0].Start.Format(time.RFC3339), r[len(r)-1].End.Format(time.RFC3339)) From 97eaa60139ea1ecbfd3b6c030b2f22ef113f306f Mon Sep 17 00:00:00 2001 From: Michael Geers Date: Thu, 14 Nov 2024 11:32:33 +0100 Subject: [PATCH 4/4] Update api/rates.go Co-authored-by: andig --- api/rates.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/rates.go b/api/rates.go index f7b3ee3f2f..14ccfb1085 100644 --- a/api/rates.go +++ b/api/rates.go @@ -40,5 +40,5 @@ func (r Rates) Current(now time.Time) (Rate, error) { return Rate{}, fmt.Errorf("no matching rate for: %s", now.Local().Format(time.RFC3339)) } return Rate{}, fmt.Errorf("no matching rate for: %s, %d rates (%s to %s)", - now.Format(time.RFC3339), len(r), r[0].Start.Format(time.RFC3339), r[len(r)-1].End.Format(time.RFC3339)) + now.Local().Format(time.RFC3339), len(r), r[0].Start.Local().Format(time.RFC3339), r[len(r)-1].End.Local().Format(time.RFC3339)) }