Subversion Repositories Applications.gtt

Rev

Rev 61 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 jpm 1
<?php
2
/**
3
* Description: shows how to perform validation with PEAR::Calendar
4
*/
5
function getmicrotime(){
6
    list($usec, $sec) = explode(' ', microtime());
7
    return ((float)$usec + (float)$sec);
8
}
9
$start = getmicrotime();
10
 
11
if ( !@include 'Calendar/Calendar.php' ) {
12
    define('CALENDAR_ROOT', '../../');
13
}
14
require_once CALENDAR_ROOT.'Second.php';
15
 
16
if (!isset($_GET['y'])) $_GET['y'] = date('Y');
17
if (!isset($_GET['m'])) $_GET['m'] = date('n');
18
if (!isset($_GET['d'])) $_GET['d'] = date('j');
19
if (!isset($_GET['h'])) $_GET['h'] = date('H');
20
if (!isset($_GET['i'])) $_GET['i'] = date('i');
21
if (!isset($_GET['s'])) $_GET['s'] = date('s');
22
 
23
$Unit = & new Calendar_Second($_GET['y'], $_GET['m'], $_GET['d'], $_GET['h'], $_GET['i'], $_GET['s']);
24
 
25
echo '<p><b>Result:</b> '.$Unit->thisYear().'-'.$Unit->thisMonth().'-'.$Unit->thisDay().
26
        ' '.$Unit->thisHour().':'.$Unit->thisMinute().':'.$Unit->thisSecond();
27
if ($Unit->isValid()) {
28
    echo ' is valid!</p>';
29
} else {
30
    $V= & $Unit->getValidator();
31
    echo ' is invalid:</p>';
32
    while ($error = $V->fetch()) {
33
        echo $error->toString() .'<br />';
34
    }
35
}
36
?>
37
<p>Enter a date / time to validate:</p>
38
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
39
Year:   <input type="text" name="y" value="2039"><br />
40
Month:  <input type="text" name="m" value="13"><br />
41
Day:    <input type="text" name="d" value="32"><br />
42
Hour:   <input type="text" name="h" value="24"><br />
43
Minute: <input type="text" name="i" value="-1"><br />
44
Second: <input type="text" name="s" value="60"><br />
45
<input type="submit" value="Validate">
46
</form>
47
<p><b>Note:</b> Error messages can be controlled with the constants <code>CALENDAR_VALUE_TOOSMALL</code> and <code>CALENDAR_VALUE_TOOLARGE</code> - see <code>Calendar_Validator.php</code></p>
48
 
49
<?php echo '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>'; ?>