MonthField.php 883 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace Cron;
  3. use DateTime;
  4. /**
  5. * Month field. Allows: * , / -
  6. */
  7. class MonthField extends AbstractField
  8. {
  9. protected $rangeStart = 1;
  10. protected $rangeEnd = 12;
  11. protected $literals = [1 => 'JAN', 2 => 'FEB', 3 => 'MAR', 4 => 'APR', 5 => 'MAY', 6 => 'JUN', 7 => 'JUL',
  12. 8 => 'AUG', 9 => 'SEP', 10 => 'OCT', 11 => 'NOV', 12 => 'DEC'];
  13. public function isSatisfiedBy(DateTime $date, $value)
  14. {
  15. $value = $this->convertLiterals($value);
  16. return $this->isSatisfied($date->format('m'), $value);
  17. }
  18. public function increment(DateTime $date, $invert = false)
  19. {
  20. if ($invert) {
  21. $date->modify('last day of previous month');
  22. $date->setTime(23, 59);
  23. } else {
  24. $date->modify('first day of next month');
  25. $date->setTime(0, 0);
  26. }
  27. return $this;
  28. }
  29. }