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)
|
||||
return [];
|
||||
|
||||
currentDate ??= DateOnly.FromDateTime(DateTime.Now);
|
||||
DateTimeOffset nextRunTime = currentDate.Value.ToDateTime(TimeOnly.FromDateTime(DateTime.Now));
|
||||
|
||||
DateTimeOffset nextRunTime = (currentDate?.ToDateTime(TimeOnly.MinValue) ?? DateTime.Now).ToUniversalTime();
|
||||
List<DateTimeOffset> result = [];
|
||||
|
||||
do
|
||||
{
|
||||
var lastSkip = data.FilterDateEntry(nextRunTime.DateTime).LastOrDefault();
|
||||
var lastSkippedEntry = data.FilterDateEntry(nextRunTime.DateTime).LastOrDefault();
|
||||
|
||||
if (lastSkip is { Start: not null, End: not null })
|
||||
nextRunTime = new DateTimeOffset(lastSkip.End.Value.AddDays(1), new TimeOnly(0, 0, 0), TimeSpan.Zero);
|
||||
else if (lastSkip.Date.HasValue)
|
||||
nextRunTime = new DateTimeOffset(lastSkip.Date.Value.AddDays(1), new TimeOnly(0, 0, 0), TimeSpan.Zero);
|
||||
if (lastSkippedEntry is { Start: not null, End: not null })
|
||||
nextRunTime = lastSkippedEntry.End.Value.ToDateTime(TimeOnly.MinValue).AddDays(1);
|
||||
else if (lastSkippedEntry.Date.HasValue)
|
||||
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;
|
||||
|
||||
nextRunTime = next.Value;
|
||||
|
||||
if (data.FilterDateEntry(nextRunTime.DateTime).Any())
|
||||
if (data.FilterDateEntry(nextOccurrence.Value.DateTime).Count != 0)
|
||||
{
|
||||
nextRunTime = nextOccurrence.Value.AddDays(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
result.Add(nextRunTime);
|
||||
nextRunTime = nextRunTime.AddMinutes(1);
|
||||
result.Add(nextOccurrence.Value.ToLocalTime());
|
||||
nextRunTime = nextOccurrence.Value.AddMinutes(1);
|
||||
|
||||
} while (result.Count < depth);
|
||||
|
||||
|
Reference in New Issue
Block a user