natural-cron.js icon indicating copy to clipboard operation
natural-cron.js copied to clipboard

Wrong Expression

Open joshuaquek opened this issue 7 years ago • 3 comments

'every hour between 5pm and 8pm' gives * 17-20 * * ? * which is not the correct expression. It should be 0 0 * 17-20 * ? *

joshuaquek avatar Oct 12 '18 03:10 joshuaquek

Which format do you have for cron-expressions?

onkar27 avatar Oct 24 '18 04:10 onkar27

To begin with, I would like to say that this is a great package, because I can't find any other nlp cron expression generator out there on npm that is as smart as this package.

However, one small downside is that the cron expressions generated somehow get flagged by crontab as a different meaning from what they should be.

After doing a quick search on google, there are a few crontab checkers to check if the cron expression is what you want it to be:

https://www.freeformatter.com/cron-expression-generator-quartz.html https://cronexpressiondescriptor.azurewebsites.net/

As I mentioned earlier, when I try to do a cron expression for 'every hour between 5pm and 8pm' gives * 17-20 * * ? * which is not the correct expression.

The correct cron expression for that should be 0 0 * 17-20 * ? *

joshuaquek avatar Oct 26 '18 01:10 joshuaquek

Hi @joshuaquek Thanks a lot, it feels great to know that you liked the package.

Regarding the issue, The format you described (0 0 * 17-20 * ? *) contains 7 fields which means the first one is the seconds field. Right now this package doesn't have support for seconds field. So the generated expression has only 6 fields.

  1. Still your reported issue is correct and for every hour, the minutes field should be 0 instead of *. (We will resolve this issue in next update as early as possible)

  2. We will definitely add support for seconds field soon when we get time.

Also it looks like your required expression has some fields shuffled as compared to the default generated expression from this package. But you can easily change the generated cron expression format as per your need with optional second argument to the function call. Check out Flexible outputs section in README.

RathiRohit avatar Oct 26 '18 04:10 RathiRohit