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.

YearField.php 779 B

4 years ago
12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace Cron;
  3. use DateTime;
  4. /**
  5. * Year field. Allows: * , / -
  6. */
  7. class YearField extends AbstractField
  8. {
  9. public function isSatisfiedBy(DateTime $date, $value)
  10. {
  11. return $this->isSatisfied($date->format('Y'), $value);
  12. }
  13. public function increment(DateTime $date, $invert = false)
  14. {
  15. if ($invert) {
  16. $date->modify('-1 year');
  17. $date->setDate($date->format('Y'), 12, 31);
  18. $date->setTime(23, 59, 0);
  19. } else {
  20. $date->modify('+1 year');
  21. $date->setDate($date->format('Y'), 1, 1);
  22. $date->setTime(0, 0, 0);
  23. }
  24. return $this;
  25. }
  26. public function validate($value)
  27. {
  28. return (bool) preg_match('/^[\*,\/\-0-9]+$/', $value);
  29. }
  30. }