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