Skip to content

Commit 7412a54

Browse files
committed
fix: reject zero/negative-length WeeklyRange window
1 parent 8039d1e commit 7412a54

4 files changed

Lines changed: 6 additions & 9 deletions

File tree

common-lib/timeRangeLib/constant.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const (
2828
WeekDaysNotPresent ErrorMessage = "weekdays, must be present for Weekly frequency"
2929
WeekDayFromOrToNotPresent ErrorMessage = "weekdayFrom, must be present for WeeklyRange frequency"
3030
DayFromOrToNotPresent ErrorMessage = "dayFrom, dayTo, must be present for Monthly frequency"
31-
ToBeforeFrom ErrorMessage = "Invalid value of hourMinuteFrom or hourMinuteTo for same day ,hourMinuteFrom >hourMinuteTo"
31+
ToBeforeFrom ErrorMessage = "Invalid value of hourMinuteFrom or hourMinuteTo for same day ,hourMinuteFrom > hourMinuteTo"
3232
BothLessThanZeroAndFromGreaterThanTo ErrorMessage = "invalid value of DayFrom or DayTo,DayFrom and DayTo is less than zero and dayFrom > dayTo"
3333
DayFromOrToNotValid ErrorMessage = "invalid value of dayFrom or dayTo"
3434
InvalidHourMinuteForWeeklyAndDaily ErrorMessage = "HourMinuteFrom should be less than HourMinuteTo in daily or weekly Frequency"

common-lib/timeRangeLib/evaluator.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ func (evaluator BaseTimeRangeExpressionEvaluator) getDurationForHourMinute() tim
3232

3333
func (evaluator BaseTimeRangeExpressionEvaluator) getDurationBetweenWeekdays() time.Duration {
3434
days := calculateDaysBetweenWeekdays(int(evaluator.TimeRange.WeekdayFrom), int(evaluator.TimeRange.WeekdayTo))
35-
// When weekdayFrom == weekdayTo, days is 0. If the to-time is not after the from-time the window
36-
// would collapse to a zero/negative duration, which stalls the next-window search (infinite loop).
37-
// Treat such a same-weekday range as spanning the full week instead.
38-
if days == 0 && isToBeforeFrom(evaluator.TimeRange.HourMinuteFrom, evaluator.TimeRange.HourMinuteTo) {
39-
days = daysInWeek
40-
}
4135
fromDateTime := constructDateTime(evaluator.TimeRange.HourMinuteFrom, 0)
4236
toDateTime := constructDateTime(evaluator.TimeRange.HourMinuteTo, days)
4337
return toDateTime.Sub(fromDateTime)

common-lib/timeRangeLib/models.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ type TimeRange struct {
5555
// random values for for understanding HH:MM format
5656
const hourMinuteFormat = "15:04"
5757

58-
const daysInWeek = 7
59-
6058
type Frequency string
6159

6260
const (

common-lib/timeRangeLib/validator.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ func (tr TimeRange) ValidateTimeRange() error {
8686
if (tr.WeekdayFrom < 0 || tr.WeekdayFrom > 6) || (tr.WeekdayTo < 0 || tr.WeekdayTo > 6) {
8787
return errors.New(string(WeekDayOutsideRange))
8888
}
89+
// Same weekday with a non-positive intra-day span collapses the window to zero/negative
90+
// duration, which stalls the next-window search. Reject it (mirrors the Monthly check).
91+
if tr.WeekdayFrom == tr.WeekdayTo && isToBeforeFrom(tr.HourMinuteFrom, tr.HourMinuteTo) {
92+
return errors.New(string(ToBeforeFrom))
93+
}
8994
case Monthly:
9095
if tr.DayFrom == 0 || tr.DayTo == 0 {
9196
return errors.New(string(DayFromOrToNotPresent))

0 commit comments

Comments
 (0)