diff --git a/cron_test.go b/cron_test.go index 6c5bdc3..093f904 100644 --- a/cron_test.go +++ b/cron_test.go @@ -23,11 +23,12 @@ func TestSchedule_Next(t *testing.T) { {"* * 2 * * *", time.Date(2000, time.March, 16, 2, 0, 0, 0, time.UTC)}, {"* * 10-13 * * *", time.Date(2000, time.March, 15, 12, 5, 2, 0, time.UTC)}, {"* * 2,13 * * *", time.Date(2000, time.March, 15, 13, 0, 0, 0, time.UTC)}, - {"* * * 31 7 *", time.Date(2000, time.July, 31, 0, 0, 0, 0, time.UTC)}, + {"* * * 31 4-7 *", time.Date(2000, time.May, 31, 0, 0, 0, 0, time.UTC)}, {"* * * 14 3,5 *", time.Date(2000, time.May, 14, 0, 0, 0, 0, time.UTC)}, {"* * * * 1-2 *", time.Date(2001, time.January, 1, 0, 0, 0, 0, time.UTC)}, {"* * * L * *", time.Date(2000, time.March, 31, 0, 0, 0, 0, time.UTC)}, {"* * * 1,L 4 *", time.Date(2000, time.April, 1, 0, 0, 0, 0, time.UTC)}, + {"* * * 20-L 4 *", time.Date(2000, time.April, 20, 0, 0, 0, 0, time.UTC)}, {"* * * 1 12 SUN", time.Date(2002, time.December, 1, 0, 0, 0, 0, time.UTC)}, {"* * * 1 12 0", time.Date(2002, time.December, 1, 0, 0, 0, 0, time.UTC)}, {"* * * 1 12 SUN,FRI", time.Date(2000, time.December, 1, 0, 0, 0, 0, time.UTC)}, diff --git a/parser.go b/parser.go index e1965fd..afd467f 100644 --- a/parser.go +++ b/parser.go @@ -92,18 +92,15 @@ func (Parser) parse(expr string, convFn ConvertFn) (fields []ExprField, err erro func parseRange(expr string, convFn ConvertFn) (r Range, err error) { parts := strings.Split(expr, "-") - from, err := convFn(parts[0]) + r.from, err = convFn(parts[0]) if err != nil { return } - to, err := convFn(parts[1]) + r.to, err = convFn(parts[1]) if err != nil { return } - r.from = from.Value(time.Time{}) - r.to = to.Value(time.Time{}) - return } @@ -259,23 +256,23 @@ func (u Unit) Value(_ time.Time) int { } type Range struct { - from int - to int + from ExprField + to ExprField } -func (r Range) Compare(_ time.Time, other int) Ordering { +func (r Range) Compare(t time.Time, other int) Ordering { switch { - case r.to < other: + case r.to.Compare(t, other) == OrderingLess: return OrderingLess - case r.from > other: + case r.from.Compare(t, other) == OrderingGreater: return OrderingGreater default: return OrderingEqual } } -func (r Range) Value(_ time.Time) int { - return r.from +func (r Range) Value(t time.Time) int { + return r.from.Value(t) } type LastDayOfMonth struct{}