How to validate if current date time is within Spring Cron Expression?

Viewed 838

I have a Spring Cron Expression like */10 * 9-17 * * MON-FRI

I want to find out if the current time or any given time is within the range or not.

I know I can use CronExpression class and use the next() method. But it gives me the next valid runnable time.

Thanks

1 Answers

A cron expression does not define a range or ranges of time. Rather, it defines distinct points in time throughout a year. In many cases, like with your example, cron expressions are viewed as describing distinct points in time throughout each week.

Since cron doesn't define a range, it doesn't make sense to ask if a particular time is "within the range or not". This is why it has only a next() method...pretty much all you can do is ask what the next point in time is given a time to start from.

If this doesn't clear up your problem for you, I would suggest that you edit your question and describe your use case. What is it that you are actually trying to accomplish?

Related