3 * Description: same as 1.php, but using the PEAR::Date engine
4 * Notice the use of the CALENDAR_ENGINE constant, which
5 * switches the calculation "engine"
6 * Note: make sure PEAR::Date is a stable release!!!
8 function getmicrotime(){
9 list($usec, $sec) = explode(" ",microtime());
10 return ((float)$usec + (float)$sec);
13 // Switch to PEAR::Date engine
14 define('CALENDAR_ENGINE','PearDate');
16 if ( !@include 'Calendar/Calendar.php' ) {
17 define('CALENDAR_ROOT','../../');
20 if (!isset($_GET['y'])) $_GET['y'] = 2003;
21 if (!isset($_GET['m'])) $_GET['m'] = 8;
22 if (!isset($_GET['d'])) $_GET['d'] = 9;
23 if (!isset($_GET['h'])) $_GET['h'] = 12;
24 if (!isset($_GET['i'])) $_GET['i'] = 34;
25 if (!isset($_GET['s'])) $_GET['s'] = 46;
27 switch ( @$_GET['view'] ) {
29 $_GET['view'] = 'calendar_year';
31 require_once CALENDAR_ROOT.'Year.php';
32 $c = new Calendar_Year($_GET['y']);
34 case 'calendar_month':
35 require_once CALENDAR_ROOT.'Month.php';
36 $c = new Calendar_Month($_GET['y'],$_GET['m']);
39 require_once CALENDAR_ROOT.'Day.php';
40 $c = new Calendar_Day($_GET['y'],$_GET['m'],$_GET['d']);
43 require_once CALENDAR_ROOT.'Hour.php';
44 $c = new Calendar_Hour($_GET['y'],$_GET['m'],$_GET['d'],$_GET['h']);
46 case 'calendar_minute':
47 require_once CALENDAR_ROOT.'Minute.php';
48 $c = new Calendar_Minute($_GET['y'],$_GET['m'],$_GET['d'],$_GET['h'],$_GET['i']);
50 case 'calendar_second':
51 require_once CALENDAR_ROOT.'Second.php';
52 $c = new Calendar_Second($_GET['y'],$_GET['m'],$_GET['d'],$_GET['h'],$_GET['i'],$_GET['s']);
56 // Convert timestamp to human readable date
57 $date = new Date($c->getTimestamp());
59 echo ( '<h1>Using PEAR::Date engine</h1>' );
60 echo ( 'Viewing: '.@$_GET['view'].'<br />' );
61 echo ( 'The time is now: '.$date->format('%Y %a %e %T').'<br >' );
64 echo ( '<h1>First Iteration</h1>' );
65 echo ( '<p>The first iteration is more "expensive", the calendar data
66 structures having to be built.</p>' );
67 $start = getmicrotime();
69 while ( $e = $c->fetch() ) {
70 $class = strtolower(get_class($e));
71 $link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay().
72 "&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond();
73 $method = 'this'.str_replace('calendar_','',$class);
74 echo ( "<a href=\"".$_SERVER['PHP_SELF']."?view=".$class.$link."\">".$e->{$method}()."</a> : " );
75 if ( ($i % 10) == 0 ) {
80 echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' );
83 echo ( '<h1>Second Iteration</h1>' );
84 echo ( '<p>This second iteration is faster, the data structures
86 $start = getmicrotime();
87 while ( $e = $c->fetch() ) {
88 $class = strtolower(get_class($e));
89 $link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay().
90 "&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond();
91 $method = 'this'.str_replace('calendar_','',$class);
92 echo ( "<a href=\"".$_SERVER['PHP_SELF']."?view=".$class.$link."\">".$e->{$method}()."</a> : " );
93 if ( ($i % 10) == 0 ) {
98 echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' );