mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 18:46:24 +05:00
added simplified weekdays
This commit is contained in:
@@ -128,6 +128,17 @@ func (at *ActionTiming) GetNextStartTime() (t time.Time, err error) {
|
||||
|
||||
if i.WeekDays != nil && len(i.WeekDays) > 0 {
|
||||
sort.Sort(i.WeekDays)
|
||||
if t.Equal(time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)) {
|
||||
t = time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, now.Location())
|
||||
}
|
||||
for _, j := range []int{0, 1, 2, 3, 4, 5, 6} {
|
||||
t = time.Date(t.Year(), t.Month(), t.Day()+j, t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), t.Location())
|
||||
for _, wd := range i.WeekDays {
|
||||
if t.Weekday() == wd {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if i.MonthDays != nil && len(i.MonthDays) > 0 {
|
||||
@@ -140,7 +151,7 @@ func (at *ActionTiming) GetNextStartTime() (t time.Time, err error) {
|
||||
if now.Before(t) {
|
||||
h, m, s := t.Clock()
|
||||
t = time.Date(now.Year(), now.Month(), now.Day(), h, m, s, 0, time.Local)
|
||||
goto Months
|
||||
goto MONTHS
|
||||
}
|
||||
if x+1 < len(i.MonthDays) { // today was found in the list, jump to the next grater day
|
||||
d = i.MonthDays[x+1]
|
||||
@@ -152,7 +163,7 @@ func (at *ActionTiming) GetNextStartTime() (t time.Time, err error) {
|
||||
h, m, s := t.Clock()
|
||||
t = time.Date(now.Year(), now.Month(), d, h, m, s, 0, time.Local)
|
||||
}
|
||||
Months:
|
||||
MONTHS:
|
||||
if i.Months != nil && len(i.Months) > 0 {
|
||||
sort.Sort(i.Months)
|
||||
now := time.Now()
|
||||
|
||||
@@ -49,7 +49,7 @@ func TestActionTimingOnlyHour(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
/*func TestActionTimingOnlyWeekdays(t *testing.T) {
|
||||
func TestActionTimingOnlyWeekdays(t *testing.T) {
|
||||
at := &ActionTiming{Timing: &Interval{WeekDays: []time.Weekday{time.Monday}}}
|
||||
st, err := at.GetNextStartTime()
|
||||
if err != nil {
|
||||
@@ -57,13 +57,20 @@ func TestActionTimingOnlyHour(t *testing.T) {
|
||||
}
|
||||
now := time.Now()
|
||||
y, m, d := now.Date()
|
||||
expected := time.Date(y, m, d, 10, 1, 0, 0, time.Local)
|
||||
if !st.Equal(expected) {
|
||||
t.Errorf("Expected %v was %v", expected, st)
|
||||
h, min, s := now.Clock()
|
||||
e := time.Date(y, m, d, h, min, s, 0, time.Local)
|
||||
for _, i := range []int{0, 1, 2, 3, 4, 5, 6} {
|
||||
e = time.Date(e.Year(), e.Month(), e.Day()+i, e.Hour(), e.Minute(), e.Second(), e.Nanosecond(), e.Location())
|
||||
if e.Weekday() == time.Monday {
|
||||
break
|
||||
}
|
||||
}
|
||||
if !st.Equal(e) {
|
||||
t.Errorf("Expected %v was %v", e, st)
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingWeekdaysHour(t *testing.T) {
|
||||
func TestActionTimingHourWeekdays(t *testing.T) {
|
||||
at := &ActionTiming{Timing: &Interval{WeekDays: []time.Weekday{time.Monday}, StartTime: "10:01:00"}}
|
||||
st, err := at.GetNextStartTime()
|
||||
if err != nil {
|
||||
@@ -71,11 +78,17 @@ func TestActionTimingWeekdaysHour(t *testing.T) {
|
||||
}
|
||||
now := time.Now()
|
||||
y, m, d := now.Date()
|
||||
expected := time.Date(y, m, d, 10, 1, 0, 0, time.Local)
|
||||
if !st.Equal(expected) {
|
||||
t.Errorf("Expected %v was %v", expected, st)
|
||||
e := time.Date(y, m, d, 10, 1, 0, 0, time.Local)
|
||||
for _, i := range []int{0, 1, 2, 3, 4, 5, 6} {
|
||||
e = time.Date(e.Year(), e.Month(), e.Day()+i, e.Hour(), e.Minute(), e.Second(), e.Nanosecond(), e.Location())
|
||||
if e.Weekday() == time.Monday {
|
||||
break
|
||||
}
|
||||
}
|
||||
}*/
|
||||
if !st.Equal(e) {
|
||||
t.Errorf("Expected %v was %v", e, st)
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingOnlyMonthdays(t *testing.T) {
|
||||
now := time.Now()
|
||||
|
||||
Reference in New Issue
Block a user