From 5037e23f2c655d493186b0d092704f36a3f28e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Barto=C5=A1?= Date: Mon, 4 Mar 2024 11:05:18 +0100 Subject: [PATCH] ExplainCommand --- CHANGELOG.md | 2 + src/Command/ExplainCommand.php | 69 ++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/Command/ExplainCommand.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 027dea7..15293e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added +- `ExplainCommand` + - explains cron expression syntax - `ListCommand` - adds `--explain` option to explain whole expression diff --git a/src/Command/ExplainCommand.php b/src/Command/ExplainCommand.php new file mode 100644 index 0000000..746787f --- /dev/null +++ b/src/Command/ExplainCommand.php @@ -0,0 +1,69 @@ +explainSyntax($output); + + return 0; + } + + private function explainSyntax(OutputInterface $output): void + { + $output->writeln( + <<<'CMD' +* * * * * +- - - - - +| | | | | +| | | | | +| | | | +----- day of week (0-7) (Sunday = 0 or 7) (or SUN-SAT) +| | | +--------- month (1-12) (or JAN-DEC) +| | +------------- day of month (1-31) +| +----------------- hour (0-23) ++--------------------- minute (0-59) + +Each part of expression can also use wildcard, lists, ranges and steps: + +- wildcard - * * * * * - At every minute. +- lists - e.g. 15,30 * * * * - At minute 15 and 30. +- ranges - e.g. 1-9 * * * * - At every minute from 1 through 9. +- steps + - e.g. */5 * * * * - At every 5th minute. + - e.g. 0-30/5 * * * * - At every 5th minute from 0 through 30. +- combinations - e.g. 0-14,30-44 * * * * - At every minute from 0 through 14 and every minute from 30 through 44. + +You can also use macro instead of an expression: + +- @yearly, @annually - Run once a year, midnight, Jan. 1 - 0 0 1 1 * +- @monthly - Run once a month, midnight, first of month - 0 0 1 * * +- @weekly - Run once a week, midnight on Sun - 0 0 * * 0 +- @daily, @midnight - Run once a day, midnight - 0 0 * * * +- @hourly - Run once an hour, first minute - 0 * * * * + +Although they are not part of cron expression syntax, you can also add to job: + +- seconds - repeat job every n seconds +- timezone - run only when cron expression matches within given timezone +CMD, + ); + } + +}