1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class Jyxo_Time_Composer
24: {
25: 26: 27: 28: 29:
30: const YEAR_MAX = 2037;
31:
32: 33: 34: 35: 36:
37: const YEAR_MIN = 1902;
38:
39: 40: 41: 42: 43:
44: private $day = 0;
45:
46: 47: 48: 49: 50:
51: private $month = 0;
52:
53: 54: 55: 56: 57:
58: private $year = 0;
59:
60: 61: 62: 63: 64:
65: private $second = 0;
66:
67: 68: 69: 70: 71:
72: private $minute = 0;
73:
74: 75: 76: 77: 78:
79: private $hour = 0;
80:
81: 82: 83: 84: 85: 86:
87: public function getTime()
88: {
89: if ($this->month === 0 || $this->year === 0 || $this->day === 0) {
90: throw new Jyxo_Time_ComposerException('Date not complete.', Jyxo_Time_ComposerException::NOT_COMPLETE);
91: }
92:
93:
94:
95: if (!checkdate($this->month, $this->day, $this->year)) {
96: throw new Jyxo_Time_ComposerException('Day out of range.', Jyxo_Time_ComposerException::INVALID);
97: }
98:
99: $time = mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
100: return new Jyxo_Time_Time($time);
101: }
102:
103: 104: 105: 106: 107: 108: 109:
110: public function setDay($day)
111: {
112: $day = (integer) $day;
113:
114: if ($day < 1 || $day > 31) {
115: throw new Jyxo_Time_ComposerException('Day out of range.', Jyxo_Time_ComposerException::DAY);
116: }
117:
118: $this->day = $day;
119:
120: return $this;
121: }
122:
123: 124: 125: 126: 127: 128: 129:
130: public function setMonth($month)
131: {
132: $month = (integer) $month;
133:
134: if ($month < 1 || $month > 12) {
135: throw new Jyxo_Time_ComposerException('Month out of range.', Jyxo_Time_ComposerException::MONTH);
136: }
137:
138: $this->month = $month;
139:
140: return $this;
141: }
142:
143: 144: 145: 146: 147: 148: 149:
150: public function setYear($year)
151: {
152: $year = (integer) $year;
153:
154: if ($year > self::YEAR_MAX || $year < self::YEAR_MIN) {
155: throw new Jyxo_Time_ComposerException('Year out of range.', Jyxo_Time_ComposerException::YEAR);
156: }
157:
158: $this->year = $year;
159:
160: return $this;
161: }
162:
163: 164: 165: 166: 167: 168: 169:
170: public function setSecond($second)
171: {
172: $second = (integer) $second;
173:
174: if ($second < 0 || $second > 60) {
175: throw new Jyxo_Time_ComposerException('Second out of range.', Jyxo_Time_ComposerException::SECOND);
176: }
177:
178: $this->second = $second;
179:
180: return $this;
181: }
182:
183: 184: 185: 186: 187: 188: 189:
190: public function setMinute($minute)
191: {
192: $minute = (integer) $minute;
193:
194: if ($minute < 0 || $minute > 60) {
195: throw new Jyxo_Time_ComposerException('Minute out of range.', Jyxo_Time_ComposerException::MINUTE);
196: }
197:
198: $this->minute = $minute;
199:
200: return $this;
201: }
202:
203: 204: 205: 206: 207: 208: 209:
210: public function setHour($hour)
211: {
212: $hour = (integer) $hour;
213:
214: if ($hour < 0 || $hour > 24) {
215: throw new Jyxo_Time_ComposerException('Hour out of range.', Jyxo_Time_ComposerException::HOUR);
216: }
217:
218: $this->hour = $hour;
219:
220: return $this;
221: }
222: }
223: