cvs: pear /Validate Validate.php

From: Date: Thu, 16 Nov 2006 10:55:14 +0000
Subject: cvs: pear /Validate Validate.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-43096@lists.php.net to get a copy of this message
amir Thu Nov 16 10:55:14 2006 UTC Modified files: /pear/Validate Validate.php Log: - Now RFC822 compliant dates are comfortable with min and max stuff http://cvs.php.net/viewvc.cgi/pear/Validate/Validate.php?r1=1.101&r2=1.102&diff_format=u Index: pear/Validate/Validate.php diff -u pear/Validate/Validate.php:1.101 pear/Validate/Validate.php:1.102 --- pear/Validate/Validate.php:1.101 Wed Nov 15 12:58:28 2006 +++ pear/Validate/Validate.php Thu Nov 16 10:55:14 2006 @@ -32,7 +32,7 @@ * @author Pierre-Alain Joye <pajoye@php.net> * @copyright 1997-2005 Pierre-Alain Joye,Tomas V.V.Cox * @license http://www.opensource.org/licenses/bsd-license.php New BSD License - * @version CVS: $Id: Validate.php,v 1.101 2006/11/15 12:58:28 amir Exp $ + * @version CVS: $Id: Validate.php,v 1.102 2006/11/16 10:55:14 amir Exp $ * @link http://pear.php.net/package/Validate */ @@ -456,17 +456,23 @@ if (strtolower($format) == 'rfc822_compliant') { $preg = '&^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),) \s+ - (?:\d\d) \s+ - (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \s+ - (?:\d\d(\d\d)?) \s+ - (?:\d\d):(?:\d\d)(:(?:\d\d))? \s+ - (?:([+-]\d\d\d\d)|UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|[A-IK-Za-ik-z])$&xi'; + (?:(\d{2})?) \s+ + (?:(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)?) \s+ + (?:(\d{2}(\d{2})?)?) \s+ + (?:\d{2}):(?:\d{2})(:(?:\d{2}))? \s+ + (?:[+-]\d{4}|UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|[A-IK-Za-ik-z])$&xi'; - if (!preg_match($preg, $date)) { + if (!preg_match($preg, $date, $matches)) { return false; - } else { - return true; } + + $year = $matches[4]; + $months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', + 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); + $month = array_keys($months, $matches[3]); + $month = $month[0]+1; + $day = $matches[2]; + $weekday= $matches[1]; } else { $date_len = strlen($format); for ($i = 0; $i < $date_len; $i++) { @@ -551,7 +557,7 @@ } } // there is remaing data, we don't want it - if (strlen($date)) { + if (strlen($date) && (strtolower($format) != 'rfc822_compliant')) { return false; } @@ -560,6 +566,12 @@ return false; } + if (strtolower($format) == 'rfc822_compliant') { + if ($weekday != date("D", mktime(0, 0, 0, $month, $day, $year))) { + return false; + } + } + if ($min) { include_once 'Date/Calc.php'; if (is_a($min, 'Date') &&

« previous php.pear.cvs (#43096) next »