HangfireIO / HangfireIO/Cronos
GetNextOccurrence calculated incorrect when switching from DST
- Dominant language
- C#
- Stars
- 1.2k
- Forks
- 137
- Avg merge
- 5d 11h
- Merged PRs (30d)
- 1
Description
Hello there!
This issue was initially spotted using Hangfire jobs scheduler, but I managed to investigate it to the following point:
So, imagine we have a cron `0 0 2 * * 0` (run at 2:00 each Sunday) and a specific time zone W. Europe Standard Time (supports DST, UTC+1 when non-DST, UTC+2 when DST). And Sunday 27th of October is the day when we move from DST to non-DST which leads to time 02:00 in this timezone happen twice (at 00:00 UTC and 01:00 UTC).
We request next occurrence exactly at 00:30 UTC and expect it to be 01:00 UTC time, but it is actually skipped.
Here, I draw a picture:

And here is a code to reproduce it:
```
using Cronos;
using TimeZoneConverter;
var cron = CronExpression.Parse("0 0 2 * * 0", CronFormat.Standard | CronFormat.IncludeSeconds);
var requestedAt = new DateTime(2024, 10, 27, 0, 30, 0, DateTimeKind.Utc);
var nextOccurrence = cron.GetNextOccurrence(requestedAt, TZConvert.GetTimeZoneInfo("W. Europe Standard Time"), inclusive: false);
Console.WriteLine(nextOccurrence?.ToString("o"));
```
The code output is `2024-11-03T01:00:00.0000000Z` - next week. And I would expect it to be `2024-10-27T01:00:00.0000000Z`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.