Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,23 @@ public static IEnumerable<object[]> GetNextDayOfWeekData()
new DateTime ?[] { new DateTime(2021, 03, 20, 0, 0, 0, 0) }
};
}

[TestMethod]
public void WeeklyValueNotReturnedWhenDaylightsavingChanges()
{
var now = new DateTimeOffset(new DateTime(2024, 10, 23, 10, 27, 0), new TimeSpan(0, 0, 0));
var expected = new DateTimeOffset(new DateTime(2024, 10, 30, 9, 0, 0), new TimeSpan(2, 0, 0));

var trigger = new WeeklyTrigger()
{
TriggerTimes = new List<TimeSpan>()
{
new TimeSpan(9, 0, 0)
},
TriggerDays = new List<DayOfWeek>() { DayOfWeek.Wednesday }
};
var execution = trigger.GetNextExecution(now, TimeZoneInfo.FindSystemTimeZoneById("FLE Standard Time"));
Assert.AreEqual(expected.ToUniversalTime(), execution?.ToUniversalTime());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public DailyTrigger()
timeZoneInfo = timeZoneInfo ?? TimeZoneInfo.Local;

// When should we start looking?
var before = after.Value;
after = (after ?? DateTime.UtcNow).ToUniversalTime();

// Convert the time into the timezone we're after.
Expand All @@ -73,7 +74,12 @@ public DailyTrigger()
// What is the potential time that this will run?
DateTimeOffset potential;
{
var dateTime = after.Value.Date.Add(t);
// If the timezone conversion changed the date then go back to the start of the date.
var date = after.Value.Date;
if (after.Value.Date != before.Date)
date = new DateTime(before.Date.Ticks);

var dateTime = date.Add(t);
potential = new DateTimeOffset(dateTime, timeZoneInfo.GetUtcOffset(dateTime));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ public class Schedule
}

// Get the next execution date from the triggers.
return this.Triggers?
var next = this.Triggers?
.Select(t => t.GetNextExecution(after, timeZoneInfo))
.Where(d => d.HasValue)
.OrderBy(d => d)
.FirstOrDefault();
.Where(d => d.HasValue && d.Value.DateTime != DateTime.MinValue)
.OrderBy(d => d);
return next.Any() ? next.First() : null;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,12 @@ public WeeklyTrigger()
.Select(d => d.Value)
.Where(d => d > after.Value)
.OrderBy(d => d)
.Select(d => d.ToUniversalTime())
.ToList();

this.Logger?.Trace($"These are the potential matches: {string.Join(", ", potentialMatches)}");

return potentialMatches
.Select(d => d.ToUniversalTime())
.FirstOrDefault();
return potentialMatches.Any() ? (DateTimeOffset?)potentialMatches.First() : null;
}

/// <summary>
Expand Down
Loading