2

i have a job to be run on the last weekend of the month (i.e) if the month has a sunday at the end it should run on sunday and if the month ends or has a saturday at the end the job should run on saturday. I didnt find any documentation to build a cron expression for this case.

Thanks in advance.

flipper
  • 146
  • 3
  • 11
  • Use this simple website to generate cron expression http://www.cronmaker.com/ – Maas Jul 30 '14 at 05:48
  • @Girish That website did not give an option for the last weekend of the month. – Scary Wombat Jul 30 '14 at 05:51
  • i have already seen that but i didnt find what i wanted.To be more clear am reconstructing the outlook meeting recurrence pattern of MONTHLY->THE LAST->WEEKEND DAY ->OF EVERY 1 MONTH – flipper Jul 30 '14 at 05:53
  • 0 15 10 ? * 1L Fire at 10:15am on the last Sunday of every month – Maas Jul 30 '14 at 06:01
  • i dont want to fire that only on sunday. It should be based on the month for example for JAN & FEB 2015 it should run on last saturday and MAR it should run on last sunday – flipper Jul 30 '14 at 06:36
  • @flipper Did you ever find a solution to this problem? – Steve Dec 20 '15 at 23:05
  • still they are not supporting the feature that we are looking for, If you are trying to do so there are work around's where you can actually configure a daily job in quartz and check for the last weekend and try to trigger or adding exclusion in the job will also hold good. But the trade off is if too many jobs are to be scheduled in this manner it will increase the load and the other triggers will have a little time lag. I solved it by adding it to the exclusions... – flipper Dec 22 '15 at 07:00

1 Answers1

3

You can use L in the day of week field

0 0 0 ? * SUNL

This will trigger at every last SUN of every month, e.g.

Sunday, August 31, 2014 12:00 AM
Sunday, September 28, 2014 12:00 AM
Sunday, October 26, 2014 12:00 AM
Sunday, November 30, 2014 12:00 AM
Sunday, December 28, 2014 12:00 AM

I don't see a way to specify the last weekend of a month since quartz does not allow to combine the L character with multiple days of week. So you can't do something like SATL,SUNL. If you want to trigger something on every last SAT and SUN I would define 2 cron expressions.

From the quartz documentation (Special characters)

L ("last") - .....
for example "6L" means "the last friday of the month". 

I tested it with my cron expression view - a plugin that I wrote for eclipse https://github.com/link-intersystems/eclipse-plugins-repository. Maybe it is also useful for you,

René Link
  • 48,224
  • 13
  • 108
  • 140
  • Thank you @rene link but case is to run either on saturday or sunday which ever falls on the end of the month – flipper Aug 01 '14 at 04:54