- Timestamp:
- 2013/08/26 12:42:34 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13-dev/data/module/Calendar/Calendar.php
r20119 r23125 1 1 <?php 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 // | [email protected] so we can mail you a copy immediately. | 16 // +----------------------------------------------------------------------+ 17 // | Authors: Harry Fuecks <[email protected]> | 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 // 2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 3 23 4 /** 24 * @package Calendar 25 * @version $Id: Calendar.php,v 1.3 2005/10/22 10:07:11 quipo Exp $ 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 <[email protected]> 33 * @author Lorenzo Alberton <[email protected]> 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 26 38 */ 27 39 … … 53 65 * Calendar_Engines. The engine used can be controlled with the constant 54 66 * CALENDAR_ENGINE 55 * @see Calendar_Engine_Interface 56 * @package Calendar 57 * @access protected 67 * 68 * @category Date and Time 69 * @package Calendar 70 * @author Harry Fuecks <[email protected]> 71 * @author Lorenzo Alberton <[email protected]> 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 58 77 */ 59 78 class Calendar_Engine_Factory … … 61 80 /** 62 81 * Returns an instance of the engine 82 * 63 83 * @return object instance of a calendar calculation engine 64 84 * @access protected … … 68 88 static $engine = false; 69 89 switch (CALENDAR_ENGINE) { 70 case 'PearDate':71 $class = 'Calendar_Engine_PearDate';72 break;73 case 'UnixTS':74 default:75 $class = 'Calendar_Engine_UnixTS';90 case 'PearDate': 91 $class = 'Calendar_Engine_PearDate'; 92 break; 93 case 'UnixTS': 94 default: 95 $class = 'Calendar_Engine_UnixTS'; 76 96 break; 77 97 } 78 98 if (!$engine) { 79 99 if (!class_exists($class)) { 80 require_once CALENDAR_ROOT.'Engine'.DIRECTORY_SEPARATOR.CALENDAR_ENGINE.'.php';100 include_once CALENDAR_ROOT.'Engine'.DIRECTORY_SEPARATOR.CALENDAR_ENGINE.'.php'; 81 101 } 82 102 $engine = new $class; … … 87 107 88 108 /** 89 * Base class for Calendar API. This class should not be instantiated 90 * directly. 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 <[email protected]> 114 * @author Lorenzo Alberton <[email protected]> 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 91 118 * @abstract 92 * @package Calendar93 119 */ 94 120 class Calendar … … 114 140 * @var int 115 141 */ 116 var $year;142 var $year; 117 143 118 144 /** … … 168 194 /** 169 195 * Constructs the Calendar 170 * @param int year 171 * @param int month 172 * @param int day 173 * @param int hour 174 * @param int minute 175 * @param int second 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 * 176 204 * @access protected 177 205 */ … … 182 210 $cE = & Calendar_Engine_Factory::getEngine(); 183 211 } 184 $this->cE = & $cE;212 $this->cE = & $cE; 185 213 $this->year = (int)$y; 186 214 $this->month = (int)$m; … … 194 222 * Defines the calendar by a timestamp (Unix or ISO-8601), replacing values 195 223 * passed to the constructor 196 * @param int|string Unix or ISO-8601 timestamp 224 * 225 * @param int|string $ts Unix or ISO-8601 timestamp 226 * 197 227 * @return void 198 228 * @access public … … 211 241 * Returns a timestamp from the current date / time values. Format of 212 242 * timestamp depends on Calendar_Engine implementation being used 243 * 213 244 * @return int|string timestamp 214 245 * @access public … … 223 254 /** 224 255 * Defines calendar object as selected (e.g. for today) 225 * @param boolean state whether Calendar subclass 256 * 257 * @param boolean $state whether Calendar subclass 258 * 226 259 * @return void 227 260 * @access public … … 234 267 /** 235 268 * True if the calendar subclass object is selected (e.g. today) 269 * 236 270 * @return boolean 237 271 * @access public … … 243 277 244 278 /** 279 * Checks if the current Calendar object is today's date 280 * 281 * @return boolean 282 * @access public 283 */ 284 function isToday() 285 { 286 return $this->cE->isToday($this->getTimeStamp()); 287 } 288 289 /** 245 290 * Adjusts the date (helper method) 291 * 246 292 * @return void 247 293 * @access public … … 249 295 function adjust() 250 296 { 251 $stamp = $this->getTimeStamp();297 $stamp = $this->getTimeStamp(); 252 298 $this->year = $this->cE->stampToYear($stamp); 253 299 $this->month = $this->cE->stampToMonth($stamp); … … 260 306 /** 261 307 * Returns the date as an associative array (helper method) 262 * @param mixed timestamp (leave empty for current timestamp) 308 * 309 * @param mixed $stamp timestamp (leave empty for current timestamp) 310 * 263 311 * @return array 264 312 * @access public … … 281 329 /** 282 330 * Returns the value as an associative array (helper method) 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) 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 * 287 337 * @return mixed 288 338 * @access private … … 291 341 { 292 342 switch (strtolower($format)) { 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;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; 306 356 } 307 357 } … … 310 360 * Abstract method for building the children of a calendar object. 311 361 * Implemented by Calendar subclasses 312 * @param array containing Calendar objects to select (optional) 362 * 363 * @param array $sDates array containing Calendar objects to select (optional) 364 * 313 365 * @return boolean 314 366 * @access public … … 317 369 function build($sDates = array()) 318 370 { 319 require_once 'PEAR.php'; 320 PEAR::raiseError( 321 'Calendar::build is abstract', null, PEAR_ERROR_TRIGGER, 371 include_once 'PEAR.php'; 372 PEAR::raiseError('Calendar::build is abstract', null, PEAR_ERROR_TRIGGER, 322 373 E_USER_NOTICE, 'Calendar::build()'); 323 374 return false; … … 326 377 /** 327 378 * Abstract method for selected data objects called from build 328 * @param array 379 * 380 * @param array $sDates array of Calendar objects to select 381 * 329 382 * @return boolean 330 383 * @access public … … 333 386 function setSelection($sDates) 334 387 { 335 require_once 'PEAR.php';388 include_once 'PEAR.php'; 336 389 PEAR::raiseError( 337 390 'Calendar::setSelection is abstract', null, PEAR_ERROR_TRIGGER, … … 345 398 * the collection, returns false and resets the collection for 346 399 * further iteratations. 400 * 347 401 * @return mixed either an object subclass of Calendar or false 348 402 * @access public … … 361 415 /** 362 416 * Fetches all child from the current collection of children 417 * 363 418 * @return array 364 419 * @access public … … 370 425 371 426 /** 372 * Get the number Calendar subclass objects stored in the internal 373 * collection.427 * Get the number Calendar subclass objects stored in the internal collection 428 * 374 429 * @return int 375 430 * @access public … … 382 437 /** 383 438 * Determine whether this date is valid, with the bounds determined by 384 * the Calendar_Engine. The call is passed on to 385 * Calendar_Validator::isValid439 * the Calendar_Engine. The call is passed on to Calendar_Validator::isValid 440 * 386 441 * @return boolean 387 442 * @access public … … 395 450 /** 396 451 * Returns an instance of Calendar_Validator 452 * 397 453 * @return Calendar_Validator 398 454 * @access public … … 401 457 { 402 458 if (!isset($this->validator)) { 403 require_once CALENDAR_ROOT.'Validator.php';404 $this->validator = &new Calendar_Validator($this);459 include_once CALENDAR_ROOT.'Validator.php'; 460 $this->validator = new Calendar_Validator($this); 405 461 } 406 462 return $this->validator; … … 410 466 * Returns a reference to the current Calendar_Engine being used. Useful 411 467 * for Calendar_Table_Helper and Calendar_Validator 468 * 412 469 * @return object implementing Calendar_Engine_Inteface 413 470 * @access protected … … 421 478 * Set the CALENDAR_FIRST_DAY_OF_WEEK constant to the $firstDay value 422 479 * if the constant is not set yet. 480 * 481 * @param integer $firstDay first day of the week (0=sunday, 1=monday, ...) 482 * 483 * @return integer 423 484 * @throws E_USER_WARNING this method throws a WARNING if the 424 485 * CALENDAR_FIRST_DAY_OF_WEEK constant is already defined and 425 486 * the $firstDay parameter is set to a different value 426 * @param integer $firstDay first day of the week (0=sunday, 1=monday, ...)427 * @return integer428 487 * @access protected 429 488 */ … … 451 510 /** 452 511 * Returns the value for the previous year 453 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 512 * 513 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 514 * 454 515 * @return int e.g. 2002 or timestamp 455 516 * @access public … … 463 524 /** 464 525 * Returns the value for this year 465 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 526 * 527 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 528 * 466 529 * @return int e.g. 2003 or timestamp 467 530 * @access public … … 475 538 /** 476 539 * Returns the value for next year 477 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 540 * 541 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 542 * 478 543 * @return int e.g. 2004 or timestamp 479 544 * @access public … … 487 552 /** 488 553 * Returns the value for the previous month 489 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 554 * 555 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 556 * 490 557 * @return int e.g. 4 or Unix timestamp 491 558 * @access public … … 499 566 /** 500 567 * Returns the value for this month 501 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 568 * 569 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 570 * 502 571 * @return int e.g. 5 or timestamp 503 572 * @access public … … 511 580 /** 512 581 * Returns the value for next month 513 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 582 * 583 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 584 * 514 585 * @return int e.g. 6 or timestamp 515 586 * @access public … … 523 594 /** 524 595 * Returns the value for the previous day 525 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 596 * 597 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 598 * 526 599 * @return int e.g. 10 or timestamp 527 600 * @access public … … 536 609 /** 537 610 * Returns the value for this day 538 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 611 * 612 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 613 * 539 614 * @return int e.g. 11 or timestamp 540 615 * @access public … … 549 624 /** 550 625 * Returns the value for the next day 551 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 626 * 627 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 628 * 552 629 * @return int e.g. 12 or timestamp 553 630 * @access public … … 562 639 /** 563 640 * Returns the value for the previous hour 564 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 641 * 642 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 643 * 565 644 * @return int e.g. 13 or timestamp 566 645 * @access public … … 575 654 /** 576 655 * Returns the value for this hour 577 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 656 * 657 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 658 * 578 659 * @return int e.g. 14 or timestamp 579 660 * @access public … … 588 669 /** 589 670 * Returns the value for the next hour 590 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 671 * 672 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 673 * 591 674 * @return int e.g. 14 or timestamp 592 675 * @access public … … 601 684 /** 602 685 * Returns the value for the previous minute 603 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 686 * 687 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 688 * 604 689 * @return int e.g. 23 or timestamp 605 690 * @access public … … 615 700 /** 616 701 * Returns the value for this minute 617 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 702 * 703 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 704 * 618 705 * @return int e.g. 24 or timestamp 619 706 * @access public … … 629 716 /** 630 717 * Returns the value for the next minute 631 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 718 * 719 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 720 * 632 721 * @return int e.g. 25 or timestamp 633 722 * @access public … … 643 732 /** 644 733 * Returns the value for the previous second 645 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 734 * 735 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 736 * 646 737 * @return int e.g. 43 or timestamp 647 738 * @access public … … 657 748 /** 658 749 * Returns the value for this second 659 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 750 * 751 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 752 * 660 753 * @return int e.g. 44 or timestamp 661 754 * @access public … … 671 764 /** 672 765 * Returns the value for the next second 673 * @param string return value format ['int' | 'timestamp' | 'object' | 'array'] 766 * 767 * @param string $format return value format ['int'|'timestamp'|'object'|'array'] 768 * 674 769 * @return int e.g. 45 or timestamp 675 770 * @access public
Note: See TracChangeset
for help on using the changeset viewer.
