DateCompare.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. // $Id: DateCompare.php 6187 2005-09-07 10:23:57Z bmol $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004-2005 Dokeos S.A.
  7. Copyright (c) Bart Mollet, Hogeschool Gent
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  16. Mail: info@dokeos.com
  17. ==============================================================================
  18. */
  19. require_once 'HTML/QuickForm/Rule/Compare.php';
  20. /**
  21. * QuickForm rule to compare 2 dates
  22. */
  23. class HTML_QuickForm_Rule_DateCompare extends HTML_QuickForm_Rule_Compare
  24. {
  25. /**
  26. * Validate 2 dates
  27. * @param array $values Array with the 2 dates. Each element in this array
  28. * should be an array width keys F (month), d (day) and Y (year)
  29. * @param string $operator The operator to use (default '==')
  30. * @return boolean True if the 2 given dates match the operator
  31. */
  32. function validate($values, $operator = null)
  33. {
  34. $date1 = $values[0];
  35. $date2 = $values[1];
  36. $time1 = mktime($date1['H'],$date1['i'],0,$date1['F'],$date1['d'],$date1['Y']);
  37. $time2 = mktime($date2['H'],$date2['i'],0,$date2['F'],$date2['d'],$date2['Y']);
  38. return parent::validate(array($time1,$time2),$operator);
  39. }
  40. }
  41. ?>