<?php
/*
* Copyright (C) 2014 Everton
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* This file is a simple example of use Ptk\utils\Validator for testing an validate dates.
*/
function show_validation($date, $rules){
global $onerror;
if(\Ptk\utils\Validator::date($date, $rules, true)){
echo "This date $date is VALID.".PHP_EOL;
}else{
echo "This date $date is INVALID.".PHP_EOL;
echo "Invalid for: ".PHP_EOL;
echo join(', ', $onerror);
}
}
try{
require 'examples.inc.php';
//testing date from timestamp
$date = time();//a timestamp for validation
$rules = array(
'min' => mktime(0, 0, 0, 1, 1, 2014)//minimum timestamp
,'max' => mktime(0, 0, 0, 12, 1, 2014)//maximum timestamp
,'day' => 27//the day must be 27
,'month' => 10//the month must be 10
,'year' => 2014//the year must be 2014
,'weekday' => 1//the day of week must be 1
);
show_validation($date, $rules);
} catch (Exception $ex) {
echo $ex->getMessage();
exit($ex->getCode());
}
|