Class TimeZones
- Namespace
- Quartz
- Assembly
- Quartz.dll
Time zone lookup that answers the same way on every platform.
public static class TimeZones
- Inheritance
-
TimeZones
- Inherited Members
Remarks
FindSystemTimeZoneById(string) resolves a different set of ids on Windows, on Linux and under ICU, so an expression that named a zone on the developer's machine could fail to resolve on the server. These members translate the spellings each platform is missing.
Methods
AddResolver(Func<string, TimeZoneInfo?>)
Registers a last-resort resolver, consulted when a time zone id is neither a system id nor one of the aliases above. Disposing the returned registration removes the resolver again.
public static IDisposable AddResolver(Func<string, TimeZoneInfo?> resolver)
Parameters
resolverFunc<string, TimeZoneInfo>Maps a time zone id to a TimeZoneInfo, or to null for an id it does not know.
Returns
- IDisposable
A registration whose disposal removes the resolver. Disposing twice is a no-op.
Remarks
This is process-wide, and deliberately so: FindById(string) is reached from
places that have no scheduler in scope — parsing a CronExpression, deserializing
a trigger or calendar out of a job store blob — so there is nothing scheduler-scoped to hang a
resolver on. Adding a resolver from one scheduler changes id resolution for every scheduler in
the process, which is what Quartz.Plugins.TimeZoneConverter's UseTimeZoneConverter
does — once per process, and without ever removing it, so that a scheduler shutting down cannot
take resolution away from the ones still running.
Resolvers are consulted most recently added first, so a later registration shadows an earlier one for the ids it resolves. A resolver declines an id by returning null or by throwing TimeZoneNotFoundException; either way the search continues with the next resolver, and FindById(string) throws only when every fallback has failed.
FindById(string)
Tries to find time zone with given id, has ability do some fallbacks when necessary.
public static TimeZoneInfo FindById(string id)
Parameters
idstringSystem id of the time zone.
Returns
GetUtcOffset(DateTime, TimeZoneInfo)
The zone's offset at the given instant, resolving an ambiguous local time to the earlier of the two — which is the daylight one, and the one time reaches first.
public static TimeSpan GetUtcOffset(DateTime dateTime, TimeZoneInfo timeZoneInfo)
Parameters
dateTimeDateTimeThe instant to read the offset at.
timeZoneInfoTimeZoneInfoThe zone.