CompareDateTimeText.php 847 B

1234567891011121314151617181920212223242526272829
  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. {
  15. $datetime1 = api_strtotime($values[0]);
  16. $datetime2 = api_strtotime($values[1]);
  17. if (strpos($operator, 'allow_empty') !== false) {
  18. $operator = str_replace('allow_empty', '', $operator);
  19. if (!$datetime2 || empty($datetime2)) {
  20. return true;
  21. }
  22. }
  23. $result = parent::validate(array($datetime1, $datetime2), $operator);
  24. return $result;
  25. }
  26. }