1<?php
2
3namespace Cron;
4
5use DateTime;
6
7/**
8 * Month field.  Allows: * , / -
9 */
10class MonthField extends AbstractField
11{
12    public function isSatisfiedBy(DateTime $date, $value)
13    {
14        // Convert text month values to integers
15        $value = str_ireplace(
16            array(
17                'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',
18                'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'
19            ),
20            range(1, 12),
21            $value
22        );
23
24        return $this->isSatisfied($date->format('m'), $value);
25    }
26
27    public function increment(DateTime $date, $invert = false)
28    {
29        if ($invert) {
30            $date->modify('last day of previous month');
31            $date->setTime(23, 59);
32        } else {
33            $date->modify('first day of next month');
34            $date->setTime(0, 0);
35        }
36
37        return $this;
38    }
39
40    public function validate($value)
41    {
42        return (bool) preg_match('/^[\*,\/\-0-9A-Z]+$/', $value);
43    }
44}
45