Pulkit Mittal
Pulkit Mittal

Reputation: 6086

Setting multiple timezones in Java Scheduler Quartz Cron

I need to run a CRON at midnight which auto-assigns some periodic tasks for the people working in my company. The situation I am facing is that my company basically has offices all around US, which has more than 1 timezone. So basically I would want the job to be done timezone-specific. Also, my server is running by UTC.

If I set EDT as the base timezone (which is 4 hours behind UTC) and set the CRON to be triggered at midnight, the CRON time would be

0 0 4 * * ?

The possible way that I think can be is that instead of setting it just once, I set it to be triggered 7 times at the following times:

0 0 4 * * ? [EDT]
0 0 5 * * ? [CDT]
0 0 6 * * ? [MDT]
0 0 7 * * ? [PDT]
0 0 8 * * ? [AKDT]
0 0 9 * * ? [HADT]
0 0 10 * * ? [HST]

So once any of it triggers, it would check which of my offices come under this time zone and will do the job.

This may work, as I believe, but does anyone else have any other option instead of this? Also, I would need to fix for the Daylight saving, which I am not really sure about how I would want to do.

Upvotes: 4

Views: 2226

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1501976

I think the simplest approach would probably be to have a single job which ran once an hour, which then went through all the offices, and found any that were now on a later day to the one when the job last ran. (You'd need to maintain that, of course, along with the office's time zone.) That would take care of the DST issue for you, and also cope with a situation when the scheduler went down for a while - the next time it came up, it would "catch up" for all the offices it had missed.

Upvotes: 2

Related Questions