diff --git a/next.go b/next.go index 3643374..a99ddcc 100644 --- a/next.go +++ b/next.go @@ -141,7 +141,7 @@ func isUnreachableYear(year string, ref time.Time, incl bool, reverse bool) bool } for _, part := range strings.Split(dashRe.ReplaceAllString(offset, ""), "-") { val, err := strconv.Atoi(part) - if err != nil || (!reverse && val >= edge) || (reverse && val < edge) { + if err != nil || (!reverse && val >= edge) || (reverse && val <= edge) { return false } } diff --git a/next_test.go b/next_test.go index a45591d..51a746c 100644 --- a/next_test.go +++ b/next_test.go @@ -72,3 +72,18 @@ func TestNextTickAfter(t *testing.T) { } }) } + +// https://github.com/adhocore/gronx/issues/51 +func TestIsUnreachableYearCurrentYear(t *testing.T) { + now := time.Date(2024, time.November, 8, 22, 18, 16, 0, time.UTC) + + cronExpr := "30 15 4 11 * 2024" + expectedTime := time.Date(2024, time.November, 4, 15, 30, 0, 0, time.UTC) + actualTime, err := PrevTickBefore(cronExpr, now, true) + + if err != nil { + t.Errorf("got unexpected error: %s", err) + } else if !actualTime.Equal(expectedTime) { + t.Errorf("expected previous tick to be %v, got %v", expectedTime, actualTime) + } +}