'How to validate if current date time is within Spring Cron Expression?
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
Solution 1:[1]
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?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
