{"id":31064907,"url":"https://github.com/pkg6/cronexpr","last_synced_at":"2025-09-15T15:05:50.122Z","repository":{"id":299341905,"uuid":"1002709707","full_name":"pkg6/cronexpr","owner":"pkg6","description":"Cron expression parser in Go language (golang)","archived":false,"fork":false,"pushed_at":"2025-06-16T02:59:00.000Z","size":96,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-16T04:14:45.195Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pkg6.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-16T02:45:53.000Z","updated_at":"2025-06-16T02:59:00.000Z","dependencies_parsed_at":"2025-06-16T04:14:47.681Z","dependency_job_id":"13ff7675-c58d-4c3f-a481-c53f20c595b4","html_url":"https://github.com/pkg6/cronexpr","commit_stats":null,"previous_names":["pkg6/cronexpr"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/pkg6/cronexpr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg6%2Fcronexpr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg6%2Fcronexpr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg6%2Fcronexpr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg6%2Fcronexpr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pkg6","download_url":"https://codeload.github.com/pkg6/cronexpr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg6%2Fcronexpr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275274476,"owners_count":25435786,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-15T02:00:09.272Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-15T15:05:45.549Z","updated_at":"2025-09-15T15:05:50.114Z","avatar_url":"https://github.com/pkg6.png","language":"Go","readme":"Golang Cron expression parser\n=============================\nGiven a cron expression and a time stamp, you can get the next time stamp which satisfies the cron expression.\n\nIn another project, I decided to use cron expression syntax to encode scheduling information. Thus this standalone library to parse and apply time stamps to cron expressions.\n\nThe time-matching algorithm in this implementation is efficient, it avoids as much as possible to guess the next matching time stamp, a common technique seen in a number of implementations out there.\n\nThere is also a companion command-line utility to evaluate cron time expressions: \u003chttps://github.com/pkg6/cronexpr/tree/master/cronexpr\u003e (which of course uses this library).\n\nImplementation\n--------------\nThe reference documentation for this implementation is found at\n\u003chttps://en.wikipedia.org/wiki/Cron#CRON_expression\u003e, which I copy/pasted here (laziness!) with modifications where this implementation differs:\n\n    Field name     Mandatory?   Allowed values    Allowed special characters\n    ----------     ----------   --------------    --------------------------\n    Seconds        No           0-59              * / , -\n    Minutes        Yes          0-59              * / , -\n    Hours          Yes          0-23              * / , -\n    Day of month   Yes          1-31              * / , - L W\n    Month          Yes          1-12 or JAN-DEC   * / , -\n    Day of week    Yes          0-6 or SUN-SAT    * / , - L #\n    Year           No           1970–2099         * / , -\n\n#### Asterisk ( * )\nThe asterisk indicates that the cron expression matches for all values of the field. E.g., using an asterisk in the 4th field (month) indicates every month. \n\n#### Slash ( / )\nSlashes describe increments of ranges. For example `3-59/15` in the minute field indicate the third minute of the hour and every 15 minutes thereafter. The form `*/...` is equivalent to the form \"first-last/...\", that is, an increment over the largest possible range of the field.\n\n#### Comma ( , )\nCommas are used to separate items of a list. For example, using `MON,WED,FRI` in the 5th field (day of week) means Mondays, Wednesdays and Fridays.\n\n#### Hyphen ( - )\nHyphens define ranges. For example, 2000-2010 indicates every year between 2000 and 2010 AD, inclusive.\n\n#### L\n`L` stands for \"last\". When used in the day-of-week field, it allows you to specify constructs such as \"the last Friday\" (`5L`) of a given month. In the day-of-month field, it specifies the last day of the month.\n\n#### W\nThe `W` character is allowed for the day-of-month field. This character is used to specify the business day (Monday-Friday) nearest the given day. As an example, if you were to specify `15W` as the value for the day-of-month field, the meaning is: \"the nearest business day to the 15th of the month.\"\n\nSo, if the 15th is a Saturday, the trigger fires on Friday the 14th. If the 15th is a Sunday, the trigger fires on Monday the 16th. If the 15th is a Tuesday, then it fires on Tuesday the 15th. However if you specify `1W` as the value for day-of-month, and the 1st is a Saturday, the trigger fires on Monday the 3rd, as it does not 'jump' over the boundary of a month's days.\n\nThe `W` character can be specified only when the day-of-month is a single day, not a range or list of days.\n\nThe `W` character can also be combined with `L`, i.e. `LW` to mean \"the last business day of the month.\"\n\n#### Hash ( # )\n`#` is allowed for the day-of-week field, and must be followed by a number between one and five. It allows you to specify constructs such as \"the second Friday\" of a given month.\n\nPredefined cron expressions\n---------------------------\n(Copied from \u003chttps://en.wikipedia.org/wiki/Cron#Predefined_scheduling_definitions\u003e, with text modified according to this implementation) \n\n    Entry       Description                                                             Equivalent to\n    @annually   Run once a year at midnight in the morning of January 1                 0 0 0 1 1 * *\n    @yearly     Run once a year at midnight in the morning of January 1                 0 0 0 1 1 * *\n    @monthly    Run once a month at midnight in the morning of the first of the month   0 0 0 1 * * *\n    @weekly     Run once a week at midnight in the morning of Sunday                    0 0 0 * * 0 *\n    @daily      Run once a day at midnight                                              0 0 0 * * * *\n    @hourly     Run once an hour at the beginning of the hour                           0 0 * * * * *\n    @reboot     Not supported\n\nOther details\n-------------\n* If only six fields are present, a `0` second field is prepended, that is, `* * * * * 2013` internally become `0 * * * * * 2013`.\n* If only five fields are present, a `0` second field is prepended and a wildcard year field is appended, that is, `* * * * Mon` internally become `0 * * * * Mon *`.\n* Domain for day-of-week field is [0-7] instead of [0-6], 7 being Sunday (like 0). This to comply with http://linux.die.net/man/5/crontab#.\n* As of now, the behavior of the code is undetermined if a malformed cron expression is supplied\n\nInstall\n-------\n    go get github.com/pkg6/cronexpr\n\nUsage\n-----\nImport the library:\n\n    import \"github.com/pkg6/cronexpr\"\n    import \"time\"\n\nSimplest way:\n\n    nextTime := cronexpr.MustParse(\"0 0 29 2 *\").Next(time.Now())\n\nAssuming `time.Now()` is \"2013-08-29 09:28:00\", then `nextTime` will be \"2016-02-29 00:00:00\".\n\nYou can keep the returned Expression pointer around if you want to reuse it:\n\n    expr := cronexpr.MustParse(\"0 0 29 2 *\")\n    nextTime := expr.Next(time.Now())\n    ...\n    nextTime = expr.Next(nextTime)\n\nUse `time.IsZero()` to find out whether a valid time was returned. For example,\n\n    cronexpr.MustParse(\"* * * * * 1980\").Next(time.Now()).IsZero()\n\nwill return `true`, whereas\n\n    cronexpr.MustParse(\"* * * * * 2050\").Next(time.Now()).IsZero()\n\nwill return `false` (as of 2013-08-29...)\n\nYou may also query for `n` next time stamps:\n\n    cronexpr.MustParse(\"0 0 29 2 *\").NextN(time.Now(), 5)\n\nwhich returns a slice of time.Time objects, containing the following time stamps (as of 2013-08-30):\n\n    2016-02-29 00:00:00\n    2020-02-29 00:00:00\n    2024-02-29 00:00:00\n    2028-02-29 00:00:00\n    2032-02-29 00:00:00\n\nThe time zone of time values returned by `Next` and `NextN` is always the\ntime zone of the time value passed as argument, unless a zero time value is\nreturned.\n\nAPI\n---\n\u003chttp://godoc.org/github.com/pkg6/cronexpr\u003e\n\nLicense\n-------\n\nLicense: pick the one which suits you best:\n\n- GPL v3 see \u003chttps://www.gnu.org/licenses/gpl.html\u003e\n- APL v2 see \u003chttp://www.apache.org/licenses/LICENSE-2.0\u003e\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkg6%2Fcronexpr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpkg6%2Fcronexpr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkg6%2Fcronexpr/lists"}