Files
apimacro/vendor/dragonmantank/cron-expression/src/Cron/MonthField.php

62 lines
1.3 KiB
PHP
Raw Normal View History

2024-05-07 12:17:25 +02:00
<?php
2024-08-13 13:44:16 +00:00
declare(strict_types=1);
2024-05-07 12:17:25 +02:00
namespace Cron;
use DateTimeInterface;
/**
2024-08-13 13:44:16 +00:00
* Month field. Allows: * , / -.
2024-05-07 12:17:25 +02:00
*/
class MonthField extends AbstractField
{
/**
2024-08-13 13:44:16 +00:00
* {@inheritdoc}
2024-05-07 12:17:25 +02:00
*/
protected $rangeStart = 1;
/**
2024-08-13 13:44:16 +00:00
* {@inheritdoc}
2024-05-07 12:17:25 +02:00
*/
protected $rangeEnd = 12;
/**
2024-08-13 13:44:16 +00:00
* {@inheritdoc}
2024-05-07 12:17:25 +02:00
*/
protected $literals = [1 => 'JAN', 2 => 'FEB', 3 => 'MAR', 4 => 'APR', 5 => 'MAY', 6 => 'JUN', 7 => 'JUL',
2024-08-13 13:44:16 +00:00
8 => 'AUG', 9 => 'SEP', 10 => 'OCT', 11 => 'NOV', 12 => 'DEC', ];
2024-05-07 12:17:25 +02:00
/**
2024-08-13 13:44:16 +00:00
* {@inheritdoc}
2024-05-07 12:17:25 +02:00
*/
2024-08-13 13:44:16 +00:00
public function isSatisfiedBy(DateTimeInterface $date, $value, bool $invert): bool
2024-05-07 12:17:25 +02:00
{
2024-08-13 13:44:16 +00:00
if ($value === '?') {
2024-05-07 12:17:25 +02:00
return true;
}
$value = $this->convertLiterals($value);
2024-08-13 13:44:16 +00:00
return $this->isSatisfied((int) $date->format('m'), $value);
2024-05-07 12:17:25 +02:00
}
/**
* @inheritDoc
*
2024-08-13 13:44:16 +00:00
* @param \DateTime|\DateTimeImmutable $date
2024-05-07 12:17:25 +02:00
*/
2024-08-13 13:44:16 +00:00
public function increment(DateTimeInterface &$date, $invert = false, $parts = null): FieldInterface
2024-05-07 12:17:25 +02:00
{
2024-08-13 13:44:16 +00:00
if (! $invert) {
$date = $date->modify('first day of next month');
$date = $date->setTime(0, 0);
2024-05-07 12:17:25 +02:00
} else {
2024-08-13 13:44:16 +00:00
$date = $date->modify('last day of previous month');
$date = $date->setTime(23, 59);
2024-05-07 12:17:25 +02:00
}
return $this;
}
}