From bed00730c462042ab01224890f37562e9013356b Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Fri, 21 Jul 2023 09:10:14 +0200 Subject: [PATCH] fix: allow leading zero for NextTick --- checker.go | 9 +++++---- gronx_test.go | 9 +++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/checker.go b/checker.go index 78fd0cc..789570d 100644 --- a/checker.go +++ b/checker.go @@ -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]) } diff --git a/gronx_test.go b/gronx_test.go index 58e2d5e..580d3c4 100644 --- a/gronx_test.go +++ b/gronx_test.go @@ -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) { @@ -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"},