. */ /** * Doctrine_Validator_Timestamp * * @package Doctrine * @subpackage Validator * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.org * @since 1.0 * @version $Revision: 3884 $ * @author Mark Pearson */ class Doctrine_Validator_Timestamp { /** * checks if given value is a valid timestamp (YYYY-MM-DD HH:MM:SS) * * @param mixed $value * @return boolean */ public function validate($value) { if ($value === null) { return true; } if (!preg_match('/^ *[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} *$/', $value)) { return false; } list($date, $time) = explode(' ', trim($value)); $dateValidator = Doctrine_Validator::getValidator('date'); $timeValidator = Doctrine_Validator::getValidator('time'); if (!$dateValidator->validate($date)) { return false; } if (!$timeValidator->validate($time)) { return false; } return true; } }