Skip to content

Commit

Permalink
Fix seconds to reset to first occurrence on minute/hour changes
Browse files Browse the repository at this point in the history
This is a squashed merge of PR #91 that closes #90.
  • Loading branch information
atifaziz committed Feb 28, 2021
1 parent 4396e72 commit c6e4728
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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 @@ -255,9 +255,14 @@ public DateTime GetNextOccurrence(DateTime baseTime, DateTime endTime)

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

//
// Hour
Expand All @@ -273,6 +278,7 @@ public DateTime GetNextOccurrence(DateTime baseTime, DateTime endTime)
}
else if (hour > baseHour)
{
second = seconds.GetFirst();
minute = _minutes.GetFirst();
}

Expand Down

0 comments on commit c6e4728

Please sign in to comment.