From feca8366e8fcab555b61fdc310dcf8b6d185c762 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Thu, 7 May 2020 17:26:42 -0400 Subject: [PATCH] Added handling for day-of-week spans that end in seven Authored by Paul Kirby in https://github.com/gorhill/cronexpr/pull/12 --- cronexpr_parse.go | 4 ++++ cronexpr_test.go | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/cronexpr_parse.go b/cronexpr_parse.go index a9fe746..a7f8fe0 100644 --- a/cronexpr_parse.go +++ b/cronexpr_parse.go @@ -319,6 +319,10 @@ func (expr *Expression) dowFieldHandler(s string) error { case one: populateOne(expr.daysOfWeek, directive.first) case span: + // To properly handle spans that end in 7 (Sunday) + if directive.last == 0 { + directive.last = 6 + } populateMany(expr.daysOfWeek, directive.first, directive.last, directive.step) case all: populateMany(expr.daysOfWeek, directive.first, directive.last, directive.step) diff --git a/cronexpr_test.go b/cronexpr_test.go index 939aea4..664fb25 100644 --- a/cronexpr_test.go +++ b/cronexpr_test.go @@ -143,6 +143,15 @@ var crontests = []crontest{ {"2013-12-30 00:30:00", "Sat 2014-01-04 00:00"}, }, }, + { + "0 0 * * 5-7", + "Mon 2006-01-02 15:04", + []crontimes{ + {"2013-01-01 00:00:00", "Fri 2013-01-04 00:00"}, + {"2013-01-28 00:00:00", "Fri 2013-02-01 00:00"}, + {"2013-12-30 00:30:00", "Fri 2014-01-03 00:00"}, + }, + }, // Specific days of week {