Overview

Packages

  • Auth
  • Config
  • Controller
  • Date
  • Db
  • Feed
    • Abstract
    • Writers
  • File
    • Decorator
  • Form
    • Element
  • Image
  • Log
    • Writer
  • Net
    • Exception
  • None
  • PHP
  • PHPMailer
  • Session
  • Util
  • Validate
    • Validator
  • Zend
    • Registry

Classes

  • Validate_Validator_Alnum
  • Validate_Validator_Alpha
  • Validate_Validator_Cp
  • Validate_Validator_Date
  • Validate_Validator_Digit
  • Validate_Validator_Email
  • Validate_Validator_Equal
  • Validate_Validator_Interval
  • Validate_Validator_Time
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Pry Framework
  4:  *
  5:  * LICENSE
  6:  *
  7:  * This source file is subject to the new BSD license that is bundled
  8:  * with this package in the file LICENSE.txt.
  9:  * 
 10:  * @version $Revision: 276 $
 11:  */
 12: 
 13: /**
 14:  * Validateur de date.
 15:  * Permet de valider des date du type fr,us,sql,sqldatetime
 16:  * @category Pry
 17:  * @package Validate
 18:  * @subpackage Validate_Validator
 19:  * @version 1.0.0 
 20:  * @author Olivier ROGER <oroger.fr>
 21:  * 
 22:  * <code>
 23:  * $factory = new Validate_Validate();
 24:  * $factory -> addValidator('Date','fr');
 25:  * </code>
 26:  *       
 27:  *
 28:  */
 29: class Validate_Validator_Date extends Validate_Abstract
 30: {
 31:     const DATE_SQL          = 'sql';
 32:     const DATE_SQLDATETIME  = 'sqldatetime';
 33:     const DATE_FR           = 'fr';
 34:     const DATE_US           = 'us';
 35:     
 36:     private $format;
 37:     
 38:     public function __construct($format='fr')
 39:     {
 40:         $this->errorMsg = "n'est pas une date valide";
 41:         $this->format = $format;
 42:     }
 43:     
 44:     /**
 45:      * Valide la date en fonction de son format
 46:      *
 47:      * @param string $date
 48:      * @return boolean
 49:      */
 50:     public function isValid($date)
 51:     {
 52:         switch($this->format)
 53:         {
 54:             case self::DATE_FR:
 55:             {
 56:                 if(preg_match('`^\d{1,2}/\d{1,2}/(\d{4}|\d{2})$`',$date))
 57:                 {
 58:                     list($d,$m,$y) = explode('/',$date);
 59:                     if(checkdate($m,$d,$y))
 60:                         return true;    
 61:                 }
 62:                 return false;   
 63:             }
 64:             case self::DATE_US:
 65:             {
 66:                 if(preg_match('`^\d{1,2}/\d{1,2}/(\d{4}|\d{2})$`',$date))
 67:                 {
 68:                     list($m,$d,$y) = explode('/',$date);
 69:                     if(checkdate($m,$d,$y))
 70:                         return true;    
 71:                 }
 72:                 return false;   
 73:             }
 74:             case self::DATE_SQL:
 75:             {
 76:                 if(preg_match('`^(\d{4}|\d{2})-\d{1,2}-\d{1,2}$`',$date))   
 77:                 {
 78:                     list($y,$m,$d) = explode('-',$date);
 79:                     if(checkdate($m,$d,$y))
 80:                         return true;
 81:                 }
 82:                 return false;
 83:             }
 84:             case self::DATE_SQLDATETIME:
 85:             {
 86:                 if(preg_match('`^(\d{4}|\d{2})-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}$`',$date))   
 87:                 {
 88:                     list($date,$heure)  = explode(' ',$date);
 89:                     list($y,$m,$d)      = explode('-',$date);
 90:                     list($h,$mi,$s)     = explode(':',$heure);
 91:                     if(checkdate($m,$d,$y) && ($h>=0 && $h<24) && ($mi>=0 && $mi<60) && ($s>=0 && $s<60))
 92:                         return true;
 93:                 }
 94:                 return false;   
 95:             }
 96:             default:
 97:                 break;
 98:         }
 99:     }
100: }
101:  ?>
Pry Framework API documentation generated by ApiGen 2.6.1