You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

45 lines
988 B

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