I did some searching but haven't landed anything that looks useful yet but I am wondering if anyone knows of something (tool,lib etc) that can parse English phrases and translate them into a cron string.
For example: Every Tuesday at 15:00
converts to 0 15 * * 2
It seems like something that would have lots of gotchas and it would be preferable to benefit from someone elses work. You see it in a few nice sites/apps that can work out what you mean from a simple phrase rather than having some hideous user interface.
Thanks in advance.
Though this is an old question I would like to list out all libraries/tools that I know so far, so that this answer might help others who arrive on this page looking for the same thing:
JavaScript:
natural-cron.js
(link)
friendly-cron
(link)
PHP:
natural-cron-expression
(link)Ruby:
whenever
(link)Feel free to reply in comments, if you know about any other library which is not listed here :)
(Full disclosure: natural-cron.js has been developed by me & my friend, when no other library satisfied the needs of our project)
For Ruby there's "Whenever" which might provide a starting point: It translates quasi-english (actually it's valid Ruby) into cron strings.
Depending on how flexible you need it to be, and how willing to roll up your own sleeves you are, you could define a simple grammar for this.
Every would be a quantifier. You may need others but I can't think of any. Valid syntax might be:
Every (day-spec) AT (time)
Where day-spec could be a literal day (ie. Monday) or be a day of the month (ie. 30th Day) or some other syntax (I'd suggest fortnights but I'm not sure if Cron can represent those well).
Time could be specified using either 24 hour (16:00) or 12 hour (4:00pm) format.
Another syntax that you might want is: Every (frequency) From (time) where frequency is basically (quantity) (unit) (ie. 10 Minutes). The from time enables you to set an offset (eg. Every 30 Minutes From 01:10am).
You'd probably need to sit down and figure out these details a bit more. But a rigid grammar could be implemented relatively easily using recursive descent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With