{"id":13562589,"url":"https://github.com/dragonmantank/cron-expression","last_synced_at":"2025-10-05T18:31:22.006Z","repository":{"id":25852049,"uuid":"103715337","full_name":"dragonmantank/cron-expression","owner":"dragonmantank","description":"CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due","archived":false,"fork":true,"pushed_at":"2024-10-21T12:57:55.000Z","size":447,"stargazers_count":4557,"open_issues_count":21,"forks_count":123,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-10-29T19:20:08.804Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"mtdowling/cron-expression","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dragonmantank.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":["dragonmantank"]}},"created_at":"2017-09-16T01:31:41.000Z","updated_at":"2024-10-29T14:52:44.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/dragonmantank/cron-expression","commit_stats":{"total_commits":278,"total_committers":73,"mean_commits":3.808219178082192,"dds":0.7482014388489209,"last_synced_commit":"782ca5968ab8b954773518e9e49a6f892a34b2a8"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragonmantank%2Fcron-expression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragonmantank%2Fcron-expression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragonmantank%2Fcron-expression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragonmantank%2Fcron-expression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dragonmantank","download_url":"https://codeload.github.com/dragonmantank/cron-expression/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235432205,"owners_count":18989480,"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","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":["hacktoberfest"],"created_at":"2024-08-01T13:01:10.212Z","updated_at":"2025-10-05T18:31:16.702Z","avatar_url":"https://github.com/dragonmantank.png","language":"PHP","readme":"PHP Cron Expression Parser\n==========================\n\n[![Latest Stable Version](https://poser.pugx.org/dragonmantank/cron-expression/v/stable.png)](https://packagist.org/packages/dragonmantank/cron-expression) [![Total Downloads](https://poser.pugx.org/dragonmantank/cron-expression/downloads.png)](https://packagist.org/packages/dragonmantank/cron-expression) [![Tests](https://github.com/dragonmantank/cron-expression/actions/workflows/tests.yml/badge.svg)](https://github.com/dragonmantank/cron-expression/actions/workflows/tests.yml) [![StyleCI](https://github.styleci.io/repos/103715337/shield?branch=master)](https://github.styleci.io/repos/103715337)\n\nThe PHP cron expression parser can parse a CRON expression, determine if it is\ndue to run, calculate the next run date of the expression, and calculate the previous\nrun date of the expression.  You can calculate dates far into the future or past by\nskipping **n** number of matching dates.\n\nThe parser can handle increments of ranges (e.g. */12, 2-59/3), intervals (e.g. 0-9),\nlists (e.g. 1,2,3), **W** to find the nearest weekday for a given day of the month, **L** to\nfind the last day of the month, **L** to find the last given weekday of a month, and hash\n(#) to find the nth weekday of a given month.\n\nMore information about this fork can be found in the blog post [here](http://ctankersley.com/2017/10/12/cron-expression-update/). tl;dr - v2.0.0 is a major breaking change, and @dragonmantank can better take care of the project in a separate fork.\n\nInstalling\n==========\n\nAdd the dependency to your project:\n\n```bash\ncomposer require dragonmantank/cron-expression\n```\n\nUsage\n=====\n```php\n\u003c?php\n\nrequire_once '/vendor/autoload.php';\n\n// Works with predefined scheduling definitions\n$cron = new Cron\\CronExpression('@daily');\n$cron-\u003eisDue();\necho $cron-\u003egetNextRunDate()-\u003eformat('Y-m-d H:i:s');\necho $cron-\u003egetPreviousRunDate()-\u003eformat('Y-m-d H:i:s');\n\n// Works with complex expressions\n$cron = new Cron\\CronExpression('3-59/15 6-12 */15 1 2-5');\necho $cron-\u003egetNextRunDate()-\u003eformat('Y-m-d H:i:s');\n\n// Calculate a run date two iterations into the future\n$cron = new Cron\\CronExpression('@daily');\necho $cron-\u003egetNextRunDate(null, 2)-\u003eformat('Y-m-d H:i:s');\n\n// Calculate a run date relative to a specific time\n$cron = new Cron\\CronExpression('@monthly');\necho $cron-\u003egetNextRunDate('2010-01-12 00:00:00')-\u003eformat('Y-m-d H:i:s');\n```\n\nCRON Expressions\n================\n\nA CRON expression is a string representing the schedule for a particular command to execute.  The parts of a CRON schedule are as follows:\n\n```\n*   *   *   *   *\n-   -   -   -   -\n|   |   |   |   |\n|   |   |   |   |\n|   |   |   |   +----- day of week (0-7) (Sunday = 0 or 7) (or SUN-SAT)\n|   |   |   +--------- month (1-12) (or JAN-DEC)\n|   |   +------------- day of month (1-31)\n|   +----------------- hour (0-23)\n+--------------------- minute (0-59)\n```\n\nEach part of expression can also use wildcard, lists, ranges and steps:\n\n- wildcard - match always\n\t- `* * * * *` - At every minute.\n\t- day of week and day of month also support `?`, an alias to `*`\n- lists - match list of values, ranges and steps\n\t- e.g. `15,30 * * * *` - At minute 15 and 30.\n- ranges - match values in range\n\t- e.g. `1-9 * * * *` - At every minute from 1 through 9.\n- steps - match every nth value in range\n\t- e.g. `*/5 * * * *` - At every 5th minute.\n\t- e.g. `0-30/5 * * * *` - At every 5th minute from 0 through 30.\n- combinations\n\t- e.g. `0-14,30-44 * * * *` - At every minute from 0 through 14 and every minute from 30 through 44.\n\nYou can also use macro instead of an expression:\n\n- `@yearly`, `@annually` - At 00:00 on 1st of January. (same as `0 0 1 1 *`)\n- `@monthly` - At 00:00 on day-of-month 1. (same as `0 0 1 * *`)\n- `@weekly` - At 00:00 on Sunday. (same as `0 0 * * 0`)\n- `@daily`, `@midnight` - At 00:00. (same as `0 0 * * *`)\n- `@hourly` - At minute 0. (same as `0 * * * *`)\n\nDay of month extra features:\n\n- nearest weekday - weekday (Monday-Friday) nearest to the given day\n\t- e.g. `* * 15W * *` - At every minute on a weekday nearest to the 15th.\n\t- If you were to specify `15W` as the value, the meaning is: \"the nearest weekday to the 15th of the month\"\n\t  So if the 15th is a Saturday, the trigger will fire on Friday the 14th.\n\t  If the 15th is a Sunday, the trigger will fire on Monday the 16th.\n\t  If the 15th is a Tuesday, then it will fire on Tuesday the 15th.\n\t- However, if you specify `1W` as the value for day-of-month,\n\t  and the 1st is a Saturday, the trigger will fire on Monday the 3rd,\n\t  as it will not 'jump' over the boundary of a month's days.\n- last day of the month\n\t- e.g. `* * L * *` - At every minute on a last day-of-month.\n- last weekday of the month\n\t- e.g. `* * LW * *` - At every minute on a last weekday.\n\nDay of week extra features:\n\n- nth day\n\t- e.g. `* * * * 7#4` - At every minute on 4th Sunday.\n\t- 1-5\n\t- Every day of week repeats 4-5 times a month. To target the last one, use \"last day\" feature instead.\n- last day\n\t- e.g. `* * * * 7L` - At every minute on the last Sunday.\n\nRequirements\n============\n\n- PHP 7.2+\n- PHPUnit is required to run the unit tests\n- Composer is required to run the unit tests\n\nProjects that Use cron-expression\n=================================\n* Part of the [Laravel Framework](https://github.com/laravel/framework/)\n* Available as a [Symfony Bundle - setono/cron-expression-bundle](https://github.com/Setono/CronExpressionBundle)\n* Framework agnostic, PHP-based job scheduler - [Crunz](https://github.com/crunzphp/crunz)\n* Framework agnostic job scheduler - with locks, parallelism, per-second scheduling and more - [orisai/scheduler](https://github.com/orisai/scheduler)\n* Explain expression in English (and other languages) with [orisai/cron-expression-explainer](https://github.com/orisai/cron-expression-explainer)\n","funding_links":["https://github.com/sponsors/dragonmantank"],"categories":["PHP","类库"],"sub_categories":["未归类"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdragonmantank%2Fcron-expression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdragonmantank%2Fcron-expression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdragonmantank%2Fcron-expression/lists"}