source: branches/version-2_4/data/module/Calendar/docs/examples/4.php @ 18734

Revision 18734, 1.8 KB checked in by nanasess, 14 years ago (diff)

Copyright の更新(#601)

Line 
1<?php
2/**
3* Description: shows how to perform validation with PEAR::Calendar
4*/
5function getmicrotime(){
6    list($usec, $sec) = explode(' ', microtime());
7    return ((float)$usec + (float)$sec);
8}
9$start = getmicrotime();
10
11if ( !@include 'Calendar/Calendar.php' ) {
12    define('CALENDAR_ROOT', '../../');
13}
14require_once CALENDAR_ROOT.'Second.php';
15
16if (!isset($_GET['y'])) $_GET['y'] = date('Y');
17if (!isset($_GET['m'])) $_GET['m'] = date('n');
18if (!isset($_GET['d'])) $_GET['d'] = date('j');
19if (!isset($_GET['h'])) $_GET['h'] = date('H');
20if (!isset($_GET['i'])) $_GET['i'] = date('i');
21if (!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
25echo '<p><b>Result:</b> '.$Unit->thisYear().'-'.$Unit->thisMonth().'-'.$Unit->thisDay().
26        ' '.$Unit->thisHour().':'.$Unit->thisMinute().':'.$Unit->thisSecond();
27if ($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">
39Year:   <input type="text" name="y" value="2039"><br />
40Month:  <input type="text" name="m" value="13"><br />
41Day:    <input type="text" name="d" value="32"><br />
42Hour:   <input type="text" name="h" value="24"><br />
43Minute: <input type="text" name="i" value="-1"><br />
44Second: <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>'; ?>
Note: See TracBrowser for help on using the repository browser.