Recurring job with custom timezone

Tags: #<Tag:0x00007fafededd628>

Hello,

I am trying to use custom timezone info to schedule a recurring job, and it seems like it is not supported

recurring job schedule

I set up the timezone as follow:

TimeZoneInfo.CreateCustomTimeZone(
“CST”,
TimeSpan.FromHours(-6),
“Central Standard Time(-06:00)”,
“CST(-06:00)”
)

What I am doing wrong as the job is not scheduled?

Thank you,

Just curious why you would need to create a custom time zone?

If you are using CreateCustomTimeZone the new timezone is stored in the registry of the Windows Server or PC where you created the timezone.

If it ends up running the code on another node that could be a problem. There is a way to save and restore custom timezones using serialization:
https://docs.microsoft.com/en-us/dotnet/standard/datetime/saving-and-restoring-time-zones

But I would expect Hangfire would need to use that in its recurring job code in order for custom timezones to work correctly.

It looks like only the timezone id is being stored by HangFire. I couldn’t find any serialization done for the timezone info.

As far as why, in most of our in house applications we provide 3 variants of most US timezones. For example, CPT is the central timezone that auto adjusts, CDT has no adjustment rule and is fixed at UTC-0500 , and CST is fixed at UTC-0600. I already mapped the system Central Standard Time to CPT, but I need to add custom ones for CST and CDT.

Thank you,

I wanted to check and see if you ever got this resolved.

I ran into something similar today and here’s how I’m going to approach it:

  1. On application server (or I guess anywhere) that submits jobs create custom time zones using TimeZoneInfo.CreateCustomTimeZone

  2. Capture the serialized version of the timezones using TimeZoneInfo.ToSerializedString()

  3. Restore timezones in Startup.cs inside of the job submitting application and the Hangfire job server using TimeZoneInfo.FromSerializedString(serializedTz)

I think this would accomplish what you want with being sure timezones are always available where you need them.

In my case, I created a map between our custom timezone and IANA. Then I used TimezoneConverter to convert into system timezone. This library is supposed to produce cross platform system timezone.