Skip to content

Commit 8039d1e

Browse files
committed
fix: handle same weekdayFrom and weekdayTo bug
1 parent 09867a9 commit 8039d1e

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

common-lib/timeRangeLib/evaluator.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ 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+
}
3541
fromDateTime := constructDateTime(evaluator.TimeRange.HourMinuteFrom, 0)
3642
toDateTime := constructDateTime(evaluator.TimeRange.HourMinuteTo, days)
3743
return toDateTime.Sub(fromDateTime)

common-lib/timeRangeLib/models.go

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

58+
const daysInWeek = 7
59+
5860
type Frequency string
5961

6062
const (

0 commit comments

Comments
 (0)