Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Cron expression parser for Amazon EventBridge.

License

NotificationsYou must be signed in to change notification settings

winebarrel/cronplan

Repository files navigation

CIGo ReferenceGo Report Card

Overview

Cron expression parser for Amazon EventBridge.

Try with curl

$ curl cronplan.in -d'5 0 10 * ? *'Tue, 10 Oct 2023 00:05:00Fri, 10 Nov 2023 00:05:00Sun, 10 Dec 2023 00:05:00Wed, 10 Jan 2024 00:05:00Sat, 10 Feb 2024 00:05:00Sun, 10 Mar 2024 00:05:00Wed, 10 Apr 2024 00:05:00Fri, 10 May 2024 00:05:00Mon, 10 Jun 2024 00:05:00Wed, 10 Jul 2024 00:05:00

Installation

go get github.com/winebarrel/cronplan

Usage

package mainimport ("fmt""time""github.com/winebarrel/cronplan")funcmain() {cron,err:=cronplan.Parse("0 10 * * ? *")iferr!=nil {panic(err)}fmt.Println(cron.Minute.Exps[0].Number)//=> 0fmt.Println(cron.Hour.Exps[0].Number)//=> 10fmt.Println(cron.String())//=> "0 10 * * ? *"fmt.Println(cron.Match(time.Date(2022,11,3,9,0,0,0,time.UTC)))//=> falsefmt.Println(cron.Match(time.Date(2022,11,3,10,0,0,0,time.UTC)))//=> truefmt.Println(cron.Next(time.Date(2022,11,3,10,0,0,0,time.UTC)))//=> 2022-11-03 10:00:00 +0000 UTCfmt.Println(cron.Next(time.Date(2022,11,3,11,0,0,0,time.UTC)))//=> 2022-11-04 10:00:00 +0000 UTCfmt.Println(cron.NextN(time.Date(2022,11,3,10,0,0,0,time.UTC),3))//=> [2022-11-03 10:00:00 +0000 UTC 2022-11-04 10:00:00 +0000 UTC 2022-11-05 10:00:00 +0000 UTC]fmt.Println(cron.Between(time.Date(2022,11,3,10,0,0,0,time.UTC),time.Date(2022,11,4,10,0,0,0,time.UTC),))//=> [2022-11-03 10:00:00 +0000 UTC 2022-11-04 10:00:00 +0000 UTC]}

Behavior of "L" in day-of-week

If you specify "L" for day-of-week, the last day of the week of each month is usually matched.

# cron(0 0 ? * 6L *)Fri, 27 Oct 2023 00:00:00Fri, 24 Nov 2023 00:00:00Fri, 29 Dec 2023 00:00:00Fri, 26 Jan 2024 00:00:00Fri, 23 Feb 2024 00:00:00

However, if you do not specify the day of the week before "L", the behavior will be the same as when you specify "SAT".

# cron(0 0 ? * L *) = cron(0 0 ? * SAT *)Sat, 07 Oct 2023 00:00:00Sat, 14 Oct 2023 00:00:00Sat, 21 Oct 2023 00:00:00Sat, 28 Oct 2023 00:00:00Sat, 04 Nov 2023 00:00:00

cronplan CLI

CLI to show next triggers.

Installation

brew install winebarrel/cronplan/cronplan

Usage

Usage: cronplan [OPTION] CRON_EXPR  -h int    hour to add  -n int    number of next triggers (default 10)  -version    print version and exit
$ cronplan '*/10 10 ? * MON-FRI *'Tue, 11 Oct 2022 10:00:00Tue, 11 Oct 2022 10:10:00Tue, 11 Oct 2022 10:20:00Tue, 11 Oct 2022 10:30:00Tue, 11 Oct 2022 10:40:00Tue, 11 Oct 2022 10:50:00Wed, 12 Oct 2022 10:00:00Wed, 12 Oct 2022 10:10:00Wed, 12 Oct 2022 10:20:00Wed, 12 Oct 2022 10:30:00$ cronplan -h -9 '*/10 10 ? * MON-FRI *'Tue, 11 Oct 2022 01:00:00Tue, 11 Oct 2022 01:10:00Tue, 11 Oct 2022 01:20:00Tue, 11 Oct 2022 01:30:00Tue, 11 Oct 2022 01:40:00Tue, 11 Oct 2022 01:50:00Wed, 12 Oct 2022 01:00:00Wed, 12 Oct 2022 01:10:00Wed, 12 Oct 2022 01:20:00Wed, 12 Oct 2022 01:30:00

cronmatch CLI

CLI to check if datetime matches cron expression.

Installation

brew install winebarrel/cronplan/cronmatch

Usage

Usage: cronmatch [OPTION] CRON_EXPR DATE  -h int    hour to add  -no-color    disable color output  -version    print version and exit
$ cronmatch -h -9 '0 1 * * ? *' '2022/10/20 10:00''0 1 * * ? *' matches '2022/10/20 10:00' (offset: -9h)$ cronmatch '0 10 * * ? *' 'Oct 10, 2022, 10:10''0 10 * * ? *' does not match 'Oct 10, 2022, 10:10'

cf.https://pkg.go.dev/github.com/araddon/dateparse#readme-extended-example

cronviz CLI

CLI to visualize cron schedule.

inspired bycronv,aws-cronv.

Installation

brew install winebarrel/cronplan/cronviz

Usage

Usage: cronviz [OPTION] [FILE]  -f string    from date (default current date)  -h int    hour to add  -p string    period (default "1d")  -version    print version and exit
$ cat cron.txtbatch1  0 * * * ? *batch2  30 */2 * * ? *batch3  15,45 */3 * * ? *$ cronviz cron.txt > output.html$ open output.html

cf.https://raw.githack.com/winebarrel/cronplan/main/_example/timeline.html

crongrep CLI

CLI to grep with cron expression.

Installation

brew install winebarrel/cronplan/crongrep

Usage

Usage: crongrep [OPTION] CRON_EXPR  -version    print version and exit
$ cronplan -n 5 '10 12 */5 * ? *'Fri, 06 Oct 2023 12:10:00Wed, 11 Oct 2023 12:10:00Mon, 16 Oct 2023 12:10:00Sat, 21 Oct 2023 12:10:00Thu, 26 Oct 2023 12:10:00$ cronplan -n 5 '10 12 */5 * ? *' | crongrep '* * ? * WED-FRI *'Fri, 06 Oct 2023 12:10:00Wed, 11 Oct 2023 12:10:00Thu, 26 Oct 2023 12:10:00

cronskd CLI

CLI to show a schedule of cron expressions.

Installation

brew install winebarrel/cronplan/cronskd

Usage

Usage: cronskd [OPTION] [FILE]  -e string    end date (default: end of day)  -s string    start date (default: beginning of day)  -version    print version and exit
$ cat exprs.txt0 10 * * ? *15 12 * * ? *0 18 ? * MON-FRI *0 8 1 * ? *5 8-10 ? * MON-FRI *$ cronskd -s '2024-11-11' exprs.txtMon, 11 Nov 2024 08:05:00    5 8-10 ? * MON-FRI *Mon, 11 Nov 2024 09:05:00    5 8-10 ? * MON-FRI *Mon, 11 Nov 2024 10:00:00    0 10 * * ? *Mon, 11 Nov 2024 10:05:00    5 8-10 ? * MON-FRI *Mon, 11 Nov 2024 12:15:00    15 12 * * ? *Mon, 11 Nov 2024 18:00:00    0 18 ? * MON-FRI *$ cronskd -s '2024/11/12 10:00' -e 'Nov 13, 2024, 12:00' exprs.txtTue, 12 Nov 2024 10:00:000 10 * * ? *Tue, 12 Nov 2024 10:05:005 8-10 ? * MON-FRI *Tue, 12 Nov 2024 12:15:0015 12 * * ? *Tue, 12 Nov 2024 18:00:000 18 ? * MON-FRI *Wed, 13 Nov 2024 08:05:005 8-10 ? * MON-FRI *Wed, 13 Nov 2024 09:05:005 8-10 ? * MON-FRI *Wed, 13 Nov 2024 10:00:000 10 * * ? *Wed, 13 Nov 2024 10:05:005 8-10 ? * MON-FRI *

cf.https://pkg.go.dev/github.com/araddon/dateparse#readme-extended-example

Related Links


[8]ページ先頭

©2009-2025 Movatter.jp