From 1c56081e0027a04fff73faab025dbb4f96dd2dc4 Mon Sep 17 00:00:00 2001 From: gorhill Date: Fri, 30 Aug 2013 07:36:30 -0400 Subject: [PATCH] fleshing out --- cronexpression.go | 4 ++-- cronexpression_test.go | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/cronexpression.go b/cronexpression.go index 2cb6574..b64eb00 100644 --- a/cronexpression.go +++ b/cronexpression.go @@ -604,7 +604,7 @@ func (cronexpr *CronExpression) dayofmonthFieldParse(cronField string) error { cronexpr.daysOfMonth = make(map[int]bool) // days of month map cronexpr.workdaysOfMonth = make(map[int]bool) // work day of month map - // "You can also mix all of the above, as in: 1-5,10,12,20-30/5" + // Comma separator is used to mix different allowed syntax cronList := strings.Split(cronField, ",") for _, s := range cronList { // "/" @@ -651,7 +651,7 @@ func genericFieldParse(cronField string, min, max int) []int { // Defaults values := make(map[int]bool) - // "You can also mix all of the above, as in: 1-5,10,12,20-30/5" + // Comma separator is used to mix different allowed syntax cronList := strings.Split(cronField, ",") for _, s := range cronList { // "/" diff --git a/cronexpression_test.go b/cronexpression_test.go index 002e0db..5501baa 100644 --- a/cronexpression_test.go +++ b/cronexpression_test.go @@ -39,6 +39,7 @@ var crontests = []crontest{ []crontimes{ {"2013-01-01 00:00:00", "2013-01-01 00:00:01"}, {"2013-01-01 00:00:59", "2013-01-01 00:01:00"}, + {"2013-01-01 00:59:59", "2013-01-01 01:00:00"}, {"2013-01-01 23:59:59", "2013-01-02 00:00:00"}, {"2013-02-28 23:59:59", "2013-03-01 00:00:00"}, {"2016-02-28 23:59:59", "2016-02-29 00:00:00"}, @@ -61,7 +62,7 @@ var crontests = []crontest{ }, }, - // Minutes with intervals + // Minutes with interval { "17-43/5 * * * *", "2006-01-02 15:04:05", @@ -89,10 +90,22 @@ var crontests = []crontest{ {"2013-01-01 23:55:00", "2013-01-02 00:15:00"}, {"2013-02-28 23:55:00", "2013-03-01 00:15:00"}, {"2016-02-28 23:55:00", "2016-02-29 00:15:00"}, + {"2012-12-31 23:54:00", "2012-12-31 23:55:00"}, {"2012-12-31 23:55:00", "2013-01-01 00:15:00"}, }, }, + // Days of week + { + "0 0 * * MON", + "MON 2006-01-02 15:04", + []crontimes{ + {"2013-01-01 00:00:00", "MON 2013-01-07 00:00"}, + {"2013-01-28 00:00:00", "MON 2013-02-04 00:00"}, + {"2013-12-30 00:30:00", "MON 2014-01-06 00:00"}, + }, + }, + // TODO: more tests } @@ -101,8 +114,9 @@ func TestCronExpressions(t *testing.T) { for _, times := range test.times { from, _ := time.Parse("2006-01-02 15:04:05", times.from) next := cronexpression.NextTimeFromCronString(test.expr, from) - if next.Format(test.layout) != times.next { - t.Errorf("(\"%s\").NextTime(\"%s\") = \"%s\", got \"%s\"", test.expr, times.from, times.next, next.Format(test.layout)) + nextstr := next.Format(test.layout) + if nextstr != times.next { + t.Errorf("(\"%s\").NextTime(\"%s\") = \"%s\", got \"%s\"", test.expr, times.from, times.next, nextstr) } } }