CompareDateTimeText.php 862 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * QuickForm rule to compare 2 dates.
  5. */
  6. class HTML_QuickForm_Rule_CompareDateTimeText extends HTML_QuickForm_Rule_Compare
  7. {
  8. /**
  9. * Validate 2 dates.
  10. *
  11. * @param string $operator The operator to use (default '==')
  12. *
  13. * @return bool True if the 2 given dates match the operator
  14. */
  15. public function validate($values, $operator = null)
  16. {
  17. $datetime1 = api_strtotime($values[0]);
  18. $datetime2 = api_strtotime($values[1]);
  19. if (strpos($operator, 'allow_empty') !== false) {
  20. $operator = str_replace('allow_empty', '', $operator);
  21. if (!$datetime2 || empty($datetime2)) {
  22. return true;
  23. }
  24. }
  25. $result = parent::validate([$datetime1, $datetime2], $operator);
  26. return $result;
  27. }
  28. }