Skip to content

Commit

Permalink
Merge pull request #30 from millotp/main
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore authored Jul 21, 2023
2 parents cef6505 + bed0073 commit 5a6b134
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 5 additions & 4 deletions checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ func (c *SegmentChecker) isOffsetDue(offset string, val, pos int) (bool, error)
return inRange(val, offset, bounds)
}

if !isWeekDay && (val == 0 || offset == "0") {
return offset == "0" && val == 0, nil
}

nval, err := strconv.Atoi(offset)
if err != nil {
return false, err
}

if !isWeekDay && (val == 0 || nval == 0) {
return nval == 0 && val == 0, nil
}

if nval < bounds[0] || nval > bounds[1] {
return false, fmt.Errorf("segment#%d: '%s' out of bounds(%d, %d)", pos, offset, bounds[0], bounds[1])
}
Expand Down
9 changes: 9 additions & 0 deletions gronx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ func TestIsValid(t *testing.T) {
if !gron.IsValid("5,10-20/4,55 * * * *") {
t.Errorf("expected true, got false")
}
if !gron.IsValid("00 * * * *") {
t.Errorf("expected true, got false")
}
if !gron.IsValid("* 00 * * *") {
t.Errorf("expected true, got false")
}
})

t.Run("is not valid", func(t *testing.T) {
Expand Down Expand Up @@ -155,6 +161,9 @@ func testcases() []Case {
{"7-9 * */9 * *", "2015-08-10 22:02:00", false, "2015-08-18 22:07:00"},
{"1 * * * 7", "2015-08-10 21:47:00", false, "2015-08-16 22:01:00"},
{"47 21 * * *", "2015-08-10 21:47:00", true, "2015-08-11 21:47:00"},
{"00 * * * *", "2023-07-21 12:30:00", false, "2023-07-21 13:00:00"},
{"0 00 * * *", "2023-07-21 12:30:00", false, "2023-07-22 00:00:00"},
{"0 000 * * *", "2023-07-21 12:30:00", false, "2023-07-22 00:00:00"},
{"* * * * 0", "2011-06-15 23:09:00", false, "2011-06-19 23:09:00"},
{"* * * * 7", "2011-06-15 23:09:00", false, "2011-06-19 23:09:00"},
{"* * * * 1", "2011-06-15 23:09:00", false, "2011-06-20 23:09:00"},
Expand Down

0 comments on commit 5a6b134

Please sign in to comment.