AbstractField.php
1 year ago
CronExpression.php
8 months ago
DayOfMonthField.php
1 year ago
DayOfWeekField.php
1 year ago
FieldFactory.php
1 year ago
FieldFactoryInterface.php
1 year ago
FieldInterface.php
1 year ago
HoursField.php
1 year ago
MinutesField.php
1 year ago
MonthField.php
1 year ago
index.php
1 year ago
MonthField.php
32 lines
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | namespace Cron; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use DateTimeInterface; |
| 6 | class MonthField extends AbstractField |
| 7 | { |
| 8 | protected $rangeStart = 1; |
| 9 | protected $rangeEnd = 12; |
| 10 | protected $literals = [1 => 'JAN', 2 => 'FEB', 3 => 'MAR', 4 => 'APR', 5 => 'MAY', 6 => 'JUN', 7 => 'JUL', |
| 11 | 8 => 'AUG', 9 => 'SEP', 10 => 'OCT', 11 => 'NOV', 12 => 'DEC', ]; |
| 12 | public function isSatisfiedBy(DateTimeInterface $date, $value, bool $invert): bool |
| 13 | { |
| 14 | if ($value === '?') { |
| 15 | return true; |
| 16 | } |
| 17 | $value = $this->convertLiterals($value); |
| 18 | return $this->isSatisfied((int) $date->format('m'), $value); |
| 19 | } |
| 20 | public function increment(DateTimeInterface &$date, $invert = false, $parts = null): FieldInterface |
| 21 | { |
| 22 | if (! $invert) { |
| 23 | $date = $date->modify('first day of next month'); |
| 24 | $date = $date->setTime(0, 0); |
| 25 | } else { |
| 26 | $date = $date->modify('last day of previous month'); |
| 27 | $date = $date->setTime(23, 59); |
| 28 | } |
| 29 | return $this; |
| 30 | } |
| 31 | } |
| 32 |