fix: correct calculate next occurrence
Some checks failed
.NET Test Pipeline / build (pull_request) Failing after 44s
Some checks failed
.NET Test Pipeline / build (pull_request) Failing after 44s
This commit is contained in:
@ -45,32 +45,31 @@ public static class CronUpdateSkipService
|
|||||||
if (depth <= 0)
|
if (depth <= 0)
|
||||||
return [];
|
return [];
|
||||||
|
|
||||||
currentDate ??= DateOnly.FromDateTime(DateTime.Now);
|
DateTimeOffset nextRunTime = (currentDate?.ToDateTime(TimeOnly.MinValue) ?? DateTime.Now).ToUniversalTime();
|
||||||
DateTimeOffset nextRunTime = currentDate.Value.ToDateTime(TimeOnly.FromDateTime(DateTime.Now));
|
|
||||||
|
|
||||||
List<DateTimeOffset> result = [];
|
List<DateTimeOffset> result = [];
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
var lastSkip = data.FilterDateEntry(nextRunTime.DateTime).LastOrDefault();
|
var lastSkippedEntry = data.FilterDateEntry(nextRunTime.DateTime).LastOrDefault();
|
||||||
|
|
||||||
if (lastSkip is { Start: not null, End: not null })
|
if (lastSkippedEntry is { Start: not null, End: not null })
|
||||||
nextRunTime = new DateTimeOffset(lastSkip.End.Value.AddDays(1), new TimeOnly(0, 0, 0), TimeSpan.Zero);
|
nextRunTime = lastSkippedEntry.End.Value.ToDateTime(TimeOnly.MinValue).AddDays(1);
|
||||||
else if (lastSkip.Date.HasValue)
|
else if (lastSkippedEntry.Date.HasValue)
|
||||||
nextRunTime = new DateTimeOffset(lastSkip.Date.Value.AddDays(1), new TimeOnly(0, 0, 0), TimeSpan.Zero);
|
nextRunTime = lastSkippedEntry.Date.Value.ToDateTime(TimeOnly.MinValue).AddDays(1);
|
||||||
|
|
||||||
var next = expression.GetNextOccurrence(nextRunTime.ToUniversalTime(), TimeZoneInfo.Local);
|
var nextOccurrence = expression.GetNextOccurrence(nextRunTime.AddMinutes(-1), TimeZoneInfo.Local);
|
||||||
|
|
||||||
if (!next.HasValue)
|
if (!nextOccurrence.HasValue)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
nextRunTime = next.Value;
|
if (data.FilterDateEntry(nextOccurrence.Value.DateTime).Count != 0)
|
||||||
|
{
|
||||||
if (data.FilterDateEntry(nextRunTime.DateTime).Any())
|
nextRunTime = nextOccurrence.Value.AddDays(1);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
result.Add(nextRunTime);
|
result.Add(nextOccurrence.Value.ToLocalTime());
|
||||||
nextRunTime = nextRunTime.AddMinutes(1);
|
nextRunTime = nextOccurrence.Value.AddMinutes(1);
|
||||||
|
|
||||||
} while (result.Count < depth);
|
} while (result.Count < depth);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user