From ca3d5c02768459c0fecb0ce2cb24191b5bbd3151 Mon Sep 17 00:00:00 2001 From: TeoV Date: Fri, 24 Jul 2020 09:11:12 +0300 Subject: [PATCH] Add more test cases for *monthly_estimated --- engine/action_plan.go | 2 +- engine/action_plan_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/engine/action_plan.go b/engine/action_plan.go index 9d4811909..e164ae67b 100644 --- a/engine/action_plan.go +++ b/engine/action_plan.go @@ -131,7 +131,7 @@ func (at *ActionTiming) GetNextStartTime(t1 time.Time) (t time.Time) { if i.Timing.ID == utils.MetaMonthlyEstimated { clnRITiming := at.Timing.Timing.Clone() mnt := t1.Month() - if t1.Day() > clnRITiming.MonthDays[0] { + if t1.Day() >= clnRITiming.MonthDays[0] { mnt++ if mnt == 13 { // special case in case of december next month is January mnt = 1 diff --git a/engine/action_plan_test.go b/engine/action_plan_test.go index b8dd98ce5..659fa7584 100644 --- a/engine/action_plan_test.go +++ b/engine/action_plan_test.go @@ -323,4 +323,28 @@ func TestActionTimingGetNextStartTime(t *testing.T) { if st := at.GetNextStartTime(t1); !st.Equal(exp) { t.Errorf("Expecting: %+v, received: %+v", exp, st) } + + t1 = time.Date(2020, 2, 17, 14, 25, 0, 0, time.UTC) + at = &ActionTiming{ + Timing: &RateInterval{ + Timing: &RITiming{ + ID: utils.MetaMonthlyEstimated, + MonthDays: utils.MonthDays{17}, + StartTime: "15:00:00"}}} + exp = time.Date(2020, 2, 17, 15, 0, 0, 0, time.UTC) + if st := at.GetNextStartTime(t1); !st.Equal(exp) { + t.Errorf("Expecting: %+v, received: %+v", exp, st) + } + + t1 = time.Date(2020, 2, 17, 15, 25, 0, 0, time.UTC) + at = &ActionTiming{ + Timing: &RateInterval{ + Timing: &RITiming{ + ID: utils.MetaMonthlyEstimated, + MonthDays: utils.MonthDays{17}, + StartTime: "10:00:00"}}} + exp = time.Date(2020, 3, 17, 10, 0, 0, 0, time.UTC) + if st := at.GetNextStartTime(t1); !st.Equal(exp) { + t.Errorf("Expecting: %+v, received: %+v", exp, st) + } }