14

I'm trying to fire a job every morning at 8AM, UTC time. The problem is the triggers aren't respecting the time I'm telling it.

My code is as follows:

    ITrigger trigger = TriggerBuilder.Create()
        .WithDailyTimeIntervalSchedule(
             s => s.WithIntervalInHours(24)
                 .OnEveryDay()
                 .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(8,0)))
        .Build();

   var times = TriggerUtils.ComputeFireTimes(trigger as IOperableTrigger, null, 10);

   foreach (var time in times)
       Console.WriteLine(time.UtcDateTime);

The output is:

30/09/2013 10:00:00 PM
1/10/2013 10:00:00 PM
2/10/2013 10:00:00 PM
3/10/2013 10:00:00 PM
4/10/2013 10:00:00 PM
5/10/2013 10:00:00 PM
6/10/2013 9:00:00 PM
7/10/2013 9:00:00 PM
8/10/2013 9:00:00 PM
9/10/2013 9:00:00 PM

The reason the hour changes on the 6th is that daylight savings time starts here this weekend.

How do I get it to just trigger at 8AM UTC time like I'm telling it to?

Edit: This is crazy, it even does it with the Cron schedule:

ITrigger trigger = TriggerBuilder.Create()
    .WithCronSchedule("0 0 8 * * ?")
    .Build();

var times = TriggerUtils.ComputeFireTimes(trigger as IOperableTrigger, null, 10);

foreach (var time in times)
    Console.WriteLine(time.UtcDateTime);

Output:

30/09/2013 10:00:00 PM
1/10/2013 10:00:00 PM
2/10/2013 10:00:00 PM
3/10/2013 10:00:00 PM
4/10/2013 10:00:00 PM
5/10/2013 9:00:00 PM
6/10/2013 9:00:00 PM
7/10/2013 9:00:00 PM
8/10/2013 9:00:00 PM
9/10/2013 9:00:00 PM
3
  • Which version of quartz.net are you using? Maybe this post is related to your issue? stackoverflow.com/questions/15661268/…
    – J.Hudler
    Commented Sep 29, 2013 at 23:46
  • Quartz.Net 2.2 for 4.0 (2.2.400.0)
    – PMac
    Commented Sep 30, 2013 at 1:51
  • According to that question there was a bug in GetFireTimeAfter() that used local time to create trigger dates. That seems to be the behaviour I'm seeing. That question mentions a fix in Quartz.Net 2.1, but I'm running 2.2, so it could be a new variation on that bug (or I could be doing something wrong).
    – PMac
    Commented Sep 30, 2013 at 2:00

2 Answers 2

23

After pulling down the source code and digging through, I've found a couple of solutions.

I originally found a solution like so:

var trigger4 = new DailyTimeIntervalTriggerImpl
{
    StartTimeUtc = DateTime.UtcNow,
    StartTimeOfDay = new TimeOfDay(8, 0, 0),
    RepeatIntervalUnit = IntervalUnit.Hour,
    RepeatInterval = 24,
    TimeZone = TimeZoneInfo.Utc
};

...which led me to adjust my original code:

ITrigger trigger2 = TriggerBuilder.Create()
    .WithDailyTimeIntervalSchedule(
        s => s.WithIntervalInHours(24)
            .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(8, 0))
            .InTimeZone(TimeZoneInfo.Utc))
    .Build();

Both of these give me what I'm after. I just wish there was some decent documentation out there for this library.

1
  • Are there any unwanted/unknown side effects changing a running system from Local to Utc?
    – norgie
    Commented Aug 3, 2021 at 10:21
8

Though this is old, I'll answer it here anyway. You can simply perform the operation of:

ITrigger trigger = TriggerBuilder.Create() .WithCronSchedule("0 0 8 * * ?", cron => { cron.InTimeZone(TimeZoneInfo.Utc); } ) .Build();

2
  • So the default is the local time zone? And not UTC?
    – Ozkan
    Commented Sep 10, 2018 at 9:25
  • 1
    @Ozkan Yes, it runs as per the system timezone. That's why as per the docs, you can choose a different timezone, please refer to docs here Commented Jan 17, 2021 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.