| 1 | cronexpr: command-line utility |
| 2 | ============================== |
| 3 | |
| 4 | A command-line utility written in Go to evaluate cron time expressions. |
| 5 | |
| 6 | It is based on the standalone Go library <https://github.com/gorhill/cronexpr>. |
| 7 | |
| 8 | ## Install |
| 9 | |
| 10 | go get github.com/gorhill/cronexpr |
| 11 | go install github.com/gorhill/cronexpr |
| 12 | |
| 13 | ## Usage |
| 14 | |
| 15 | cronexpr [options] "{cron expression}" |
| 16 | |
| 17 | ## Options |
| 18 | |
| 19 | `-l`: |
| 20 | |
| 21 | Go-compliant time layout to use for outputting time value(s), see <http://golang.org/pkg/time/#pkg-constants>. |
| 22 | |
| 23 | Default is `"Mon, 02 Jan 2006 15:04:05 MST"` |
| 24 | |
| 25 | `-n`: |
| 26 | |
| 27 | Number of resulting time values to output. |
| 28 | |
| 29 | Default is 1. |
| 30 | |
| 31 | `-t`: |
| 32 | |
| 33 | Whole or partial RFC3339 time value (i.e. `2006-01-02T15:04:05Z07:00`) against which the cron expression is evaluated. Examples of valid values include (assuming EST time zone): |
| 34 | |
| 35 | `13` = 2013-01-01T00:00:00-05:00 |
| 36 | `2013` = 2013-01-01T00:00:00-05:00 |
| 37 | `2013-08` = 2013-08-01T00:00:00-05:00 |
| 38 | `2013-08-31` = 2013-08-31T00:00:00-05:00 |
| 39 | `2013-08-31T12` = 2013-08-31T12:00:00-05:00 |
| 40 | `2013-08-31T12:40` = 2013-08-31T12:40:00-05:00 |
| 41 | `2013-08-31T12:40:35` = 2013-08-31T12:40:35-05:00 |
| 42 | `2013-08-31T12:40:35-10:00` = 2013-08-31T12:40:35-10:00 |
| 43 | |
| 44 | Default time is current time, and default time zone is local time zone. |
| 45 | |
| 46 | ## Examples |
| 47 | |
| 48 | #### Example 1 |
| 49 | |
| 50 | Midnight on December 31st of any year. |
| 51 | |
| 52 | Command: |
| 53 | |
| 54 | cronexpr -t="2013-08-31" -n=5 "0 0 31 12 *" |
| 55 | |
| 56 | Output (assuming computer is in EST time zone): |
| 57 | |
| 58 | # "0 0 31 12 *" + "2013-08-31T00:00:00-04:00" = |
| 59 | Tue, 31 Dec 2013 00:00:00 EST |
| 60 | Wed, 31 Dec 2014 00:00:00 EST |
| 61 | Thu, 31 Dec 2015 00:00:00 EST |
| 62 | Sat, 31 Dec 2016 00:00:00 EST |
| 63 | Sun, 31 Dec 2017 00:00:00 EST |
| 64 | |
| 65 | #### Example 2 |
| 66 | |
| 67 | 2pm on February 29th of any year. |
| 68 | |
| 69 | Command: |
| 70 | |
| 71 | cronexpr -t=2000 -n=10 "0 14 29 2 *" |
| 72 | |
| 73 | Output (assuming computer is in EST time zone): |
| 74 | |
| 75 | # "0 14 29 2 *" + "2000-01-01T00:00:00-05:00" = |
| 76 | Tue, 29 Feb 2000 14:00:00 EST |
| 77 | Sun, 29 Feb 2004 14:00:00 EST |
| 78 | Fri, 29 Feb 2008 14:00:00 EST |
| 79 | Wed, 29 Feb 2012 14:00:00 EST |
| 80 | Mon, 29 Feb 2016 14:00:00 EST |
| 81 | Sat, 29 Feb 2020 14:00:00 EST |
| 82 | Thu, 29 Feb 2024 14:00:00 EST |
| 83 | Tue, 29 Feb 2028 14:00:00 EST |
| 84 | Sun, 29 Feb 2032 14:00:00 EST |
| 85 | Fri, 29 Feb 2036 14:00:00 EST |
| 86 | |
| 87 | #### Example 3 |
| 88 | |
| 89 | 12pm on the work day closest to the 15th of March and every three month |
| 90 | thereafter. |
| 91 | |
| 92 | Command: |
| 93 | |
| 94 | cronexpr -t=2013-09-01 -n=5 "0 12 15W 3/3 *" |
| 95 | |
| 96 | Output (assuming computer is in EST time zone): |
| 97 | |
| 98 | # "0 12 15W 3/3 *" + "2013-09-01T00:00:00-04:00" = |
| 99 | Mon, 16 Sep 2013 12:00:00 EDT |
| 100 | Mon, 16 Dec 2013 12:00:00 EST |
| 101 | Fri, 14 Mar 2014 12:00:00 EDT |
| 102 | Mon, 16 Jun 2014 12:00:00 EDT |
| 103 | Mon, 15 Sep 2014 12:00:00 EDT |
| 104 | |
| 105 | #### Example 4 |
| 106 | |
| 107 | Midnight on the fifth Saturday of any month (twist: not all months have a 5th |
| 108 | specific day of week). |
| 109 | |
| 110 | Command: |
| 111 | |
| 112 | cronexpr -t=2013-09-02 -n 5 "0 0 * * 6#5" |
| 113 | |
| 114 | Output (assuming computer is in EST time zone): |
| 115 | |
| 116 | # "0 0 * * 6#5" + "2013-09-02T00:00:00-04:00" = |
| 117 | Sat, 30 Nov 2013 00:00:00 EST |
| 118 | Sat, 29 Mar 2014 00:00:00 EDT |
| 119 | Sat, 31 May 2014 00:00:00 EDT |
| 120 | Sat, 30 Aug 2014 00:00:00 EDT |
| 121 | Sat, 29 Nov 2014 00:00:00 EST |
| 122 |