mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-23 08:08:45 +05:00
fixed the firts of month bug
This commit is contained in:
@@ -89,6 +89,7 @@ func (at *ActionTiming) GetNextStartTime() (t time.Time) {
|
||||
if i.MonthDays != nil && len(i.MonthDays) > 0 {
|
||||
i.MonthDays.Sort()
|
||||
now := time.Now()
|
||||
month := now.Month()
|
||||
x := sort.SearchInts(i.MonthDays, now.Day())
|
||||
d = i.MonthDays[0]
|
||||
if x < len(i.MonthDays) {
|
||||
@@ -104,14 +105,19 @@ func (at *ActionTiming) GetNextStartTime() (t time.Time) {
|
||||
} else { // today was not found in the list, x is the first greater day
|
||||
d = i.MonthDays[x]
|
||||
}
|
||||
} else {
|
||||
if len(i.Months) == 0 {
|
||||
month += 1
|
||||
}
|
||||
}
|
||||
h, m, s := t.Clock()
|
||||
t = time.Date(now.Year(), now.Month(), d, h, m, s, 0, time.Local)
|
||||
t = time.Date(now.Year(), month, d, h, m, s, 0, time.Local)
|
||||
}
|
||||
MONTHS:
|
||||
if i.Months != nil && len(i.Months) > 0 {
|
||||
i.Months.Sort()
|
||||
now := time.Now()
|
||||
year := now.Year()
|
||||
x := sort.Search(len(i.Months), func(x int) bool { return i.Months[x] >= now.Month() })
|
||||
m = i.Months[0]
|
||||
if x < len(i.Months) {
|
||||
@@ -135,9 +141,13 @@ MONTHS:
|
||||
t = time.Date(t.Year(), t.Month(), i.MonthDays[0], t.Hour(), t.Minute(), t.Second(), 0, t.Location())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if len(i.Years) == 0 {
|
||||
year += 1
|
||||
}
|
||||
}
|
||||
h, min, s := t.Clock()
|
||||
t = time.Date(now.Year(), m, t.Day(), h, min, s, 0, time.Local)
|
||||
t = time.Date(year, m, t.Day(), h, min, s, 0, time.Local)
|
||||
}
|
||||
YEARS:
|
||||
if i.Years != nil && len(i.Years) > 0 {
|
||||
|
||||
@@ -175,7 +175,6 @@ func TestActionTimingFirstOfTheMonth(t *testing.T) {
|
||||
at := &ActionTiming{Timing: &Interval{
|
||||
Months: 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: MonthDays{1},
|
||||
StartTime: "00:00:00",
|
||||
}}
|
||||
st := at.GetNextStartTime()
|
||||
expected := nextMonth
|
||||
@@ -297,6 +296,20 @@ func TestActionTimingFirstOfTheYear(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingFirstMonthOfTheYear(t *testing.T) {
|
||||
now := time.Now()
|
||||
y, _, _ := now.Date()
|
||||
nextYear := time.Date(y+1, 1, 1, 0, 0, 0, 0, time.Local)
|
||||
at := &ActionTiming{Timing: &Interval{
|
||||
Months: Months{time.January},
|
||||
}}
|
||||
st := at.GetNextStartTime()
|
||||
expected := nextYear
|
||||
if !st.Equal(expected) {
|
||||
t.Errorf("Expected %v was %v", expected, st)
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingCheckForASAP(t *testing.T) {
|
||||
at := &ActionTiming{Timing: &Interval{StartTime: ASAP}}
|
||||
if !at.CheckForASAP() {
|
||||
|
||||
Reference in New Issue
Block a user