CoreFiles by mySites.guru
MonthField.php59 lines, 1,265 bytes, from Joomla_4.1.2-Stable-Full_Package.zip
Raw History Compare with 4.1.1
md5
f0e2e776eb576b418fb03d4c5d1020a8
sha1
cfeb955c127c7ea923f5dac0cfa34fa6d5267266
sha256
043f9f28d846f20a0c451dafb97a6465ea5b1a89cc679434587530f3f423a744
<?php

declare(strict_types=1);

namespace Cron;

use DateTimeInterface;

/**
 * Month field.  Allows: * , / -.
 */
class MonthField extends AbstractField
{
    /**
     * {@inheritdoc}
     */
    protected $rangeStart = 1;

    /**
     * {@inheritdoc}
     */
    protected $rangeEnd = 12;

    /**
     * {@inheritdoc}
     */
    protected $literals = [1 => 'JAN', 2 => 'FEB', 3 => 'MAR', 4 => 'APR', 5 => 'MAY', 6 => 'JUN', 7 => 'JUL',
        8 => 'AUG', 9 => 'SEP', 10 => 'OCT', 11 => 'NOV', 12 => 'DEC', ];

    /**
     * {@inheritdoc}
     */
    public function isSatisfiedBy(DateTimeInterface $date, $value): bool
    {
        if ($value == '?') {
            return true;
        }

        $value = $this->convertLiterals($value);

        return $this->isSatisfied((int) $date->format('m'), $value);
    }

    /**
     * @inheritDoc
     *
     * @param \DateTime|\DateTimeImmutable $date
     */
    public function increment(DateTimeInterface &$date, $invert = false, $parts = null): FieldInterface
    {
        if ($invert) {
            $date = $date->modify('last day of previous month')->setTime(23, 59);
        } else {
            $date = $date->modify('first day of next month')->setTime(0, 0);
        }

        return $this;
    }
}

The same content is in 21 releases, Joomla 4.1.0-beta1 to 4.2.0-alpha2. See them all, or every version of this file.