CLI tool (hcron) and Go library (cron) to convert CRON expression into human readable description.

Overview

cron

GoDoc Reference 1.0.0 release Code Status Build Status Coverage Status

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).

Features

  • 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.

Installation

cron module can be used with both Go module (>= 1.11) and earlier Go versions.

go get -u -v github.com/lnquy/cron

Usage

// Init with default EN locale
exprDesc, _ := cron.NewDescriptor()

desc, _ := exprDesc.ToDescription("* * * * *", cron.Locale_en)
// "Every minute" 

desc, _ := exprDesc.ToDescription("0 23 ? * MON-FRI", cron.Locale_en)
// "At 11:00 PM, Monday through Friday" 

desc, _ := exprDesc.ToDescription("23 14 * * SUN#2", cron.Locale_en)
// "At 02:23 PM, on the second Sunday of the month"

// Init with custom configs
exprDesc, _ := cron.NewDescriptor(
    cron.Use24HourTimeFormat(true),
    cron.DayOfWeekStartsAtOne(true),
    cron.Verbose(true),
    cron.SetLogger(log.New(os.Stdout, "cron: ", 0)),
    cron.SetLocales(cron.Locale_en, cron.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.

i18n

To use the i18n support, you must configure the locales when create a new ExpressionDescriptor via SetLocales() option.

exprDesc, _ := cron.NewDescriptor(
    cron.SetLocales(cron.Locale_en, cron.Locale_es, cron.Locale_fr),
)
// or load all cron.LocaleAll
exprDesc, _ := cron.NewDescriptor(cron.SetLocales(cron.LocaleAll))

desc, _ := exprDesc.ToDescription("* * * * *", cron.Locale_fr)
// Toutes les minutes

By default, ExpressionDescriptor always load the Locale_en. If you pass an unregistered locale into ToDescription() function, the result will be returned in English.

Supported Locales

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

hcron

hcron is the CLI tool to convert the CRON expression to human readable string.
You can pass the CRON expressions as the program argument, piped hcron with stdin or given the path to crontab file.

Install

You can find the pre-built binaries for Linux, MacOS, FreeBSD and Windows from the Release.

For other OS or architecture, you can build the code using Go as below:

$ go get -u -v github.com/lnquy/cron/cmd/hcron

# or

$ git clone https://github.com/lnquy/cron
$ cd cron/cmd/hcron
$ go build

Usage

$ hcron -h
hcron converts the CRON expression to human readable description.

Usage:
  hcron [flags] [cron expression]

Flags:
  -24-hour
        Output description in 24 hour time format
  -dow-starts-at-one
        Is day of the week starts at 1 (Monday-Sunday: 1-7)
  -file string
        Path to crontab file
  -h    Print help then exit
  -locale string
        Output description in which locale (default "en")
  -print-all
        Also print all the lines which is not a valid cron
  -v    Print app version then exit
  -verbose
        Output description in verbose format

Examples:
  $ hcron "0 15 * * 1-5"
  $ hcron "0 */10 9 * * 1-5 2020"
  $ hcron -locale fr "0 */10 9 * * 1-5 2020"
  $ hcron -file /var/spool/cron/crontabs/mycronfile
  $ another-app | hcron 
  $ another-app | hcron --dow-starts-at-one --24-hour -locale es

Project status

  • Port 1-1 code from cRonstrue Javascript
  • Port and pass all test cases from cRonstrue
  • i18n for 25 languages
  • Test cases i18n
  • Fix i18n issues of FA, HE, RO, RU, UK, ZH_CN and ZH_TW
  • hcron CLI tool
  • Performance improvement
  • Release v1.0.0

License

This project is under the MIT License. See the LICENSE file for the full license text.

Issues
  • Improve parser performance

    Improve parser performance

    $ benchstat before_result.pprof after_result.pprof 
    name                                old time/op    new time/op    delta
    ExpressionDescriptor_ToDescription    15.6µs ± 3%    11.8µs ± 1%  -24.52%  (p=0.000 n=10+9)
    
    name                                old alloc/op   new alloc/op   delta
    ExpressionDescriptor_ToDescription    5.63kB ± 0%    4.59kB ± 0%  -18.47%  (p=0.000 n=10+10)
    
    name                                old allocs/op  new allocs/op  delta
    ExpressionDescriptor_ToDescription      92.0 ± 0%      90.0 ± 0%   -2.17%  (p=0.000 n=10+10)
    
    
    opened by lnquy 0
Releases(v1.1.1)
Owner
Quy Le
If it's to be, it's up to me
Quy Le
Command line tool for time tracking in a human-readable file format.

klog klog is a plain-text file format and a command line tool for time tracking. ?? Documentation – Learn how to use klog ?? Download – Get the latest

Jan Heuermann 346 May 7, 2022
Clirunner - Package clirunner runs a legacy shell-style CLI as if a human were running it.

clirunner Package clirunner runs a legacy shell-style command-line interpreter (CLI) as if a human were running it. A shell-style CLI offers a prompt

Jeff Regan 0 Jan 4, 2022
A simple command line time description parser

Zeit Zeit is an extremely simple command line application to read a natural language time description and output it as a timestamp. The main usecase f

ElKowar 6 Aug 21, 2021
Utility CLI to convert Spring Boot Yaml configuration into external configuration

boot-config-export Utility CLI to convert Spring Boot Yaml configuration into external configuration (as environment variables). The variables are tra

Lucian 0 Nov 17, 2021
donLoader is a shellcode loader creation tool that uses donut to convert executable payloads into shellcode to evade detection on disk.

donLoader WARNING: This is WIP, barely anything was tested properly. Use at your own risk. Description donLoader is a shellcode loader creation tool t

blink3n 10 Mar 19, 2022
lsp is like ls command but more human-friendly

lsp: list files in a mildly human-frendlier manner lsp lists files, like ls command, but it does not attempt to meet that archaic POSIX specification,

Dmitry Borzov 507 Apr 12, 2022
A command line utility that automagically replaces UNIX timestamps with human interpretable timestamps.

Unfy unfy is a command line utility that automagically identifies and translated UNIX timestamps (since epoch) to human readable timestamps. Example B

Jens Rantil 39 Jan 15, 2022
💾 A visual du(1) alternative for human beings

dux A disk usage analyzer. Like du(1), but displays the results as an interactive treemap. testdata 111B (8 files) (4) ┌testdata/ 111B────────────

Jens Green Olander 1 Jan 15, 2022
Convert your Youtube Playlists into Spotify Playlists

yt2spotify Description This is an application that allow a Spotify user to migra

César Pinheiro 0 Dec 28, 2021
Program to convert plain text to CSV file which can imported into Anki.

Program to convert plain text to CSV file which can imported into Anki. The motivation of this program is to save time by automatically coverting Question and Answer into CSV file which can be imported directly into Anki.

Anuroop Sirothia 0 Jan 30, 2022
word2text - a tool is to convert word documents (DocX) to text on the CLI with zero dependencies for free

This tool is to convert word documents (DocX) to text on the CLI with zero dependencies for free. This tool has been tested on: - Linux 32bit and 64 bit - Windows 32 bit and 64 bit - OpenBSD 64 bit

Ryan Thomas 5 Apr 19, 2021
CLI tool to convert many common document types to plane text.

Textify. CLI tool to convert many common document types to plane text. Goals. SO many different document types exist today. PDFs, EPUB books, Microsof

Quin 1 Nov 19, 2021
CLI and web app to convert HTML markup to go-app.dev's syntax.

HTML to go-app Converter CLI and web app to convert HTML markup to go-app.dev's syntax. Installation CLI Static binaries are also available on GitHub

Felix Pojtinger 7 Feb 21, 2022
This package can parse date match expression, which used by ElasticSearch

datemath-parser this package is pure go package, this package can parse date match expression, which used by ElasticSearch. Date Math Definition you c

zhuliquan 0 Jan 8, 2022
Soren L. Hansen 1.5k May 19, 2022
✏️ CLI tool to split a file into smaller sub-files

filesplit CLI tool to split a file into smaller sub-files Build $ go build Usage filesplit [mode] [-F, --file] [-N, --number] Examples # Split foo.txt

Martin Sit 5 Apr 20, 2022
Cli tool to translate text from any language into german

GERMAN A cli tool for converting text into German. Build Locally $> go build $> go install Dependencies To execute successfully, a free tier DEEPL API

Kieran O'Sullivan 3 Jan 24, 2022
A CLI tool which loads data from yaml files into the Google Cloud Spanner tables

splanter A CLI tool which loads data from yaml files into the Google Cloud Spanner tables (mainly for the development).

Yuki Ito 4 Nov 29, 2021
Nebula Diagnosis CLI Tool is an information diagnosis cli tool for the nebula service and the node to which the service belongs.

Nebula Diagnosis CLI Tool is an information diagnosis cli tool for the nebula service and the node to which the service belongs.

Katz 1 Jan 12, 2022