fix: Changes EventScheduler API so it is more explicit (#2164)
### Summary
Refactors ScheduledEvent and EventScheduler API to use TimeOnly so recurrence offset is explicit.
API:
```cs
public ScheduledEvent(
DateTime startAfter,
DateTime endOn,
TimeOnly time,
IRecurrencePattern recurrence,
TimeZoneInfo timeZone = null
)
```
Example:
```cs
// Schedule a daily event at 8:00 AM UTC
EventScheduler.DailyAt(
new DateTime(2024, 6, 1, 8, 0, 0, DateTimeKind.Utc),
() => Console.WriteLine("Daily event triggered!")
);
// Schedule a custom recurring event at 3:30 PM UTC every Monday
var recurrence = new WeeklyRecurrencePattern(1, DaysOfWeek.Monday);
EventScheduler.Shared.ScheduleEvent(
DateTime.UtcNow,
new TimeOnly(15, 30),
() => Console.WriteLine("Weekly Monday event!"),
recurrence
);
```
This commit is contained in:
parent
f89b2be653
commit
21a4092dd8
7 changed files with 495 additions and 250 deletions
|
|
@ -1471,12 +1471,6 @@ public static partial class Utility
|
|||
|
||||
public static DateTime LocalToUtc(this DateTime local, TimeZoneInfo tz)
|
||||
{
|
||||
if (tz.IsInvalidTime(local))
|
||||
{
|
||||
// For hourly recurrence, just subtract the standard offset (simulate as if the time exists)
|
||||
return DateTime.SpecifyKind(local - tz.BaseUtcOffset, DateTimeKind.Utc);
|
||||
}
|
||||
|
||||
if (tz.IsAmbiguousTime(local))
|
||||
{
|
||||
var offsets = tz.GetAmbiguousTimeOffsets(local);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue