Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset seconds to first occurrence when minute/hour changes #91

Merged
merged 1 commit into from
Feb 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions NCrontab.Tests/CrontabScheduleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ public void Formatting(string format, string expression, bool includingSeconds)
[TestCase("01/01/2003 00:00:52", "2/5 * * * * *", "01/01/2003 00:00:57" , true)]
[TestCase("01/01/2003 00:00:57", "2/5 * * * * *", "01/01/2003 00:01:02" , true)]

// See: https://github.com/atifaziz/NCrontab/issues/90
[TestCase("24/02/2021 09:50:35", "* 0-1 10 * * *", "24/02/2021 10:00:00" , true)]

// Minute tests

[TestCase("01/01/2003 00:00:00", "45 * * * *", "01/01/2003 00:45:00", false)]
Expand All @@ -142,6 +145,10 @@ public void Formatting(string format, string expression, bool includingSeconds)
[TestCase("01/01/2003 00:52:00", "2/5 * * * *", "01/01/2003 00:57:00", false)]
[TestCase("01/01/2003 00:57:00", "2/5 * * * *", "01/01/2003 01:02:00", false)]

// See: https://github.com/atifaziz/NCrontab/issues/90
[TestCase("24/02/2021 09:50:35", "* * 10 * * *", "24/02/2021 10:00:00", true)]
[TestCase("24/02/2021 09:50:35", "* 55 * * * *", "24/02/2021 09:55:00", true)]

[TestCase("01/01/2003 00:00:30", "3 45 * * * *", "01/01/2003 00:45:03", true)]

[TestCase("01/01/2003 00:00:30", "6 45-47,48,49 * * * *", "01/01/2003 00:45:06", true)]
Expand Down
6 changes: 6 additions & 0 deletions NCrontab/CrontabSchedule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,14 @@ public IEnumerable<DateTime> GetNextOccurrences(DateTime baseTime, DateTime endT

if (minute == nil)
{
second = seconds.GetFirst();
minute = _minutes.GetFirst();
hour++;
}
else if (minute > baseMinute)
{
second = seconds.GetFirst();
}

//
// Hour
Expand All @@ -271,6 +276,7 @@ public IEnumerable<DateTime> GetNextOccurrences(DateTime baseTime, DateTime endT
}
else if (hour > baseHour)
{
second = seconds.GetFirst();
minute = _minutes.GetFirst();
}

Expand Down