Display Next Cron job run date/time?

I'm trying to display the next time the app will run based on a Cron expression.

import org.quartz.* - is allowed
import org.quartz.CronExpression - is not allowed

So then I tried this...

CronExpression exp = new CronExpression(ceValue)
nextRun = exp.getNextValidTimeAfter(new Date())
log.info "nextRun: ${nextRun}"

But it doesn't like it because I can't import CronExpression (I think).

Expression [DeclarationExpression] is not allowed: (exp = new org.quartz.CronExpression(ceValue)) at line number 194

Anybody know a way around this?

Just to make sure I'm making sense. I would like to turn '0 40 6 24 OCT ? *' into '2020-10-24 6:40:00 AM EDT' :grin:

Thanks

1 Like

@bravenel, @mike.maxwell, @gopher.ny

Any insight on this? Thanks again!

The class is not whitelisted, so there isn't. The workaround, silly at it may be, is to engage into some copy/paste engineering and lift relevant code from CronExpression itself.

Hmmm, any chance of that changing? My use case would open up a whole new avenue for automation.

Say someone created a list of Holidays (ok, ok, I did!).

If I knew when the next time it would run:

  • I could then sort on that date/time.
  • I could calculate 'How many days until'
  • On that 'day', control the house 'this way' or 'that way', make announcements, etc.

--- Start soapbox ---

Although this would seem trivial to most. To anyone that has had a stroke (me) or any sort of brain injury, Memory loss or the ability to remember things like dates is very real and can be VERY frustrating. Among other things, my memory/recall ability was hit hard. Being able to remind myself that Holiday/Birthday/Anniversary dates are coming up would help with some of the frustration.

This is just one example of what I would like to do with this information. Automation has definitely made my life easier since the events that happened to me last year. As time goes by, I'm sure I'll need to lean on it more and more. And I'll continue to find ways to make up for my disability.

This is not to make anyone feel bad or a whoa is me type of thing. Hopefully just a way for others to see how automation can change someones life. Little things make life easier or more 'normal'.

--- End soapbox ---

BTW, here's my list of Holidays. :wink:

2 Likes

:grin:

1 Like