source: branches/comu-ver2/data/module/Calendar/docs/examples/1.php @ 17073

Revision 17073, 3.1 KB checked in by Yammy, 16 years ago (diff)

カレンダーブロックを追加(PEAR::Calendarクラス使用仕様)

Line 
1<?php
2/**
3* Description: Passes through all main calendar classes, beginning with year
4* and down to seconds, skipping weeks. Useful to test Calendar is (basically)
5* working correctly
6*
7*/
8function getmicrotime(){
9    list($usec, $sec) = explode(" ",microtime());
10    return ((float)$usec + (float)$sec);
11}
12
13if ( !@include 'Calendar/Calendar.php' ) {
14    define('CALENDAR_ROOT','../../');
15}
16
17if (!isset($_GET['y'])) $_GET['y'] = 2003;
18if (!isset($_GET['m'])) $_GET['m'] = 8;
19if (!isset($_GET['d'])) $_GET['d'] = 9;
20if (!isset($_GET['h'])) $_GET['h'] = 12;
21if (!isset($_GET['i'])) $_GET['i'] = 34;
22if (!isset($_GET['s'])) $_GET['s'] = 46;
23
24switch ( @$_GET['view'] ) {
25    default:
26        $_GET['view'] = 'calendar_year';
27    case 'calendar_year':
28        require_once CALENDAR_ROOT.'Year.php';
29        $c = new Calendar_Year($_GET['y']);
30    break;
31    case 'calendar_month':
32        require_once CALENDAR_ROOT.'Month.php';
33        $c = new Calendar_Month($_GET['y'],$_GET['m']);
34    break;
35    case 'calendar_day':
36        require_once CALENDAR_ROOT.'Day.php';
37        $c = new Calendar_Day($_GET['y'],$_GET['m'],$_GET['d']);
38    break;
39    case 'calendar_hour':
40        require_once CALENDAR_ROOT.'Hour.php';
41        $c = new Calendar_Hour($_GET['y'],$_GET['m'],$_GET['d'],$_GET['h']);
42    break;
43    case 'calendar_minute':
44        require_once CALENDAR_ROOT.'Minute.php';
45        $c = new Calendar_Minute($_GET['y'],$_GET['m'],$_GET['d'],$_GET['h'],$_GET['i']);
46    break;
47    case 'calendar_second':
48        require_once CALENDAR_ROOT.'Second.php';
49        $c = new Calendar_Second($_GET['y'],$_GET['m'],$_GET['d'],$_GET['h'],$_GET['i'],$_GET['s']);
50    break;
51}
52
53echo ( 'Viewing: '.@$_GET['view'].'<br />' );
54echo ( 'The time is now: '.date('Y M d H:i:s',$c->getTimestamp()).'<br >' );
55
56$i = 1;
57echo ( '<h1>First Iteration</h1>' );
58echo ( '<p>The first iteration is more "expensive", the calendar data
59        structures having to be built.</p>' );
60$start = getmicrotime();
61$c->build();
62while ( $e = $c->fetch() ) {
63    $class = strtolower(get_class($e));
64    $link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay().
65        "&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond();
66    $method = 'this'.str_replace('calendar_','',$class);
67    echo ( "<a href=\"".$_SERVER['PHP_SELF']."?view=".$class.$link."\">".$e->{$method}()."</a> : " );
68    if ( ($i % 10) == 0 ) {
69        echo ( '<br>' );
70    }
71    $i++;
72}
73echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' );
74
75$i = 1;
76echo ( '<h1>Second Iteration</h1>' );
77echo ( '<p>This second iteration is faster, the data structures
78        being re-used</p>' );
79$start = getmicrotime();
80while ( $e = $c->fetch() ) {
81    $class = strtolower(get_class($e));
82    $link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay().
83        "&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond();
84    $method = 'this'.str_replace('calendar_','',$class);
85    echo ( "<a href=\"".$_SERVER['PHP_SELF']."?view=".$class.$link."\">".$e->{$method}()."</a> : " );
86    if ( ($i % 10) == 0 ) {
87        echo ( '<br>' );
88    }
89    $i++;
90}
91echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' );
92?>
Note: See TracBrowser for help on using the repository browser.