fixed action timing next date bug

This commit is contained in:
Radu Ioan Fericean
2013-12-02 14:21:01 +02:00
parent cc27c6a1a1
commit eebfa68375
2 changed files with 8 additions and 4 deletions

View File

@@ -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 {

View File

@@ -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},
},
}}