- Timestamp:
- 2013/08/28 13:55:43 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13_0/data/module/Calendar/Calendar.php
r23126 r23143 1 1 <?php 2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 3 2 /* vim: set expandtab tabstop=4 shiftwidth=4: */ 3 // 4 // +----------------------------------------------------------------------+ 5 // | PHP Version 4 | 6 // +----------------------------------------------------------------------+ 7 // | Copyright (c) 1997-2002 The PHP Group | 8 // +----------------------------------------------------------------------+ 9 // | This source file is subject to version 2.02 of the PHP license, | 10 // | that is bundled with this package in the file LICENSE, and is | 11 // | available at through the world-wide-web at | 12 // | http://www.php.net/license/3_0.txt. | 13 // | If you did not receive a copy of the PHP license and are unable to | 14 // | obtain it through the world-wide-web, please send a note to | 15 // | license@php.net so we can mail you a copy immediately. | 16 // +----------------------------------------------------------------------+ 17 // | Authors: Harry Fuecks <hfuecks@phppatterns.com> | 18 // | Lorenzo Alberton <l dot alberton at quipo dot it> | 19 // +----------------------------------------------------------------------+ 20 // 21 // $Id: Calendar.php,v 1.3 2005/10/22 10:07:11 quipo Exp $ 22 // 4 23 /** 5 * Contains the Calendar and Calendar_Engine_Factory classes 6 * 7 * PHP versions 4 and 5 8 * 9 * LICENSE: Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. The name of the author may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED 20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * 30 * @category Date and Time 31 * @package Calendar 32 * @author Harry Fuecks <hfuecks@phppatterns.com> 33 * @author Lorenzo Alberton <l.alberton@quipo.it> 34 * @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton 35 * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) 36 * @version CVS: $Id: Calendar.php 300729 2010-06-24 12:05:53Z quipo $ 37 * @link http://pear.php.net/package/Calendar 24 * @package Calendar 25 * @version $Id: Calendar.php,v 1.3 2005/10/22 10:07:11 quipo Exp $ 38 26 */ 39 27 … … 65 53 * Calendar_Engines. The engine used can be controlled with the constant 66 54 * CALENDAR_ENGINE 67 * 68 * @category Date and Time 69 * @package Calendar 70 * @author Harry Fuecks <hfuecks@phppatterns.com> 71 * @author Lorenzo Alberton <l.alberton@quipo.it> 72 * @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton 73 * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) 74 * @link http://pear.php.net/package/Calendar 75 * @see Calendar_Engine_Interface 76 * @access protected 55 * @see Calendar_Engine_Interface 56 * @package Calendar 57 * @access protected 77 58 */ 78 59 class Calendar_Engine_Factory … … 80 61 /** 81 62 * Returns an instance of the engine 82 *83 63 * @return object instance of a calendar calculation engine 84 64 * @access protected … … 88 68 static $engine = false; 89 69 switch (CALENDAR_ENGINE) { 90 case 'PearDate':91 $class = 'Calendar_Engine_PearDate';92 break;93 case 'UnixTS':94 default:95 $class = 'Calendar_Engine_UnixTS';70 case 'PearDate': 71 $class = 'Calendar_Engine_PearDate'; 72 break; 73 case 'UnixTS': 74 default: 75 $class = 'Calendar_Engine_UnixTS'; 96 76 break; 97 77 } 98 78 if (!$engine) { 99 79 if (!class_exists($class)) { 100 include_once CALENDAR_ROOT.'Engine'.DIRECTORY_SEPARATOR.CALENDAR_ENGINE.'.php';80 require_once CALENDAR_ROOT.'Engine'.DIRECTORY_SEPARATOR.CALENDAR_ENGINE.'.php'; 101 81 } 102 82 $engine = new $class; … … 107 87 108 88 /** 109 * Base class for Calendar API. This class should not be instantiated directly. 110 * 111 * @category Date and Time 112 * @package Calendar 113 * @author Harry Fuecks <hfuecks@phppatterns.com> 114 * @author Lorenzo Alberton <l.alberton@quipo.it> 115 * @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton 116 * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) 117 * @link http://pear.php.net/package/Calendar 89 * Base class for Calendar API. This class should not be instantiated 90 * directly. 118 91 * @abstract 92 * @package Calendar 119 93 */ 120 94 class Calendar … … 140 114 * @var int 141 115 */ 142 116 var $year; 143 117 144 118 /** … … 194 168 /** 195 169 * Constructs the Calendar 196 * 197 * @param int $y year 198 * @param int $m month 199 * @param int $d day 200 * @param int $h hour 201 * @param int $i minute 202 * @param int $s second 203 * 170 * @param int year 171 * @param int month 172 * @param int day 173 * @param int hour 174 * @param int minute 175 * @param int second 204 176 * @access protected 205 177 */ … … 210 182 $cE = & Calendar_Engine_Factory::getEngine(); 211 183 } 212 $this->cE 184 $this->cE = & $cE; 213 185 $this->year = (int)$y; 214 186 $this->month = (int)$m; … … 222 194 * Defines the calendar by a timestamp (Unix or ISO-8601), replacing values 223 195 * passed to the constructor 224 * 225 * @param int|string $ts Unix or ISO-8601 timestamp 226 * 196 * @param int|string Unix or ISO-8601 timestamp 227 197 * @return void 228 198 * @access public … … 241 211 * Returns a timestamp from the current date / time values. Format of 242 212 * timestamp depends on Calendar_Engine implementation being used 243 *244 213 * @return int|string timestamp 245 214 * @access public … … 254 223 /** 255 224 * Defines calendar object as selected (e.g. for today) 256 * 257 * @param boolean $state whether Calendar subclass 258 * 225 * @param boolean state whether Calendar subclass 259 226 * @return void 260 227 * @access public … … 267 234 /** 268 235 * True if the calendar subclass object is selected (e.g. today) 269 *270 236 * @return boolean 271 237 * @access public … … 277 243 278 244 /** 279 * Checks if the current Calendar object is today's date280 *281 * @return boolean282 * @access public283 */284 function isToday()285 {286 return $this->cE->isToday($this->getTimeStamp());287 }288 289 /**290 245 * Adjusts the date (helper method) 291 *292 246 * @return void 293 247 * @access public … … 295 249 function adjust() 296 250 { 297 $stamp 251 $stamp = $this->getTimeStamp(); 298 252 $this->year = $this->cE->stampToYear($stamp); 299 253 $this->month = $this->cE->stampToMonth($stamp); … … 306 260 /** 307 261 * Returns the date as an associative array (helper method) 308 * 309 * @param mixed $stamp timestamp (leave empty for current timestamp) 310 * 262 * @param mixed timestamp (leave empty for current timestamp) 311 263 * @return array 312 264 * @access public … … 329 281 /** 330 282 * Returns the value as an associative array (helper method) 331 * 332 * @param string $returnType type of date object that return value represents 333 * @param string $format ['int' | 'array' | 'timestamp' | 'object'] 334 * @param mixed $stamp timestamp (depending on Calendar engine being used) 335 * @param int $default default value (i.e. give me the answer quick) 336 * 283 * @param string type of date object that return value represents 284 * @param string $format ['int' | 'array' | 'timestamp' | 'object'] 285 * @param mixed timestamp (depending on Calendar engine being used) 286 * @param int integer default value (i.e. give me the answer quick) 337 287 * @return mixed 338 288 * @access private … … 341 291 { 342 292 switch (strtolower($format)) { 343 case 'int':344 return $default;345 case 'array':346 return $this->toArray($stamp);347 break;348 case 'object':349 include_once CALENDAR_ROOT.'Factory.php';350 return Calendar_Factory::createByTimestamp($returnType,$stamp);351 break;352 case 'timestamp':353 default:354 return $stamp;355 break;293 case 'int': 294 return $default; 295 case 'array': 296 return $this->toArray($stamp); 297 break; 298 case 'object': 299 require_once CALENDAR_ROOT.'Factory.php'; 300 return Calendar_Factory::createByTimestamp($returnType,$stamp); 301 break; 302 case 'timestamp': 303 default: 304 return $stamp; 305 break; 356 306 } 357 307 } … … 360 310 * Abstract method for building the children of a calendar object. 361 311 * Implemented by Calendar subclasses 362 * 363 * @param array $sDates array containing Calendar objects to select (optional) 364 * 312 * @param array containing Calendar objects to select (optional) 365 313 * @return boolean 366 314 * @access public … … 369 317 function build($sDates = array()) 370 318 { 371 include_once 'PEAR.php'; 372 PEAR::raiseError('Calendar::build is abstract', null, PEAR_ERROR_TRIGGER, 319 require_once 'PEAR.php'; 320 PEAR::raiseError( 321 'Calendar::build is abstract', null, PEAR_ERROR_TRIGGER, 373 322 E_USER_NOTICE, 'Calendar::build()'); 374 323 return false; … … 377 326 /** 378 327 * Abstract method for selected data objects called from build 379 * 380 * @param array $sDates array of Calendar objects to select 381 * 328 * @param array 382 329 * @return boolean 383 330 * @access public … … 386 333 function setSelection($sDates) 387 334 { 388 include_once 'PEAR.php';335 require_once 'PEAR.php'; 389 336 PEAR::raiseError( 390 337 'Calendar::setSelection is abstract', null, PEAR_ERROR_TRIGGER, … … 398 345 * the collection, returns false and resets the collection for 399 346 * further iteratations. 400 *401 347 * @return mixed either an object subclass of Calendar or false 402 348 * @access public … … 415 361 /** 416 362 * Fetches all child from the current collection of children 417 *418 363 * @return array 419 364 * @access public … … 425 370 426 371 /** 427 * Get the number Calendar subclass objects stored in the internal collection428 * 372 * Get the number Calendar subclass objects stored in the internal 373 * collection. 429 374 * @return int 430 375 * @access public … … 437 382 /** 438 383 * Determine whether this date is valid, with the bounds determined by 439 * the Calendar_Engine. The call is passed on to Calendar_Validator::isValid440 * 384 * the Calendar_Engine. The call is passed on to 385 * Calendar_Validator::isValid 441 386 * @return boolean 442 387 * @access public … … 450 395 /** 451 396 * Returns an instance of Calendar_Validator 452 *453 397 * @return Calendar_Validator 454 398 * @access public … … 457 401 { 458 402 if (!isset($this->validator)) { 459 include_once CALENDAR_ROOT.'Validator.php';460 $this->validator = new Calendar_Validator($this);403 require_once CALENDAR_ROOT.'Validator.php'; 404 $this->validator = & new Calendar_Validator($this); 461 405 } 462 406 return $this->validator; … … 466 410 * Returns a reference to the current Calendar_Engine being used. Useful 467 411 * for Calendar_Table_Helper and Calendar_Validator 468 *469 412 * @return object implementing Calendar_Engine_Inteface 470 413 * @access protected … … 478 421 * Set the CALENDAR_FIRST_DAY_OF_WEEK constant to the $firstDay value 479 422 * if the constant is not set yet. 480 *481 * @param integer $firstDay first day of the week (0=sunday, 1=monday, ...)482 *483 * @return integer484 423 * @throws E_USER_WARNING this method throws a WARNING if the 485 424 * CALENDAR_FIRST_DAY_OF_WEEK constant is already defined and 486 425 * the $firstDay parameter is set to a different value 426 * @param integer $firstDay first day of the week (0=sunday, 1=monday, ...) 427 * @return integer 487 428 * @access protected 488 429 */ … … 510 451 /** 511 452 * Returns the value for the previous year 512 * 513 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 514 * 453 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 515 454 * @return int e.g. 2002 or timestamp 516 455 * @access public … … 524 463 /** 525 464 * Returns the value for this year 526 * 527 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 528 * 465 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 529 466 * @return int e.g. 2003 or timestamp 530 467 * @access public … … 538 475 /** 539 476 * Returns the value for next year 540 * 541 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 542 * 477 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 543 478 * @return int e.g. 2004 or timestamp 544 479 * @access public … … 552 487 /** 553 488 * Returns the value for the previous month 554 * 555 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 556 * 489 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 557 490 * @return int e.g. 4 or Unix timestamp 558 491 * @access public … … 566 499 /** 567 500 * Returns the value for this month 568 * 569 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 570 * 501 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 571 502 * @return int e.g. 5 or timestamp 572 503 * @access public … … 580 511 /** 581 512 * Returns the value for next month 582 * 583 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 584 * 513 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 585 514 * @return int e.g. 6 or timestamp 586 515 * @access public … … 594 523 /** 595 524 * Returns the value for the previous day 596 * 597 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 598 * 525 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 599 526 * @return int e.g. 10 or timestamp 600 527 * @access public … … 609 536 /** 610 537 * Returns the value for this day 611 * 612 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 613 * 538 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 614 539 * @return int e.g. 11 or timestamp 615 540 * @access public … … 624 549 /** 625 550 * Returns the value for the next day 626 * 627 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 628 * 551 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 629 552 * @return int e.g. 12 or timestamp 630 553 * @access public … … 639 562 /** 640 563 * Returns the value for the previous hour 641 * 642 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 643 * 564 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 644 565 * @return int e.g. 13 or timestamp 645 566 * @access public … … 654 575 /** 655 576 * Returns the value for this hour 656 * 657 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 658 * 577 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 659 578 * @return int e.g. 14 or timestamp 660 579 * @access public … … 669 588 /** 670 589 * Returns the value for the next hour 671 * 672 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 673 * 590 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 674 591 * @return int e.g. 14 or timestamp 675 592 * @access public … … 684 601 /** 685 602 * Returns the value for the previous minute 686 * 687 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 688 * 603 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 689 604 * @return int e.g. 23 or timestamp 690 605 * @access public … … 700 615 /** 701 616 * Returns the value for this minute 702 * 703 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 704 * 617 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 705 618 * @return int e.g. 24 or timestamp 706 619 * @access public … … 716 629 /** 717 630 * Returns the value for the next minute 718 * 719 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 720 * 631 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 721 632 * @return int e.g. 25 or timestamp 722 633 * @access public … … 732 643 /** 733 644 * Returns the value for the previous second 734 * 735 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 736 * 645 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 737 646 * @return int e.g. 43 or timestamp 738 647 * @access public … … 748 657 /** 749 658 * Returns the value for this second 750 * 751 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 752 * 659 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 753 660 * @return int e.g. 44 or timestamp 754 661 * @access public … … 764 671 /** 765 672 * Returns the value for the next second 766 * 767 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 768 * 673 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 769 674 * @return int e.g. 45 or timestamp 770 675 * @access public
Note: See TracChangeset
for help on using the changeset viewer.