How to handle user time zone for daylight saving time in quartz for cron Triggers?

My api service accepts startDate for Job quartz and the day of the month for the job. Inside, I convert this to a cron expression and store it in quartz.

For example, a user in PST sends a job request today (November 3, 2017) as follows.

{ "start": "2017-11-03T18:00:00-07:00", "dayOfMonth" : 15 } 

Here, the user wants to schedule a work that runs on the 15th of each month at 6 pm, starting from 2017-11-03. therefore, the first day of the quartz will shoot 2017-11-15. Thus, the above query is converted to an expression cron 0 0 18 15 * ? * 0 0 18 15 * ? * which is correct. This is what the QRTZ_CRON_TRIGGERS table looks like.

enter image description here

As you noticed, time_zone_id is saved as GMT-07: 00, but after a 5-day switch to daytime it should be GMT-08: 00. Or my work on quartz will work an hour earlier. In fact, when I request nextFireTime, I get 1510794000000, which is really Wednesday November 15, 2017 17:00:00 (pm) in the time zone America / Los Angeles (PST)

How do we deal with this time_zone_id problem?

PS: I use cronTrigger, which has no concept of preserveHourOfDayAcrossDaylightSavings , which is provided by CalendarIntervalTrigger .

0
dst quartz-scheduler crontrigger
source share
1 answer

Do not use an offset to represent the time zone. Rather, you can ask the user to go in the time zone, for example, " America / Los Angeles ." Then you can use http://www.quartz-scheduler.org/api/2.2.1/org/quartz/CronScheduleBuilder.html#inTimeZone(java.util.TimeZone) to create a trigger with the appropriate time zone.

 inTimeZone(TimeZone.getTimeZone("USER_ENTERED_VALUE") 

Finally, when you look at the QRTZ_CRON_TRIGGERS table, the value for TIME_ZONE_ID will be America / Los_Angeles

+1
source share

All Articles