diff --git a/engine/action_timing.go b/engine/action_timing.go index c29096c27..dab8a9e53 100644 --- a/engine/action_timing.go +++ b/engine/action_timing.go @@ -20,11 +20,12 @@ package engine import ( "fmt" - "github.com/cgrates/cgrates/utils" "sort" "strconv" "strings" "time" + + "github.com/cgrates/cgrates/utils" ) const ( @@ -88,6 +89,7 @@ func (at *ActionTiming) GetNextStartTime() (t time.Time) { if i.Timing.MonthDays != nil && len(i.Timing.MonthDays) > 0 { i.Timing.MonthDays.Sort() now := time.Now() + year := now.Year() month := now.Month() x := sort.SearchInts(i.Timing.MonthDays, now.Day()) d = i.Timing.MonthDays[0] @@ -107,11 +109,12 @@ func (at *ActionTiming) GetNextStartTime() (t time.Time) { } else { if len(i.Timing.Months) == 0 { t = time.Date(now.Year(), month, d, 0, 0, 0, 0, time.Local).AddDate(0, 1, 0) + year = t.Year() month = t.Month() } } h, m, s := t.Clock() - t = time.Date(now.Year(), month, d, h, m, s, 0, time.Local) + t = time.Date(year, month, d, h, m, s, 0, time.Local) } MONTHS: if i.Timing.Months != nil && len(i.Timing.Months) > 0 { diff --git a/engine/actions_test.go b/engine/actions_test.go index 958b7626b..57d016115 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -20,7 +20,9 @@ package engine import ( "fmt" + "github.com/cgrates/cgrates/utils" + "testing" "time" ) @@ -117,7 +119,7 @@ func TestActionTimingOnlyMonths(t *testing.T) { nextMonth := time.Date(y, m, d, 0, 0, 0, 0, time.Local).AddDate(0, 1, 0) at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{Months: utils.Months{time.February, time.May, nextMonth.Month()}}}} st := at.GetNextStartTime() - expected := time.Date(y, nextMonth.Month(), 1, 0, 0, 0, 0, time.Local) + expected := time.Date(nextMonth.Year(), nextMonth.Month(), 1, 0, 0, 0, 0, time.Local) if !st.Equal(expected) { t.Errorf("Expected %v was %v", expected, st) } @@ -177,7 +179,6 @@ func TestActionTimingFirstOfTheMonth(t *testing.T) { nextMonth := time.Date(y, m, 1, 0, 0, 0, 0, time.Local).AddDate(0, 1, 0) at := &ActionTiming{Timing: &RateInterval{ Timing: &RITiming{ - Months: utils.Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December}, MonthDays: utils.MonthDays{1}, }, }}