Skip to content

About

Converts natural language into cron expressions

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Repository files navigation

English to CronJob Syntax Converter

english-to-cron converts natural language into cron expressions, allowing developers to easily schedule cron jobs using English text.

Features

  • 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

Installation

Add this line to your application's Gemfile:

gem 'english-to-cron'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install english-to-cron

Usage

Simply 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 *"

Full List of Supported English Patterns

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 *

Error Handling

The library will raise errors for invalid or unparseable inputs:

begin
  EnglishToCron.parse("invalid input")
rescue EnglishToCron::Error => e
  puts "Error: #{e.message}"
end

Contributing

Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration.

License

The gem is available as open source under the terms of the MIT License.

About

Converts natural language into cron expressions

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages