diff --git a/checker.go b/checker.go index f008faa..5cae233 100644 --- a/checker.go +++ b/checker.go @@ -126,7 +126,7 @@ func boundsByPos(pos int) (bounds []int) { case 5: bounds = []int{0, 7} case 6: - bounds = []int{1, 9999} + bounds = []int{0, 9999} } return } diff --git a/gronx_test.go b/gronx_test.go index 183c0b0..894536f 100644 --- a/gronx_test.go +++ b/gronx_test.go @@ -190,7 +190,8 @@ func testcases() []Case { {"* 20,21,22 * * *", "2015-08-10 21:50:00", true, "2015-08-10 21:51:00"}, {"* 20,22 * * *", "2015-08-10 21:50:00", false, "2015-08-10 22:00:00"}, {"* 5,21-22 * * *", "2015-08-10 21:50:00", true, "2015-08-10 21:51:00"}, - {"7-9 * */9 * *", "2015-08-10 22:02:00", false, "2015-08-18 00:07:00"}, + {"7-9 * */9 * *", "2015-08-10 22:02:00", false, "2015-08-10 22:07:00"}, + {"7-9 * */9 * *", "2015-08-11 22:02:00", false, "2015-08-19 00:07:00"}, {"1 * * * 7", "2015-08-10 21:47:00", false, "2015-08-16 00: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"}, diff --git a/next.go b/next.go index 646ad37..78d5142 100644 --- a/next.go +++ b/next.go @@ -61,7 +61,7 @@ over: if reverse { delta = -time.Second } - next, _, err = bumpUntilDue(gron.C, segments[0], 0, next.Add(delta), reverse) + next = next.Add(delta) continue } return @@ -118,6 +118,7 @@ func bump(ref time.Time, pos int, reverse bool) time.Time { if reverse { factor = -1 } + loc := ref.Location() switch pos { case 0: @@ -125,37 +126,37 @@ func bump(ref time.Time, pos int, reverse bool) time.Time { case 1: minTime := ref.Add(time.Duration(factor) * time.Minute) if reverse { - ref = time.Date(minTime.Year(), minTime.Month(), minTime.Day(), minTime.Hour(), minTime.Minute(), 59, 0, minTime.Location()) + ref = time.Date(minTime.Year(), minTime.Month(), minTime.Day(), minTime.Hour(), minTime.Minute(), 59, 0, loc) } else { - ref = time.Date(minTime.Year(), minTime.Month(), minTime.Day(), minTime.Hour(), minTime.Minute(), 0, 0, minTime.Location()) + ref = time.Date(minTime.Year(), minTime.Month(), minTime.Day(), minTime.Hour(), minTime.Minute(), 0, 0, loc) } case 2: hTime := ref.Add(time.Duration(factor) * time.Hour) if reverse { - ref = time.Date(hTime.Year(), hTime.Month(), hTime.Day(), hTime.Hour(), 59, 59, 0, hTime.Location()) + ref = time.Date(hTime.Year(), hTime.Month(), hTime.Day(), hTime.Hour(), 59, 59, 0, loc) } else { - ref = time.Date(hTime.Year(), hTime.Month(), hTime.Day(), hTime.Hour(), 0, 0, 0, hTime.Location()) + ref = time.Date(hTime.Year(), hTime.Month(), hTime.Day(), hTime.Hour(), 0, 0, 0, loc) } case 3, 5: dTime := ref.AddDate(0, 0, factor) if reverse { - ref = time.Date(dTime.Year(), dTime.Month(), dTime.Day(), 23, 59, 59, 0, dTime.Location()) + ref = time.Date(dTime.Year(), dTime.Month(), dTime.Day(), 23, 59, 59, 0, loc) } else { - ref = time.Date(dTime.Year(), dTime.Month(), dTime.Day(), 0, 0, 0, 0, dTime.Location()) + ref = time.Date(dTime.Year(), dTime.Month(), dTime.Day(), 0, 0, 0, 0, loc) } case 4: - mTime := ref.AddDate(0, factor, 0) + ref = time.Date(ref.Year(), ref.Month(), 1, 0, 0, 0, 0, loc) if reverse { - ref = time.Date(mTime.Year(), ref.Month(), -1, 23, 59, 59, 0, mTime.Location()) + ref = ref.Add(time.Duration(factor) * time.Second) } else { - ref = time.Date(mTime.Year(), mTime.Month(), 1, 0, 0, 0, 0, mTime.Location()) + ref = ref.AddDate(0, factor, 0) } case 6: yTime := ref.AddDate(factor, 0, 0) if reverse { - ref = time.Date(yTime.Year(), 12, 31, 23, 59, 59, 0, yTime.Location()) + ref = time.Date(yTime.Year(), 12, 31, 23, 59, 59, 0, loc) } else { - ref = time.Date(yTime.Year(), 1, 1, 0, 0, 0, 0, yTime.Location()) + ref = time.Date(yTime.Year(), 1, 1, 0, 0, 0, 0, loc) } } return ref diff --git a/validator.go b/validator.go index 0cf44fc..523e8f2 100644 --- a/validator.go +++ b/validator.go @@ -18,7 +18,10 @@ func inStep(val int, s string, bounds []int) (bool, error) { return false, errors.New("step can't be 0") } - if strings.Index(s, "*/") == 0 || strings.Index(s, "0/") == 0 { + if strings.Index(s, "*/") == 0 { + return (val-bounds[0])%step == 0, nil + } + if strings.Index(s, "0/") == 0 { return val%step == 0, nil }