CompareDateTimeText.php 834 B

123456789101112131415161718192021222324252627
  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. * @param string $operator The operator to use (default '==')
  11. * @return boolean True if the 2 given dates match the operator
  12. */
  13. function validate($values, $operator = null) {
  14. $datetime1 = api_strtotime($values[0]);
  15. $datetime2 = api_strtotime($values[1]);
  16. if (strpos($operator, 'allow_empty') !== false) {
  17. $operator = str_replace('allow_empty', '', $operator);
  18. if (!$datetime2 || empty($datetime2)) {
  19. return true;
  20. }
  21. }
  22. $result = parent::validate(array($datetime1, $datetime2), $operator);
  23. return $result;
  24. }
  25. }