From 47b724dd364935ad8f6b1e23e2917bd03a139dda Mon Sep 17 00:00:00 2001 From: Jitendra Adhikari Date: Sun, 10 Nov 2024 17:34:31 +0545 Subject: [PATCH] fix: unreachable yer #51 --- next.go | 2 +- next_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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) + } +}