From 42e97a3017e8ee67d3312f03033ab16071fe0371 Mon Sep 17 00:00:00 2001 From: gerrod Date: Wed, 16 May 2018 14:24:38 +1000 Subject: [PATCH] Correctly roll over from 58 to 59 minutes/seconds --- NCrontab.Advanced.Tests/CronInstanceTests.cs | 8 ++++++++ NCrontab.Advanced/Filters/AnyFilter.cs | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/NCrontab.Advanced.Tests/CronInstanceTests.cs b/NCrontab.Advanced.Tests/CronInstanceTests.cs index 5c44698..68c900f 100644 --- a/NCrontab.Advanced.Tests/CronInstanceTests.cs +++ b/NCrontab.Advanced.Tests/CronInstanceTests.cs @@ -160,6 +160,8 @@ public void Evaluations() new { startTime = "01/01/2003 00:00:00", inputString = "* * * * *", nextOccurence = "01/01/2003 00:01:00", cronStringFormat = CronStringFormat.Default }, new { startTime = "01/01/2003 00:01:00", inputString = "* * * * *", nextOccurence = "01/01/2003 00:02:00", cronStringFormat = CronStringFormat.Default }, new { startTime = "01/01/2003 00:02:00", inputString = "* * * * *", nextOccurence = "01/01/2003 00:03:00", cronStringFormat = CronStringFormat.Default }, + new { startTime = "01/01/2003 00:58:00", inputString = "* * * * *", nextOccurence = "01/01/2003 00:59:00", cronStringFormat = CronStringFormat.Default }, + new { startTime = "01/01/2003 01:58:00", inputString = "* * * * *", nextOccurence = "01/01/2003 01:59:00", cronStringFormat = CronStringFormat.Default }, new { startTime = "01/01/2003 00:59:00", inputString = "* * * * *", nextOccurence = "01/01/2003 01:00:00", cronStringFormat = CronStringFormat.Default }, new { startTime = "01/01/2003 01:59:00", inputString = "* * * * *", nextOccurence = "01/01/2003 02:00:00", cronStringFormat = CronStringFormat.Default }, new { startTime = "01/01/2003 23:59:00", inputString = "* * * * *", nextOccurence = "02/01/2003 00:00:00", cronStringFormat = CronStringFormat.Default }, @@ -170,6 +172,8 @@ public void Evaluations() new { startTime = "01/01/2003 00:00:00", inputString = "* * * * * *", nextOccurence = "01/01/2003 00:00:01", cronStringFormat = CronStringFormat.WithSeconds }, new { startTime = "01/01/2003 00:00:01", inputString = "* * * * * *", nextOccurence = "01/01/2003 00:00:02", cronStringFormat = CronStringFormat.WithSeconds }, new { startTime = "01/01/2003 00:00:02", inputString = "* * * * * *", nextOccurence = "01/01/2003 00:00:03", cronStringFormat = CronStringFormat.WithSeconds }, + new { startTime = "01/01/2003 00:00:58", inputString = "* * * * * *", nextOccurence = "01/01/2003 00:00:59", cronStringFormat = CronStringFormat.WithSeconds }, + new { startTime = "01/01/2003 00:01:58", inputString = "* * * * * *", nextOccurence = "01/01/2003 00:01:59", cronStringFormat = CronStringFormat.WithSeconds }, new { startTime = "01/01/2003 00:00:59", inputString = "* * * * * *", nextOccurence = "01/01/2003 00:01:00", cronStringFormat = CronStringFormat.WithSeconds }, new { startTime = "01/01/2003 00:01:59", inputString = "* * * * * *", nextOccurence = "01/01/2003 00:02:00", cronStringFormat = CronStringFormat.WithSeconds }, new { startTime = "01/01/2003 23:59:59", inputString = "* * * * * *", nextOccurence = "02/01/2003 00:00:00", cronStringFormat = CronStringFormat.WithSeconds }, @@ -180,6 +184,8 @@ public void Evaluations() new { startTime = "01/01/2003 00:00:00", inputString = "* * * * * *", nextOccurence = "01/01/2003 00:01:00", cronStringFormat = CronStringFormat.WithYears }, new { startTime = "01/01/2003 00:01:00", inputString = "* * * * * *", nextOccurence = "01/01/2003 00:02:00", cronStringFormat = CronStringFormat.WithYears }, new { startTime = "01/01/2003 00:02:00", inputString = "* * * * * *", nextOccurence = "01/01/2003 00:03:00", cronStringFormat = CronStringFormat.WithYears }, + new { startTime = "01/01/2003 00:58:00", inputString = "* * * * * *", nextOccurence = "01/01/2003 00:59:00", cronStringFormat = CronStringFormat.WithYears }, + new { startTime = "01/01/2003 01:58:00", inputString = "* * * * * *", nextOccurence = "01/01/2003 01:59:00", cronStringFormat = CronStringFormat.WithYears }, new { startTime = "01/01/2003 00:59:00", inputString = "* * * * * *", nextOccurence = "01/01/2003 01:00:00", cronStringFormat = CronStringFormat.WithYears }, new { startTime = "01/01/2003 01:59:00", inputString = "* * * * * *", nextOccurence = "01/01/2003 02:00:00", cronStringFormat = CronStringFormat.WithYears }, new { startTime = "01/01/2003 23:59:00", inputString = "* * * * * *", nextOccurence = "02/01/2003 00:00:00", cronStringFormat = CronStringFormat.WithYears }, @@ -190,6 +196,8 @@ public void Evaluations() new { startTime = "01/01/2003 00:00:00", inputString = "* * * * * * *", nextOccurence = "01/01/2003 00:00:01", cronStringFormat = CronStringFormat.WithSecondsAndYears }, new { startTime = "01/01/2003 00:00:01", inputString = "* * * * * * *", nextOccurence = "01/01/2003 00:00:02", cronStringFormat = CronStringFormat.WithSecondsAndYears }, new { startTime = "01/01/2003 00:00:02", inputString = "* * * * * * *", nextOccurence = "01/01/2003 00:00:03", cronStringFormat = CronStringFormat.WithSecondsAndYears }, + new { startTime = "01/01/2003 00:00:58", inputString = "* * * * * * *", nextOccurence = "01/01/2003 00:00:59", cronStringFormat = CronStringFormat.WithSecondsAndYears }, + new { startTime = "01/01/2003 00:01:58", inputString = "* * * * * * *", nextOccurence = "01/01/2003 00:01:59", cronStringFormat = CronStringFormat.WithSecondsAndYears }, new { startTime = "01/01/2003 00:00:59", inputString = "* * * * * * *", nextOccurence = "01/01/2003 00:01:00", cronStringFormat = CronStringFormat.WithSecondsAndYears }, new { startTime = "01/01/2003 00:01:59", inputString = "* * * * * * *", nextOccurence = "01/01/2003 00:02:00", cronStringFormat = CronStringFormat.WithSecondsAndYears }, new { startTime = "01/01/2003 23:59:59", inputString = "* * * * * * *", nextOccurence = "02/01/2003 00:00:00", cronStringFormat = CronStringFormat.WithSecondsAndYears }, diff --git a/NCrontab.Advanced/Filters/AnyFilter.cs b/NCrontab.Advanced/Filters/AnyFilter.cs index 3de7efb..6e514bd 100644 --- a/NCrontab.Advanced/Filters/AnyFilter.cs +++ b/NCrontab.Advanced/Filters/AnyFilter.cs @@ -41,7 +41,7 @@ public bool IsMatch(DateTime value) throw new CrontabException("Cannot call Next for Day, Month or DayOfWeek types"); var newValue = (int?) value + 1; - if (newValue >= max) newValue = null; + if (newValue > max) newValue = null; return newValue; }