cron is a Go library that parses a cron expression and outputs a human readable description of the cron schedule.
For example, given the expression */5 * * * * it will output Every 5 minutes.
Translated to Go from cron-expression-descriptor (C#) via cRonstrue (Javascript).
Original Author & Credit: Brady Holt (http://www.geekytidbits.com).
- Zero dependencies
- Supports all cron expression special characters including
* / , - ? L W # - Supports 5, 6 (w/ seconds or year), or 7 (w/ seconds and year) part cron expressions
- Supports Quartz Job Scheduler cron expressions
- i18n support with 26 locales.
crondesc module can be used with both Go module (>= 1.11) and earlier Go versions.
go get -u -v github.com/verystar/crondesc
// Init with default EN locale
exprDesc, _ := crondesc.NewDescriptor()
desc, _ := exprDesc.ToDescription("* * * * *", crondesc.Locale_en)
// "Every minute"
desc, _ := exprDesc.ToDescription("0 23 ? * MON-FRI", crondesc.Locale_en)
// "At 11:00 PM, Monday through Friday"
desc, _ := exprDesc.ToDescription("23 14 * * SUN#2", crondesc.Locale_en)
// "At 02:23 PM, on the second Sunday of the month"
// Init with custom configs
exprDesc, _ := crondesc.NewDescriptor(
crondesc.Use24HourTimeFormat(true),
crondesc.DayOfWeekStartsAtOne(true),
crondesc.Verbose(true),
crondesc.SetLogger(log.New(os.Stdout, "cron: ", 0)),
crondesc.SetLocales(crondesc.Locale_en, crondesc.Locale_fr),
)For more usage examples, including a demonstration of how cron can handle some very complex cron expressions, you can reference the unit tests or the example codes.
To use the i18n support, you must configure the locales when create a new ExpressionDescriptor via SetLocales() option.
exprDesc, _ := crondesc.NewDescriptor(
crondesc.SetLocales(crondesc.Locale_en, crondesc.Locale_es, crondesc.Locale_fr),
)
// or load all crondesc.LocaleAll
exprDesc, _ := crondesc.NewDescriptor(crondesc.SetLocales(crondesc.LocaleAll))
desc, _ := exprDesc.ToDescription("* * * * *", crondesc.Locale_fr)
// Toutes les minutesBy default, ExpressionDescriptor always load the Locale_en. If you pass an unregistered locale into ToDescription() function, the result will be returned in English.
| Locale Code | Language | Contributors |
|---|---|---|
| cs | Czech | hanbar |
| da | Danish | Rasmus Melchior Jacobsen |
| de | German | Michael Schuler |
| en | English | Brady Holt |
| es | Spanish | Ivan Santos |
| fa | Farsi | A. Bahrami |
| fi | Finnish | Mikael Rosenberg |
| fr | French | Arnaud TAMAILLON |
| he | Hebrew | Ilan Firsov |
| it | Italian | rinaldihno |
| ja | Japanese | Alin Sarivan |
| ko | Korean | Ion Mincu |
| nb | Norwegian | Siarhei Khalipski |
| nl | Dutch | TotalMace |
| pl | Polish | foka |
| pt_BR | Portuguese (Brazil) | Renato Lima |
| ro | Romanian | Illegitimis |
| ru | Russian | LbISS |
| sk | Slovakian | hanbar |
| sl | Slovenian | Jani Bevk |
| sv | Swedish | roobin |
| sw | Swahili | Leylow Lujuo |
| tr | Turkish | Mustafa SADEDİL |
| uk | Ukrainian | Taras |
| zh_CN | Chinese (Simplified) | Star Peng |
| zh_TW | Chinese (Traditional) | Ricky Chiang |