From f7d314ce2bc16574deadd7967b2d709400d6b14b Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Tue, 5 Sep 2023 01:01:27 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Delay=20calculation=20was=20?= =?UTF-8?q?incorrectly=20converting=20using=20the=20system=20timezone.=20N?= =?UTF-8?q?ow=20using=20the=20configured=20timezone.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CronTimer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CronTimer.cs b/src/CronTimer.cs index 1295a36..00357a8 100644 --- a/src/CronTimer.cs +++ b/src/CronTimer.cs @@ -59,7 +59,8 @@ TimeSpan CalculateDelay() TimeSpan delay; if (tz != UTC) { - delay = Next.ToUniversalTime() - nowUtc; + var nextUtc = TimeZoneInfo.ConvertTimeToUtc(Next, tzi); + delay = nextUtc - nowUtc; } else { From 279168a14f3c2e8f00a49cb22f2e1e4912f0dfe3 Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Tue, 5 Sep 2023 01:02:31 +0200 Subject: [PATCH 2/2] Updated demo to use `Asia/Hong_Kong` which is ahead of time of author :-) --- Demo/Program.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Demo/Program.cs b/Demo/Program.cs index da9365f..4d7ff81 100644 --- a/Demo/Program.cs +++ b/Demo/Program.cs @@ -8,13 +8,15 @@ static void Main() { var expression = "0-30/5 * * * * *"; Console.WriteLine(expression); - var timer = new CronTimer(expression, "Europe/Amsterdam", includingSeconds: true); + var timer = new CronTimer(expression, "Asia/Hong_Kong", includingSeconds: true); timer.OnOccurence += (s, ea) => Console.WriteLine($"{ea.At:T} - {DateTime.Now}"); timer.Start(); while (Console.ReadKey().Key != ConsoleKey.Escape) { } + + timer.Stop(); } } }