Skip to content

Commit d808a2a

Browse files
committed
Fix range-with-step check for boundary condition (#6)
1 parent 1baceda commit d808a2a

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

gronx_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ func testcases() []Case {
129129
{"0 0 * * 2-7", "2011-06-18 23:09:00", false},
130130
{"0 0 * * 4-7", "2011-07-19 00:00:00", false},
131131
{"0-12/4 * * * *", "2011-06-20 12:04:00", true},
132+
{"0-10/2 * * * *", "2011-06-20 12:12:00", false},
132133
{"4-59/2 * * * *", "2011-06-20 12:04:00", true},
133134
{"4-59/2 * * * *", "2011-06-20 12:06:00", true},
134135
{"4-59/3 * * * *", "2011-06-20 12:06:00", false},

validator.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,12 @@ func inRange(val int, s string) (bool, error) {
5353
}
5454

5555
func inStepRange(val, start, end, step int) bool {
56-
for {
57-
if start == val {
56+
for i := start; i <= end && i <= val; i += step {
57+
if i == val {
5858
return true
5959
}
60-
if start > end {
61-
return false
62-
}
63-
64-
start += step
6560
}
61+
return false
6662
}
6763

6864
func isValidMonthDay(val string, last int, ref time.Time) (bool, error) {

0 commit comments

Comments
 (0)