1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
/* vim: set expandtab tabstop=4 shiftwidth=4: */ |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Contains the Calendar_Minute class. |
7
|
|
|
* |
8
|
|
|
* PHP versions 4 and 5 |
9
|
|
|
* |
10
|
|
|
* LICENSE: Redistribution and use in source and binary forms, with or without |
11
|
|
|
* modification, are permitted provided that the following conditions are met: |
12
|
|
|
* 1. Redistributions of source code must retain the above copyright |
13
|
|
|
* notice, this list of conditions and the following disclaimer. |
14
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
15
|
|
|
* notice, this list of conditions and the following disclaimer in the |
16
|
|
|
* documentation and/or other materials provided with the distribution. |
17
|
|
|
* 3. The name of the author may not be used to endorse or promote products |
18
|
|
|
* derived from this software without specific prior written permission. |
19
|
|
|
* |
20
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED |
21
|
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
22
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
23
|
|
|
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY |
24
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
25
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
26
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
27
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
29
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30
|
|
|
* |
31
|
|
|
* @category Date and Time |
32
|
|
|
* |
33
|
|
|
* @author Harry Fuecks <[email protected]> |
34
|
|
|
* @copyright 2003-2007 Harry Fuecks |
35
|
|
|
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) |
36
|
|
|
* |
37
|
|
|
* @link http://pear.php.net/package/Calendar |
38
|
|
|
*/ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Allows Calendar include path to be redefined. |
42
|
|
|
* |
43
|
|
|
* @ignore |
44
|
|
|
*/ |
45
|
|
|
if (!defined('CALENDAR_ROOT')) { |
46
|
|
|
define('CALENDAR_ROOT', 'Calendar/'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Load Calendar base class. |
51
|
|
|
*/ |
52
|
|
|
require_once CALENDAR_ROOT . 'Calendar.php'; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Represents a Minute and builds Seconds |
56
|
|
|
* <code> |
57
|
|
|
* require_once __DIR__ . '/Calendar/Minute.php'; |
58
|
|
|
* $Minute = new Calendar_Minute(2003, 10, 21, 15, 31); // Oct 21st 2003, 3:31pm |
59
|
|
|
* $Minute->build(); // Build Calendar_Second objects |
60
|
|
|
* while ($Second = $Minute->fetch()) { |
61
|
|
|
* echo $Second->thisSecond().'<br>'; |
62
|
|
|
* } |
63
|
|
|
* </code>. |
64
|
|
|
* |
65
|
|
|
* @category Date and Time |
66
|
|
|
* |
67
|
|
|
* @author Harry Fuecks <[email protected]> |
68
|
|
|
* @copyright 2003-2007 Harry Fuecks |
69
|
|
|
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) |
70
|
|
|
* |
71
|
|
|
* @link http://pear.php.net/package/Calendar |
72
|
|
|
*/ |
73
|
|
|
class Calendar_Minute extends Calendar |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
/** |
76
|
|
|
* Constructs Minute. |
77
|
|
|
* |
78
|
|
|
* @param int $y year e.g. 2003 |
79
|
|
|
* @param int $m month e.g. 5 |
80
|
|
|
* @param int $d day e.g. 11 |
81
|
|
|
* @param int $h hour e.g. 13 |
82
|
|
|
* @param int $i minute e.g. 31 |
83
|
|
|
*/ |
84
|
|
|
public function __construct($y, $m, $d, $h, $i) |
85
|
|
|
{ |
86
|
|
|
parent::__construct($y, $m, $d, $h, $i); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Builds the Calendar_Second objects. |
91
|
|
|
* |
92
|
|
|
* @param array $sDates (optional) Calendar_Second objects representing selected dates |
93
|
|
|
* |
94
|
|
|
* @return bool |
95
|
|
|
*/ |
96
|
|
|
public function build($sDates = []) |
97
|
|
|
{ |
98
|
|
|
require_once CALENDAR_ROOT . 'Second.php'; |
99
|
|
|
$sIM = $this->cE->getSecondsInMinute($this->year, $this->month, $this->day, $this->hour, $this->minute); |
100
|
|
|
for ($i = 0; $i < $sIM; ++$i) { |
101
|
|
|
$this->children[$i] = new Calendar_Second($this->year, $this->month, $this->day, $this->hour, $this->minute, $i); |
102
|
|
|
} |
103
|
|
|
if (count($sDates) > 0) { |
104
|
|
|
$this->setSelection($sDates); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return true; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Called from build(). |
112
|
|
|
* |
113
|
|
|
* @param array $sDates Calendar_Second objects representing selected dates |
114
|
|
|
* @return bool|void |
115
|
|
|
*/ |
116
|
|
|
public function setSelection($sDates) |
117
|
|
|
{ |
118
|
|
|
foreach ($sDates as $sDate) { |
119
|
|
|
if ($this->year == $sDate->thisYear() |
120
|
|
|
&& $this->month == $sDate->thisMonth() |
121
|
|
|
&& $this->day == $sDate->thisDay() |
122
|
|
|
&& $this->hour == $sDate->thisHour() |
123
|
|
|
&& $this->minute == $sDate->thisMinute()) { |
124
|
|
|
$key = (int)$sDate->thisSecond(); |
125
|
|
|
if (isset($this->children[$key])) { |
126
|
|
|
$sDate->setSelected(); |
127
|
|
|
$this->children[$key] = $sDate; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.