Skip to content

Commit

Permalink
midnight is also an allowed shortcut in crontab (#117)
Browse files Browse the repository at this point in the history
@see https://manpages.debian.org/buster/cron/crontab.5.en.html

this adds the `@midnight` to the mapping which is the same as `@daily`.
But since it is available in some cron implementations it should not be
indicated as invalid.

Signed-off-by: BlackEagle <ike.devolder@gmail.com>
  • Loading branch information
BlackIkeEagle committed Jan 5, 2022
1 parent 4f6482a commit cc1d62c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ This library also supports a few macros:
* `@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` - Run once a day, midnight - `0 0 * * *`
* `@daily`, `@midnight` - Run once a day, midnight - `0 0 * * *`
* `@hourly` - Run once an hour, first minute - `0 * * * *`

Requirements
Expand Down
3 changes: 2 additions & 1 deletion src/Cron/CronExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CronExpression
public const DAY = 2;
public const MONTH = 3;
public const WEEKDAY = 4;

/** @deprecated */
public const YEAR = 5;

Expand All @@ -42,6 +42,7 @@ class CronExpression
'@monthly' => '0 0 1 * *',
'@weekly' => '0 0 * * 0',
'@daily' => '0 0 * * *',
'@midnight' => '0 0 * * *',
'@hourly' => '0 * * * *',
];

Expand Down
2 changes: 2 additions & 0 deletions tests/Cron/CronExpressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public function testConstructorRecognizesTemplates(): void
$this->assertSame('0 0 1 1 *', (new CronExpression('@annually'))->getExpression());
$this->assertSame('0 0 1 1 *', (new CronExpression('@yearly'))->getExpression());
$this->assertSame('0 0 * * 0', (new CronExpression('@weekly'))->getExpression());
$this->assertSame('0 0 * * *', (new CronExpression('@daily'))->getExpression());
$this->assertSame('0 0 * * *', (new CronExpression('@midnight'))->getExpression());
}

/**
Expand Down

0 comments on commit cc1d62c

Please sign in to comment.