atifaziz / NCrontab

Crontab for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there any way to use UTC?

VitorCioletti opened this issue · comments

Does this library support any cron expression to use UTC timezone?

Schedules are calculated irrespective of time zone so you it's up to the caller to decide how to have the resulting time interpreted and adjusted.

@VitorCioletti here's a dotnet fiddle script that may help in switching between local times and UTC.

In our case, we store the NextOccurance in our database in UTC and we query in UTC, looking for jobs that are due to run. However, we allow the user to specify the cron expression in their local time (which means we need their timezone)

In this script, I assume "America/Toronto" as the timezone, and get a schedule of runs between 9 and 17 local time.

Hope that helps.

In theory, just "pretending" a DateTime has the proper timezone should do it. It won't handle anything like daylight saving times and so on though..

Actually UTC is the only zone this library can handle due to mentioned DST nuances.