Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for extra custom time zone resolver function in TimeZoneUtil #290

Closed
RFlipper opened this issue Aug 26, 2015 · 1 comment
Closed
Milestone

Comments

@RFlipper
Copy link

I use the following code to schedule a job:

var webTimezoneOffset = TimeSpan.FromMilliseconds(task.WebTimezoneOffset);
var webTimezone = TimeZoneInfo.CreateCustomTimeZone("Current Web Timezone", webTimezoneOffset, null, null);

var trigger = TriggerBuilder.Create()
                .WithIdentity(task.TaskId.ToString())
                .WithCronSchedule(task.CronExpression, t => t.InTimeZone(webTimezone))
                .StartAt(task.StartTime - new TimeSpan(0, 0, 1))
                .Build();

In that case I get the following error:

Quartz.JobPersistenceException: Couldn't retrieve trigger: The time zone ID 'Current Web Timezone' was not found on the local computer. ---> System.TimeZoneNotFoundException: The time zone ID 'Current Web Timezone' was not found on the local computer.
   at System.TimeZoneInfo.FindSystemTimeZoneById(String id)
   at Quartz.Util.TimeZoneUtil.FindTimeZoneById(String id) in c:\Program Files (x86)\Jenkins\workspace\Quartz.NET\src\Quartz\Util\TimeZoneUtil.cs:line 110

As I researched the issue in method LoadExtendedTriggerProperties in the file https://github.com/quartznet/quartznet/blob/045344fe21cbdb2229cb6ac496652941a275e61b/src/Quartz/Impl/AdoJobStore/CronTriggerPersistenceDelegate.cs

I wonder to know if it possible to add support saving time zone offset.

@lahma
Copy link
Member

lahma commented Jul 25, 2017

I know this won't fully cover the use case, but opens some possibilities:

// custom time zone
const string CustomTimeZoneId = "Custom TimeZone";
var webTimezone = TimeZoneInfo.CreateCustomTimeZone(
	CustomTimeZoneId, 
	TimeSpan.FromMinutes(22),
	null, 
	null);

TimeZoneUtil.CustomResolver = id =>
{
	if (id == CustomTimeZoneId)
	{
		return webTimezone;
	}
	return null;
};

var customTimeZoneTrigger = TriggerBuilder.Create()
	.WithIdentity("customTimeZoneTrigger")
	.WithCronSchedule("0/5 * * * * ?", x => x.InTimeZone(webTimezone))
	.StartNow()
	.ForJob(job)
	.Build();

scheduler.ScheduleJob(customTimeZoneTrigger);
var loadedCustomTimeZoneTrigger = (ICronTrigger) scheduler.GetTrigger(customTimeZoneTrigger.Key);
Assert.That(loadedCustomTimeZoneTrigger.TimeZone.BaseUtcOffset, Is.EqualTo(TimeSpan.FromMinutes(22)));

Only having offset isn't enough as daylight savings vary by time zone id. This means requiring to encode offset to name in your case.

@lahma lahma changed the title Add support custom time zones Add support for extra custom time zone resolver function in TimeZoneUtil Jul 25, 2017
lahma added a commit that referenced this issue Jul 25, 2017
@lahma lahma added this to the 2.6 milestone Jul 25, 2017
@lahma lahma closed this as completed Jul 25, 2017
lahma added a commit that referenced this issue Jul 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants