Adapted from cronexpr
A cron expression parser and next occurrence calculator
import "time"
import "github.com/amasanelli/cron"
next := cron.MustParse("0 0 1 * 1", time.UTC).Next(time.Now())Parses the cron expression and sets it's timezone.
The cron expression must be written for the desired timezone; e.g., if the cron should run every day at 00:00 in Melbourne the cron expression should be "0 0 * * *" and the
timezone, _ = time.LoadLocation("Australia/Melbourne")It throws an error in case of failure.
Does the same as Parse, but it panics in case of failure
Calculares the next occurence for the cron expression and the given time. It converts the input to the timezone setted in the Parse/MustParse function to perform the calulation
Field name Mandatory? Allowed values Allowed special characters
---------- ---------- -------------- --------------------------
Minutes Yes 0-59 * / , -
Hours Yes 0-23 * / , -
Day of month Yes 1-31 * / , -
Month Yes 1-12 * / , -
Day of week Yes 0-6 * / , -
Asterisks indicate that the field matches all the allowed values; e.g., using an asterisk in the 4th field (months) means every month.
Slashes are used to indicate steps; e.g., */15 in the 1st field (minutes) means that the cron will run every 15 minutes
Commas are used to separate items of a list; e.g., 5-6,0-1 in the 5th field (dow) could be used to indicate a cron that runs from Friday to Monday
Hyphens define ranges of values; e.g., 0-6 in the 2nd field (hours) indicates the range of hours from 0 to 6, inclusive