english-to-cron converts natural language into cron expressions, allowing developers to easily schedule cron jobs using English text.
- Converts various English text descriptions into cron job syntax
- Supports complex patterns including specific days, time ranges, and more
- Handles multiple time formats including AM/PM and 24-hour notation
- Zero dependencies
Add this line to your application's Gemfile:
gem 'english-to-cron'And then execute:
$ bundle installOr install it yourself as:
$ gem install english-to-cronSimply provide an English phrase describing the schedule, and the library will return the corresponding cron job syntax.
require 'english_to_cron'
# Basic usage
EnglishToCron.parse("every 15 seconds") # => "0/15 * * * * ? *"
EnglishToCron.parse("every minute") # => "0 * * * * ? *"
EnglishToCron.parse("every day at 4:00 pm") # => "0 0 16 */1 * ? *"
EnglishToCron.parse("at 10:00 am") # => "0 0 10 * * ? *"
EnglishToCron.parse("Run at midnight on the 1st and 15th of the month") # => "0 0 0 1,15 * ? *"
EnglishToCron.parse("on Sunday at 12:00") # => "0 0 12 ? * SUN *"| English Phrase | CronJob Syntax |
|---|---|
| every 15 seconds | 0/15 * * * * ? * |
| run every minute | 0 * * * * ? * |
| fire every day at 4:00 pm | 0 0 16 */1 * ? * |
| at 10:00 am | 0 0 10 * * ? * |
| run at midnight on the 1st and 15th of the month | 0 0 0 1,15 * ? * |
| On Sunday at 12:00 | 0 0 12 ? * SUN * |
| 7pm every Thursday | 0 0 19 ? * THU * |
| midnight on Tuesdays | 0 0 0 ? * TUE * |
The library will raise errors for invalid or unparseable inputs:
begin
EnglishToCron.parse("invalid input")
rescue EnglishToCron::Error => e
puts "Error: #{e.message}"
endBug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration.
The gem is available as open source under the terms of the MIT License.