2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00

Updated PEAR Calendar class to resolve PHP Strict notices

This commit is contained in:
Adam Zammit
2013-04-03 22:53:27 +00:00
parent d1a31671d7
commit f2c1bbfb3b
23 changed files with 6586 additions and 5484 deletions

View File

@@ -1,28 +1,40 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
// +----------------------------------------------------------------------+
//
// $Id: Calendar.php,v 1.3 2005/10/22 10:07:11 quipo Exp $
//
/** /**
* @package Calendar * Contains the Calendar and Calendar_Engine_Factory classes
* @version $Id: Calendar.php,v 1.3 2005/10/22 10:07:11 quipo Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Calendar.php 300729 2010-06-24 12:05:53Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
@@ -52,32 +64,40 @@ define('CALENDAR_USE_MONTH_WEEKS', 3);
* <b>Note:</b> this class must be modified to "register" alternative * <b>Note:</b> this class must be modified to "register" alternative
* Calendar_Engines. The engine used can be controlled with the constant * Calendar_Engines. The engine used can be controlled with the constant
* CALENDAR_ENGINE * CALENDAR_ENGINE
* @see Calendar_Engine_Interface *
* @package Calendar * @category Date and Time
* @access protected * @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @see Calendar_Engine_Interface
* @access protected
*/ */
class Calendar_Engine_Factory class Calendar_Engine_Factory
{ {
/** /**
* Returns an instance of the engine * Returns an instance of the engine
*
* @return object instance of a calendar calculation engine * @return object instance of a calendar calculation engine
* @access protected * @access protected
*/ */
function & getEngine() static function & getEngine()
{ {
static $engine = false; static $engine = false;
switch (CALENDAR_ENGINE) { switch (CALENDAR_ENGINE) {
case 'PearDate': case 'PearDate':
$class = 'Calendar_Engine_PearDate'; $class = 'Calendar_Engine_PearDate';
break; break;
case 'UnixTS': case 'UnixTS':
default: default:
$class = 'Calendar_Engine_UnixTS'; $class = 'Calendar_Engine_UnixTS';
break; break;
} }
if (!$engine) { if (!$engine) {
if (!class_exists($class)) { if (!class_exists($class)) {
require_once CALENDAR_ROOT.'Engine'.DIRECTORY_SEPARATOR.CALENDAR_ENGINE.'.php'; include_once CALENDAR_ROOT.'Engine'.DIRECTORY_SEPARATOR.CALENDAR_ENGINE.'.php';
} }
$engine = new $class; $engine = new $class;
} }
@@ -86,10 +106,16 @@ class Calendar_Engine_Factory
} }
/** /**
* Base class for Calendar API. This class should not be instantiated * Base class for Calendar API. This class should not be instantiated directly.
* directly. *
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @abstract * @abstract
* @package Calendar
*/ */
class Calendar class Calendar
{ {
@@ -113,7 +139,7 @@ class Calendar
* @access private * @access private
* @var int * @var int
*/ */
var $year; var $year;
/** /**
* Month for this calendar object e.g. 9 * Month for this calendar object e.g. 9
@@ -167,12 +193,14 @@ class Calendar
/** /**
* Constructs the Calendar * Constructs the Calendar
* @param int year *
* @param int month * @param int $y year
* @param int day * @param int $m month
* @param int hour * @param int $d day
* @param int minute * @param int $h hour
* @param int second * @param int $i minute
* @param int $s second
*
* @access protected * @access protected
*/ */
function Calendar($y = 2000, $m = 1, $d = 1, $h = 0, $i = 0, $s = 0) function Calendar($y = 2000, $m = 1, $d = 1, $h = 0, $i = 0, $s = 0)
@@ -181,7 +209,7 @@ class Calendar
if (!isset($cE)) { if (!isset($cE)) {
$cE = & Calendar_Engine_Factory::getEngine(); $cE = & Calendar_Engine_Factory::getEngine();
} }
$this->cE = & $cE; $this->cE = & $cE;
$this->year = (int)$y; $this->year = (int)$y;
$this->month = (int)$m; $this->month = (int)$m;
$this->day = (int)$d; $this->day = (int)$d;
@@ -193,7 +221,9 @@ class Calendar
/** /**
* Defines the calendar by a timestamp (Unix or ISO-8601), replacing values * Defines the calendar by a timestamp (Unix or ISO-8601), replacing values
* passed to the constructor * passed to the constructor
* @param int|string Unix or ISO-8601 timestamp *
* @param int|string $ts Unix or ISO-8601 timestamp
*
* @return void * @return void
* @access public * @access public
*/ */
@@ -210,6 +240,7 @@ class Calendar
/** /**
* Returns a timestamp from the current date / time values. Format of * Returns a timestamp from the current date / time values. Format of
* timestamp depends on Calendar_Engine implementation being used * timestamp depends on Calendar_Engine implementation being used
*
* @return int|string timestamp * @return int|string timestamp
* @access public * @access public
*/ */
@@ -222,7 +253,9 @@ class Calendar
/** /**
* Defines calendar object as selected (e.g. for today) * Defines calendar object as selected (e.g. for today)
* @param boolean state whether Calendar subclass *
* @param boolean $state whether Calendar subclass
*
* @return void * @return void
* @access public * @access public
*/ */
@@ -233,6 +266,7 @@ class Calendar
/** /**
* True if the calendar subclass object is selected (e.g. today) * True if the calendar subclass object is selected (e.g. today)
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
@@ -241,14 +275,26 @@ class Calendar
return $this->selected; return $this->selected;
} }
/**
* Checks if the current Calendar object is today's date
*
* @return boolean
* @access public
*/
function isToday()
{
return $this->cE->isToday($this->getTimeStamp());
}
/** /**
* Adjusts the date (helper method) * Adjusts the date (helper method)
*
* @return void * @return void
* @access public * @access public
*/ */
function adjust() function adjust()
{ {
$stamp = $this->getTimeStamp(); $stamp = $this->getTimeStamp();
$this->year = $this->cE->stampToYear($stamp); $this->year = $this->cE->stampToYear($stamp);
$this->month = $this->cE->stampToMonth($stamp); $this->month = $this->cE->stampToMonth($stamp);
$this->day = $this->cE->stampToDay($stamp); $this->day = $this->cE->stampToDay($stamp);
@@ -259,7 +305,9 @@ class Calendar
/** /**
* Returns the date as an associative array (helper method) * Returns the date as an associative array (helper method)
* @param mixed timestamp (leave empty for current timestamp) *
* @param mixed $stamp timestamp (leave empty for current timestamp)
*
* @return array * @return array
* @access public * @access public
*/ */
@@ -280,59 +328,64 @@ class Calendar
/** /**
* Returns the value as an associative array (helper method) * Returns the value as an associative array (helper method)
* @param string type of date object that return value represents *
* @param string $format ['int' | 'array' | 'timestamp' | 'object'] * @param string $returnType type of date object that return value represents
* @param mixed timestamp (depending on Calendar engine being used) * @param string $format ['int' | 'array' | 'timestamp' | 'object']
* @param int integer default value (i.e. give me the answer quick) * @param mixed $stamp timestamp (depending on Calendar engine being used)
* @param int $default default value (i.e. give me the answer quick)
*
* @return mixed * @return mixed
* @access private * @access private
*/ */
function returnValue($returnType, $format, $stamp, $default) function returnValue($returnType, $format, $stamp, $default)
{ {
switch (strtolower($format)) { switch (strtolower($format)) {
case 'int': case 'int':
return $default; return $default;
case 'array': case 'array':
return $this->toArray($stamp); return $this->toArray($stamp);
break; break;
case 'object': case 'object':
require_once CALENDAR_ROOT.'Factory.php'; include_once CALENDAR_ROOT.'Factory.php';
return Calendar_Factory::createByTimestamp($returnType,$stamp); return Calendar_Factory::createByTimestamp($returnType, $stamp);
break; break;
case 'timestamp': case 'timestamp':
default: default:
return $stamp; return $stamp;
break; break;
} }
} }
/** /**
* Abstract method for building the children of a calendar object. * Abstract method for building the children of a calendar object.
* Implemented by Calendar subclasses * Implemented by Calendar subclasses
* @param array containing Calendar objects to select (optional) *
* @param array $sDates array containing Calendar objects to select (optional)
*
* @return boolean * @return boolean
* @access public * @access public
* @abstract * @abstract
*/ */
function build($sDates = array()) function build($sDates = array())
{ {
require_once 'PEAR.php'; include_once 'PEAR.php';
PEAR::raiseError( PEAR::raiseError('Calendar::build is abstract', null, PEAR_ERROR_TRIGGER,
'Calendar::build is abstract', null, PEAR_ERROR_TRIGGER,
E_USER_NOTICE, 'Calendar::build()'); E_USER_NOTICE, 'Calendar::build()');
return false; return false;
} }
/** /**
* Abstract method for selected data objects called from build * Abstract method for selected data objects called from build
* @param array *
* @param array $sDates array of Calendar objects to select
*
* @return boolean * @return boolean
* @access public * @access public
* @abstract * @abstract
*/ */
function setSelection($sDates) function setSelection($sDates)
{ {
require_once 'PEAR.php'; include_once 'PEAR.php';
PEAR::raiseError( PEAR::raiseError(
'Calendar::setSelection is abstract', null, PEAR_ERROR_TRIGGER, 'Calendar::setSelection is abstract', null, PEAR_ERROR_TRIGGER,
E_USER_NOTICE, 'Calendar::setSelection()'); E_USER_NOTICE, 'Calendar::setSelection()');
@@ -344,6 +397,7 @@ class Calendar
* (e.g. a minute from an hour object). On reaching the end of * (e.g. a minute from an hour object). On reaching the end of
* the collection, returns false and resets the collection for * the collection, returns false and resets the collection for
* further iteratations. * further iteratations.
*
* @return mixed either an object subclass of Calendar or false * @return mixed either an object subclass of Calendar or false
* @access public * @access public
*/ */
@@ -360,6 +414,7 @@ class Calendar
/** /**
* Fetches all child from the current collection of children * Fetches all child from the current collection of children
*
* @return array * @return array
* @access public * @access public
*/ */
@@ -369,8 +424,8 @@ class Calendar
} }
/** /**
* Get the number Calendar subclass objects stored in the internal * Get the number Calendar subclass objects stored in the internal collection
* collection. *
* @return int * @return int
* @access public * @access public
*/ */
@@ -381,8 +436,8 @@ class Calendar
/** /**
* Determine whether this date is valid, with the bounds determined by * Determine whether this date is valid, with the bounds determined by
* the Calendar_Engine. The call is passed on to * the Calendar_Engine. The call is passed on to Calendar_Validator::isValid
* Calendar_Validator::isValid *
* @return boolean * @return boolean
* @access public * @access public
*/ */
@@ -394,14 +449,15 @@ class Calendar
/** /**
* Returns an instance of Calendar_Validator * Returns an instance of Calendar_Validator
*
* @return Calendar_Validator * @return Calendar_Validator
* @access public * @access public
*/ */
function & getValidator() function & getValidator()
{ {
if (!isset($this->validator)) { if (!isset($this->validator)) {
require_once CALENDAR_ROOT.'Validator.php'; include_once CALENDAR_ROOT.'Validator.php';
$this->validator = & new Calendar_Validator($this); $this->validator = new Calendar_Validator($this);
} }
return $this->validator; return $this->validator;
} }
@@ -409,6 +465,7 @@ class Calendar
/** /**
* Returns a reference to the current Calendar_Engine being used. Useful * Returns a reference to the current Calendar_Engine being used. Useful
* for Calendar_Table_Helper and Calendar_Validator * for Calendar_Table_Helper and Calendar_Validator
*
* @return object implementing Calendar_Engine_Inteface * @return object implementing Calendar_Engine_Inteface
* @access protected * @access protected
*/ */
@@ -420,11 +477,13 @@ class Calendar
/** /**
* Set the CALENDAR_FIRST_DAY_OF_WEEK constant to the $firstDay value * Set the CALENDAR_FIRST_DAY_OF_WEEK constant to the $firstDay value
* if the constant is not set yet. * if the constant is not set yet.
*
* @param integer $firstDay first day of the week (0=sunday, 1=monday, ...)
*
* @return integer
* @throws E_USER_WARNING this method throws a WARNING if the * @throws E_USER_WARNING this method throws a WARNING if the
* CALENDAR_FIRST_DAY_OF_WEEK constant is already defined and * CALENDAR_FIRST_DAY_OF_WEEK constant is already defined and
* the $firstDay parameter is set to a different value * the $firstDay parameter is set to a different value
* @param integer $firstDay first day of the week (0=sunday, 1=monday, ...)
* @return integer
* @access protected * @access protected
*/ */
function defineFirstDayOfWeek($firstDay = null) function defineFirstDayOfWeek($firstDay = null)
@@ -450,7 +509,9 @@ class Calendar
/** /**
* Returns the value for the previous year * Returns the value for the previous year
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 2002 or timestamp * @return int e.g. 2002 or timestamp
* @access public * @access public
*/ */
@@ -462,7 +523,9 @@ class Calendar
/** /**
* Returns the value for this year * Returns the value for this year
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 2003 or timestamp * @return int e.g. 2003 or timestamp
* @access public * @access public
*/ */
@@ -474,7 +537,9 @@ class Calendar
/** /**
* Returns the value for next year * Returns the value for next year
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 2004 or timestamp * @return int e.g. 2004 or timestamp
* @access public * @access public
*/ */
@@ -486,7 +551,9 @@ class Calendar
/** /**
* Returns the value for the previous month * Returns the value for the previous month
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 4 or Unix timestamp * @return int e.g. 4 or Unix timestamp
* @access public * @access public
*/ */
@@ -498,7 +565,9 @@ class Calendar
/** /**
* Returns the value for this month * Returns the value for this month
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 5 or timestamp * @return int e.g. 5 or timestamp
* @access public * @access public
*/ */
@@ -510,7 +579,9 @@ class Calendar
/** /**
* Returns the value for next month * Returns the value for next month
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 6 or timestamp * @return int e.g. 6 or timestamp
* @access public * @access public
*/ */
@@ -522,7 +593,9 @@ class Calendar
/** /**
* Returns the value for the previous day * Returns the value for the previous day
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 10 or timestamp * @return int e.g. 10 or timestamp
* @access public * @access public
*/ */
@@ -535,7 +608,9 @@ class Calendar
/** /**
* Returns the value for this day * Returns the value for this day
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 11 or timestamp * @return int e.g. 11 or timestamp
* @access public * @access public
*/ */
@@ -548,7 +623,9 @@ class Calendar
/** /**
* Returns the value for the next day * Returns the value for the next day
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 12 or timestamp * @return int e.g. 12 or timestamp
* @access public * @access public
*/ */
@@ -561,7 +638,9 @@ class Calendar
/** /**
* Returns the value for the previous hour * Returns the value for the previous hour
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 13 or timestamp * @return int e.g. 13 or timestamp
* @access public * @access public
*/ */
@@ -574,7 +653,9 @@ class Calendar
/** /**
* Returns the value for this hour * Returns the value for this hour
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 14 or timestamp * @return int e.g. 14 or timestamp
* @access public * @access public
*/ */
@@ -587,7 +668,9 @@ class Calendar
/** /**
* Returns the value for the next hour * Returns the value for the next hour
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 14 or timestamp * @return int e.g. 14 or timestamp
* @access public * @access public
*/ */
@@ -600,7 +683,9 @@ class Calendar
/** /**
* Returns the value for the previous minute * Returns the value for the previous minute
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 23 or timestamp * @return int e.g. 23 or timestamp
* @access public * @access public
*/ */
@@ -614,7 +699,9 @@ class Calendar
/** /**
* Returns the value for this minute * Returns the value for this minute
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 24 or timestamp * @return int e.g. 24 or timestamp
* @access public * @access public
*/ */
@@ -628,7 +715,9 @@ class Calendar
/** /**
* Returns the value for the next minute * Returns the value for the next minute
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 25 or timestamp * @return int e.g. 25 or timestamp
* @access public * @access public
*/ */
@@ -642,7 +731,9 @@ class Calendar
/** /**
* Returns the value for the previous second * Returns the value for the previous second
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 43 or timestamp * @return int e.g. 43 or timestamp
* @access public * @access public
*/ */
@@ -656,7 +747,9 @@ class Calendar
/** /**
* Returns the value for this second * Returns the value for this second
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 44 or timestamp * @return int e.g. 44 or timestamp
* @access public * @access public
*/ */
@@ -670,7 +763,9 @@ class Calendar
/** /**
* Returns the value for the next second * Returns the value for the next second
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 45 or timestamp * @return int e.g. 45 or timestamp
* @access public * @access public
*/ */

View File

@@ -1,27 +1,39 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// +----------------------------------------------------------------------+
//
// $Id: Day.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Day class
* @version $Id: Day.php,v 1.1 2004/05/24 22:25:42 quipo Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Day.php 300729 2010-06-24 12:05:53Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
@@ -40,14 +52,20 @@ require_once CALENDAR_ROOT.'Calendar.php';
/** /**
* Represents a Day and builds Hours. * Represents a Day and builds Hours.
* <code> * <code>
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Day.php'; * require_once 'Calendar/Day.php';
* $Day = & new Calendar_Day(2003, 10, 21); // Oct 21st 2003 * $Day = new Calendar_Day(2003, 10, 21); // Oct 21st 2003
* while ($Hour = & $Day->fetch()) { * while ($Hour = & $Day->fetch()) {
* echo $Hour->thisHour().'<br />'; * echo $Hour->thisHour().'<br />';
* } * }
* </code> * </code>
* @package Calendar *
* @access public * @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @access public
*/ */
class Calendar_Day extends Calendar class Calendar_Day extends Calendar
{ {
@@ -60,7 +78,7 @@ class Calendar_Day extends Calendar
/** /**
* Marks the Day at the end of a week * Marks the Day at the end of a week
* @access private * @access private
* @var boolean * @var boolean
*/ */
var $last = false; var $last = false;
@@ -75,29 +93,33 @@ class Calendar_Day extends Calendar
/** /**
* Constructs Calendar_Day * Constructs Calendar_Day
* @param int year e.g. 2003 *
* @param int month e.g. 8 * @param int $y year e.g. 2003
* @param int day e.g. 15 * @param int $m month e.g. 8
* @param int $d day e.g. 15
*
* @access public * @access public
*/ */
function Calendar_Day($y, $m, $d) function Calendar_Day($y, $m, $d)
{ {
Calendar::Calendar($y, $m, $d); parent::Calendar($y, $m, $d);
} }
/** /**
* Builds the Hours of the Day * Builds the Hours of the Day
* @param array (optional) Caledar_Hour objects representing selected dates *
* @param array $sDates (optional) Caledar_Hour objects representing selected dates
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
function build($sDates = array()) function build($sDates = array())
{ {
require_once CALENDAR_ROOT.'Hour.php'; include_once CALENDAR_ROOT.'Hour.php';
$hID = $this->cE->getHoursInDay($this->year, $this->month, $this->day); $hID = $this->cE->getHoursInDay($this->year, $this->month, $this->day);
for ($i=0; $i < $hID; $i++) { for ($i=0; $i < $hID; $i++) {
$this->children[$i]= $this->children[$i] =
new Calendar_Hour($this->year, $this->month, $this->day, $i); new Calendar_Hour($this->year, $this->month, $this->day, $i);
} }
if (count($sDates) > 0) { if (count($sDates) > 0) {
@@ -108,7 +130,9 @@ class Calendar_Day extends Calendar
/** /**
* Called from build() * Called from build()
* @param array *
* @param array $sDates dates to be selected
*
* @return void * @return void
* @access private * @access private
*/ */
@@ -131,11 +155,13 @@ class Calendar_Day extends Calendar
/** /**
* Defines Day object as first in a week * Defines Day object as first in a week
* Only used by Calendar_Month_Weekdays::build() * Only used by Calendar_Month_Weekdays::build()
* @param boolean state *
* @param boolean $state set this day as first in week
*
* @return void * @return void
* @access private * @access private
*/ */
function setFirst ($state = true) function setFirst($state = true)
{ {
$this->first = $state; $this->first = $state;
} }
@@ -143,7 +169,9 @@ class Calendar_Day extends Calendar
/** /**
* Defines Day object as last in a week * Defines Day object as last in a week
* Used only following Calendar_Month_Weekdays::build() * Used only following Calendar_Month_Weekdays::build()
* @param boolean state *
* @param boolean $state set this day as last in week
*
* @return void * @return void
* @access private * @access private
*/ */
@@ -155,16 +183,19 @@ class Calendar_Day extends Calendar
/** /**
* Returns true if Day object is first in a Week * Returns true if Day object is first in a Week
* Only relevant when Day is created by Calendar_Month_Weekdays::build() * Only relevant when Day is created by Calendar_Month_Weekdays::build()
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
function isFirst() { function isFirst()
{
return $this->first; return $this->first;
} }
/** /**
* Returns true if Day object is last in a Week * Returns true if Day object is last in a Week
* Only relevant when Day is created by Calendar_Month_Weekdays::build() * Only relevant when Day is created by Calendar_Month_Weekdays::build()
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
@@ -176,7 +207,9 @@ class Calendar_Day extends Calendar
/** /**
* Defines Day object as empty * Defines Day object as empty
* Only used by Calendar_Month_Weekdays::build() * Only used by Calendar_Month_Weekdays::build()
* @param boolean state *
* @param boolean $state set this day as empty
*
* @return void * @return void
* @access private * @access private
*/ */
@@ -186,6 +219,8 @@ class Calendar_Day extends Calendar
} }
/** /**
* Check if this day is empty
*
* @return boolean * @return boolean
* @access public * @access public
*/ */

View File

@@ -1,28 +1,41 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// +----------------------------------------------------------------------+
//
// $Id: Decorator.php,v 1.3 2005/10/22 10:29:46 quipo Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Decorator class
* @version $Id: Decorator.php,v 1.3 2005/10/22 10:29:46 quipo Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Decorator.php 300729 2010-06-24 12:05:53Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
* Decorates any calendar class. * Decorates any calendar class.
* Create a subclass of this class for your own "decoration". * Create a subclass of this class for your own "decoration".
@@ -36,12 +49,18 @@
.* return date('D', $day); .* return date('D', $day);
* } * }
* } * }
* $Day = & new Calendar_Day(2003, 10, 25); * $Day = new Calendar_Day(2003, 10, 25);
* $DayDecorator = & new DayDecorator($Day); * $DayDecorator = new DayDecorator($Day);
* echo $DayDecorator->thisDay(); // Outputs "Sat" * echo $DayDecorator->thisDay(); // Outputs "Sat"
* </code> * </code>
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @abstract * @abstract
* @package Calendar
*/ */
class Calendar_Decorator class Calendar_Decorator
{ {
@@ -54,9 +73,10 @@ class Calendar_Decorator
/** /**
* Constructs the Calendar_Decorator * Constructs the Calendar_Decorator
* @param object subclass to Calendar to decorate *
* @param object &$calendar subclass to Calendar to decorate
*/ */
function Calendar_Decorator(& $calendar) function Calendar_Decorator(&$calendar)
{ {
$this->calendar = & $calendar; $this->calendar = & $calendar;
} }
@@ -64,7 +84,9 @@ class Calendar_Decorator
/** /**
* Defines the calendar by a Unix timestamp, replacing values * Defines the calendar by a Unix timestamp, replacing values
* passed to the constructor * passed to the constructor
* @param int Unix timestamp *
* @param int $ts Unix timestamp
*
* @return void * @return void
* @access public * @access public
*/ */
@@ -76,7 +98,8 @@ class Calendar_Decorator
/** /**
* Returns a timestamp from the current date / time values. Format of * Returns a timestamp from the current date / time values. Format of
* timestamp depends on Calendar_Engine implementation being used * timestamp depends on Calendar_Engine implementation being used
* @return int timestamp *
* @return int $ts timestamp
* @access public * @access public
*/ */
function getTimestamp() function getTimestamp()
@@ -86,7 +109,9 @@ class Calendar_Decorator
/** /**
* Defines calendar object as selected (e.g. for today) * Defines calendar object as selected (e.g. for today)
* @param boolean state whether Calendar subclass *
* @param boolean $state whether Calendar subclass must be selected
*
* @return void * @return void
* @access public * @access public
*/ */
@@ -97,6 +122,7 @@ class Calendar_Decorator
/** /**
* True if the calendar subclass object is selected (e.g. today) * True if the calendar subclass object is selected (e.g. today)
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
@@ -107,6 +133,7 @@ class Calendar_Decorator
/** /**
* Adjusts the date (helper method) * Adjusts the date (helper method)
*
* @return void * @return void
* @access public * @access public
*/ */
@@ -117,21 +144,25 @@ class Calendar_Decorator
/** /**
* Returns the date as an associative array (helper method) * Returns the date as an associative array (helper method)
* @param mixed timestamp (leave empty for current timestamp) *
* @param mixed $stamp timestamp (leave empty for current timestamp)
*
* @return array * @return array
* @access public * @access public
*/ */
function toArray($stamp=null) function toArray($stamp = null)
{ {
return $this->calendar->toArray($stamp); return $this->calendar->toArray($stamp);
} }
/** /**
* Returns the value as an associative array (helper method) * Returns the value as an associative array (helper method)
* @param string type of date object that return value represents *
* @param string $format ['int' | 'array' | 'timestamp' | 'object'] * @param string $returnType type of date object that return value represents
* @param mixed timestamp (depending on Calendar engine being used) * @param string $format ['int'|'timestamp'|'object'|'array']
* @param int integer default value (i.e. give me the answer quick) * @param mixed $stamp timestamp (depending on Calendar engine being used)
* @param integer $default default value (i.e. give me the answer quick)
*
* @return mixed * @return mixed
* @access private * @access private
*/ */
@@ -143,13 +174,15 @@ class Calendar_Decorator
/** /**
* Defines Day object as first in a week * Defines Day object as first in a week
* Only used by Calendar_Month_Weekdays::build() * Only used by Calendar_Month_Weekdays::build()
* @param boolean state *
* @param boolean $state whether it's first or not
*
* @return void * @return void
* @access private * @access private
*/ */
function setFirst ($state = true) function setFirst($state = true)
{ {
if ( method_exists($this->calendar,'setFirst') ) { if (method_exists($this->calendar, 'setFirst')) {
$this->calendar->setFirst($state); $this->calendar->setFirst($state);
} }
} }
@@ -157,13 +190,15 @@ class Calendar_Decorator
/** /**
* Defines Day object as last in a week * Defines Day object as last in a week
* Used only following Calendar_Month_Weekdays::build() * Used only following Calendar_Month_Weekdays::build()
* @param boolean state *
* @param boolean $state whether it's last or not
*
* @return void * @return void
* @access private * @access private
*/ */
function setLast($state = true) function setLast($state = true)
{ {
if ( method_exists($this->calendar,'setLast') ) { if (method_exists($this->calendar, 'setLast')) {
$this->calendar->setLast($state); $this->calendar->setLast($state);
} }
} }
@@ -171,11 +206,13 @@ class Calendar_Decorator
/** /**
* Returns true if Day object is first in a Week * Returns true if Day object is first in a Week
* Only relevant when Day is created by Calendar_Month_Weekdays::build() * Only relevant when Day is created by Calendar_Month_Weekdays::build()
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
function isFirst() { function isFirst()
if ( method_exists($this->calendar,'isFirst') ) { {
if (method_exists($this->calendar, 'isFirst')) {
return $this->calendar->isFirst(); return $this->calendar->isFirst();
} }
} }
@@ -183,12 +220,13 @@ class Calendar_Decorator
/** /**
* Returns true if Day object is last in a Week * Returns true if Day object is last in a Week
* Only relevant when Day is created by Calendar_Month_Weekdays::build() * Only relevant when Day is created by Calendar_Month_Weekdays::build()
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
function isLast() function isLast()
{ {
if ( method_exists($this->calendar,'isLast') ) { if (method_exists($this->calendar, 'isLast')) {
return $this->calendar->isLast(); return $this->calendar->isLast();
} }
} }
@@ -196,31 +234,37 @@ class Calendar_Decorator
/** /**
* Defines Day object as empty * Defines Day object as empty
* Only used by Calendar_Month_Weekdays::build() * Only used by Calendar_Month_Weekdays::build()
* @param boolean state *
* @param boolean $state whether it's empty or not
*
* @return void * @return void
* @access private * @access private
*/ */
function setEmpty ($state = true) function setEmpty ($state = true)
{ {
if ( method_exists($this->calendar,'setEmpty') ) { if (method_exists($this->calendar, 'setEmpty')) {
$this->calendar->setEmpty($state); $this->calendar->setEmpty($state);
} }
} }
/** /**
* Check if the current object is empty
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
function isEmpty() function isEmpty()
{ {
if ( method_exists($this->calendar,'isEmpty') ) { if (method_exists($this->calendar, 'isEmpty')) {
return $this->calendar->isEmpty(); return $this->calendar->isEmpty();
} }
} }
/** /**
* Build the children * Build the children
* @param array containing Calendar objects to select (optional) *
* @param array $sDates array containing Calendar objects to select (optional)
*
* @return boolean * @return boolean
* @access public * @access public
* @abstract * @abstract
@@ -235,6 +279,7 @@ class Calendar_Decorator
* (e.g. a minute from an hour object). On reaching the end of * (e.g. a minute from an hour object). On reaching the end of
* the collection, returns false and resets the collection for * the collection, returns false and resets the collection for
* further iteratations. * further iteratations.
*
* @return mixed either an object subclass of Calendar or false * @return mixed either an object subclass of Calendar or false
* @access public * @access public
*/ */
@@ -245,6 +290,7 @@ class Calendar_Decorator
/** /**
* Fetches all child from the current collection of children * Fetches all child from the current collection of children
*
* @return array * @return array
* @access public * @access public
*/ */
@@ -254,8 +300,8 @@ class Calendar_Decorator
} }
/** /**
* Get the number Calendar subclass objects stored in the internal * Get the number Calendar subclass objects stored in the internal collection
* collection. *
* @return int * @return int
* @access public * @access public
*/ */
@@ -266,8 +312,8 @@ class Calendar_Decorator
/** /**
* Determine whether this date is valid, with the bounds determined by * Determine whether this date is valid, with the bounds determined by
* the Calendar_Engine. The call is passed on to * the Calendar_Engine. The call is passed on to Calendar_Validator::isValid
* Calendar_Validator::isValid *
* @return boolean * @return boolean
* @access public * @access public
*/ */
@@ -278,6 +324,7 @@ class Calendar_Decorator
/** /**
* Returns an instance of Calendar_Validator * Returns an instance of Calendar_Validator
*
* @return Calendar_Validator * @return Calendar_Validator
* @access public * @access public
*/ */
@@ -290,17 +337,21 @@ class Calendar_Decorator
/** /**
* Returns a reference to the current Calendar_Engine being used. Useful * Returns a reference to the current Calendar_Engine being used. Useful
* for Calendar_Table_Helper and Calendar_Validator * for Calendar_Table_Helper and Calendar_Validator
*
* @return object implementing Calendar_Engine_Inteface * @return object implementing Calendar_Engine_Inteface
* @access private * @access private
*/ */
function & getEngine() function & getEngine()
{ {
return $this->calendar->getEngine(); $engine = $this->calendar->getEngine();
return $engine;
} }
/** /**
* Returns the value for the previous year * Returns the value for the previous year
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 2002 or timestamp * @return int e.g. 2002 or timestamp
* @access public * @access public
*/ */
@@ -311,7 +362,9 @@ class Calendar_Decorator
/** /**
* Returns the value for this year * Returns the value for this year
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 2003 or timestamp * @return int e.g. 2003 or timestamp
* @access public * @access public
*/ */
@@ -322,7 +375,9 @@ class Calendar_Decorator
/** /**
* Returns the value for next year * Returns the value for next year
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 2004 or timestamp * @return int e.g. 2004 or timestamp
* @access public * @access public
*/ */
@@ -333,7 +388,9 @@ class Calendar_Decorator
/** /**
* Returns the value for the previous month * Returns the value for the previous month
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 4 or Unix timestamp * @return int e.g. 4 or Unix timestamp
* @access public * @access public
*/ */
@@ -344,7 +401,9 @@ class Calendar_Decorator
/** /**
* Returns the value for this month * Returns the value for this month
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 5 or timestamp * @return int e.g. 5 or timestamp
* @access public * @access public
*/ */
@@ -355,7 +414,9 @@ class Calendar_Decorator
/** /**
* Returns the value for next month * Returns the value for next month
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 6 or timestamp * @return int e.g. 6 or timestamp
* @access public * @access public
*/ */
@@ -366,16 +427,18 @@ class Calendar_Decorator
/** /**
* Returns the value for the previous week * Returns the value for the previous week
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 4 or Unix timestamp * @return int e.g. 4 or Unix timestamp
* @access public * @access public
*/ */
function prevWeek($format = 'n_in_month') function prevWeek($format = 'n_in_month')
{ {
if ( method_exists($this->calendar,'prevWeek') ) { if ( method_exists($this->calendar, 'prevWeek')) {
return $this->calendar->prevWeek($format); return $this->calendar->prevWeek($format);
} else { } else {
require_once 'PEAR.php'; include_once 'PEAR.php';
PEAR::raiseError( PEAR::raiseError(
'Cannot call prevWeek on Calendar object of type: '. 'Cannot call prevWeek on Calendar object of type: '.
get_class($this->calendar), 133, PEAR_ERROR_TRIGGER, get_class($this->calendar), 133, PEAR_ERROR_TRIGGER,
@@ -386,16 +449,18 @@ class Calendar_Decorator
/** /**
* Returns the value for this week * Returns the value for this week
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 5 or timestamp * @return int e.g. 5 or timestamp
* @access public * @access public
*/ */
function thisWeek($format = 'n_in_month') function thisWeek($format = 'n_in_month')
{ {
if ( method_exists($this->calendar,'thisWeek') ) { if ( method_exists($this->calendar, 'thisWeek')) {
return $this->calendar->thisWeek($format); return $this->calendar->thisWeek($format);
} else { } else {
require_once 'PEAR.php'; include_once 'PEAR.php';
PEAR::raiseError( PEAR::raiseError(
'Cannot call thisWeek on Calendar object of type: '. 'Cannot call thisWeek on Calendar object of type: '.
get_class($this->calendar), 133, PEAR_ERROR_TRIGGER, get_class($this->calendar), 133, PEAR_ERROR_TRIGGER,
@@ -406,16 +471,18 @@ class Calendar_Decorator
/** /**
* Returns the value for next week * Returns the value for next week
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 6 or timestamp * @return int e.g. 6 or timestamp
* @access public * @access public
*/ */
function nextWeek($format = 'n_in_month') function nextWeek($format = 'n_in_month')
{ {
if ( method_exists($this->calendar,'nextWeek') ) { if ( method_exists($this->calendar, 'nextWeek')) {
return $this->calendar->nextWeek($format); return $this->calendar->nextWeek($format);
} else { } else {
require_once 'PEAR.php'; include_once 'PEAR.php';
PEAR::raiseError( PEAR::raiseError(
'Cannot call thisWeek on Calendar object of type: '. 'Cannot call thisWeek on Calendar object of type: '.
get_class($this->calendar), 133, PEAR_ERROR_TRIGGER, get_class($this->calendar), 133, PEAR_ERROR_TRIGGER,
@@ -426,17 +493,22 @@ class Calendar_Decorator
/** /**
* Returns the value for the previous day * Returns the value for the previous day
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 10 or timestamp * @return int e.g. 10 or timestamp
* @access public * @access public
*/ */
function prevDay($format = 'int') { function prevDay($format = 'int')
{
return $this->calendar->prevDay($format); return $this->calendar->prevDay($format);
} }
/** /**
* Returns the value for this day * Returns the value for this day
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 11 or timestamp * @return int e.g. 11 or timestamp
* @access public * @access public
*/ */
@@ -447,7 +519,9 @@ class Calendar_Decorator
/** /**
* Returns the value for the next day * Returns the value for the next day
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 12 or timestamp * @return int e.g. 12 or timestamp
* @access public * @access public
*/ */
@@ -458,7 +532,9 @@ class Calendar_Decorator
/** /**
* Returns the value for the previous hour * Returns the value for the previous hour
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 13 or timestamp * @return int e.g. 13 or timestamp
* @access public * @access public
*/ */
@@ -469,7 +545,9 @@ class Calendar_Decorator
/** /**
* Returns the value for this hour * Returns the value for this hour
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 14 or timestamp * @return int e.g. 14 or timestamp
* @access public * @access public
*/ */
@@ -480,7 +558,9 @@ class Calendar_Decorator
/** /**
* Returns the value for the next hour * Returns the value for the next hour
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 14 or timestamp * @return int e.g. 14 or timestamp
* @access public * @access public
*/ */
@@ -491,7 +571,9 @@ class Calendar_Decorator
/** /**
* Returns the value for the previous minute * Returns the value for the previous minute
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 23 or timestamp * @return int e.g. 23 or timestamp
* @access public * @access public
*/ */
@@ -502,7 +584,9 @@ class Calendar_Decorator
/** /**
* Returns the value for this minute * Returns the value for this minute
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 24 or timestamp * @return int e.g. 24 or timestamp
* @access public * @access public
*/ */
@@ -513,18 +597,22 @@ class Calendar_Decorator
/** /**
* Returns the value for the next minute * Returns the value for the next minute
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 25 or timestamp * @return int e.g. 25 or timestamp
* @access public * @access public
*/ */
function nextMinute($format = 'int') function nextMinute($format = 'int')
{ {
return $this->calendar->nextMinute($format); return $this->calendar->nextMinute($format);
} }
/** /**
* Returns the value for the previous second * Returns the value for the previous second
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 43 or timestamp * @return int e.g. 43 or timestamp
* @access public * @access public
*/ */
@@ -535,7 +623,9 @@ class Calendar_Decorator
/** /**
* Returns the value for this second * Returns the value for this second
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 44 or timestamp * @return int e.g. 44 or timestamp
* @access public * @access public
*/ */
@@ -546,7 +636,9 @@ class Calendar_Decorator
/** /**
* Returns the value for the next second * Returns the value for the next second
* @param string return value format ['int' | 'timestamp' | 'object' | 'array'] *
* @param string $format return value format ['int'|'timestamp'|'object'|'array']
*
* @return int e.g. 45 or timestamp * @return int e.g. 45 or timestamp
* @access public * @access public
*/ */

View File

@@ -1,28 +1,40 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
// +----------------------------------------------------------------------+
//
// $Id: Textual.php,v 1.3 2004/08/16 13:02:44 hfuecks Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Decorator_Wrapper class
* @version $Id: Textual.php,v 1.3 2004/08/16 13:02:44 hfuecks Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Textual.php 246907 2007-11-24 11:04:24Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
@@ -48,14 +60,23 @@ require_once CALENDAR_ROOT.'Util'.DIRECTORY_SEPARATOR.'Textual.php';
* days of the week. * days of the week.
* <b>Note:</b> for performance you should prefer Calendar_Util_Textual unless you * <b>Note:</b> for performance you should prefer Calendar_Util_Textual unless you
* have a specific need to use a decorator * have a specific need to use a decorator
* @package Calendar *
* @access public * @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @access public
*/ */
class Calendar_Decorator_Textual extends Calendar_Decorator class Calendar_Decorator_Textual extends Calendar_Decorator
{ {
/** /**
* Constructs Calendar_Decorator_Textual * Constructs Calendar_Decorator_Textual
* @param object subclass of Calendar *
* @param object &$Calendar subclass of Calendar
*
* @access public * @access public
*/ */
function Calendar_Decorator_Textual(&$Calendar) function Calendar_Decorator_Textual(&$Calendar)
@@ -65,105 +86,123 @@ class Calendar_Decorator_Textual extends Calendar_Decorator
/** /**
* Returns an array of 12 month names (first index = 1) * Returns an array of 12 month names (first index = 1)
* @param string (optional) format of returned months (one,two,short or long) *
* @param string $format (optional) format of returned months (one|two|short|long)
*
* @return array * @return array
* @access public * @access public
* @static * @static
*/ */
function monthNames($format='long') function monthNames($format = 'long')
{ {
return Calendar_Util_Textual::monthNames($format); return Calendar_Util_Textual::monthNames($format);
} }
/** /**
* Returns an array of 7 week day names (first index = 0) * Returns an array of 7 week day names (first index = 0)
* @param string (optional) format of returned days (one,two,short or long) *
* @param string $format (optional) format of returned days (one|two|short|long)
*
* @return array * @return array
* @access public * @access public
* @static * @static
*/ */
function weekdayNames($format='long') function weekdayNames($format = 'long')
{ {
return Calendar_Util_Textual::weekdayNames($format); return Calendar_Util_Textual::weekdayNames($format);
} }
/** /**
* Returns textual representation of the previous month of the decorated calendar object * Returns textual representation of the previous month of the decorated calendar object
* @param string (optional) format of returned months (one,two,short or long) *
* @param string $format (optional) format of returned months (one|two|short|long)
*
* @return string * @return string
* @access public * @access public
*/ */
function prevMonthName($format='long') function prevMonthName($format = 'long')
{ {
return Calendar_Util_Textual::prevMonthName($this->calendar,$format); return Calendar_Util_Textual::prevMonthName($this->calendar, $format);
} }
/** /**
* Returns textual representation of the month of the decorated calendar object * Returns textual representation of the month of the decorated calendar object
* @param string (optional) format of returned months (one,two,short or long) *
* @param string $format (optional) format of returned months (one|two|short|long)
*
* @return string * @return string
* @access public * @access public
*/ */
function thisMonthName($format='long') function thisMonthName($format = 'long')
{ {
return Calendar_Util_Textual::thisMonthName($this->calendar,$format); return Calendar_Util_Textual::thisMonthName($this->calendar, $format);
} }
/** /**
* Returns textual representation of the next month of the decorated calendar object * Returns textual representation of the next month of the decorated calendar object
* @param string (optional) format of returned months (one,two,short or long) *
* @param string $format (optional) format of returned months (one|two|short|long)
*
* @return string * @return string
* @access public * @access public
*/ */
function nextMonthName($format='long') function nextMonthName($format = 'long')
{ {
return Calendar_Util_Textual::nextMonthName($this->calendar,$format); return Calendar_Util_Textual::nextMonthName($this->calendar, $format);
} }
/** /**
* Returns textual representation of the previous day of week of the decorated calendar object * Returns textual representation of the previous day of week of the decorated calendar object
* @param string (optional) format of returned months (one,two,short or long) *
* @param string $format (optional) format of returned months (one|two|short|long)
*
* @return string * @return string
* @access public * @access public
*/ */
function prevDayName($format='long') function prevDayName($format = 'long')
{ {
return Calendar_Util_Textual::prevDayName($this->calendar,$format); return Calendar_Util_Textual::prevDayName($this->calendar, $format);
} }
/** /**
* Returns textual representation of the day of week of the decorated calendar object * Returns textual representation of the day of week of the decorated calendar object
* @param string (optional) format of returned months (one,two,short or long) *
* @param string $format (optional) format of returned months (one|two|short|long)
*
* @return string * @return string
* @access public * @access public
*/ */
function thisDayName($format='long') function thisDayName($format = 'long')
{ {
return Calendar_Util_Textual::thisDayName($this->calendar,$format); return Calendar_Util_Textual::thisDayName($this->calendar, $format);
} }
/** /**
* Returns textual representation of the next day of week of the decorated calendar object * Returns textual representation of the next day of week of the decorated calendar object
* @param string (optional) format of returned months (one,two,short or long) *
* @param string $format (optional) format of returned months (one|two|short|long)
*
* @return string * @return string
* @access public * @access public
*/ */
function nextDayName($format='long') function nextDayName($format = 'long')
{ {
return Calendar_Util_Textual::nextDayName($this->calendar,$format); return Calendar_Util_Textual::nextDayName($this->calendar, $format);
} }
/** /**
* Returns the days of the week using the order defined in the decorated * Returns the days of the week using the order defined in the decorated
* calendar object. Only useful for Calendar_Month_Weekdays, Calendar_Month_Weeks * calendar object. Only useful for Calendar_Month_Weekdays, Calendar_Month_Weeks
* and Calendar_Week. Otherwise the returned array will begin on Sunday * and Calendar_Week. Otherwise the returned array will begin on Sunday
* @param string (optional) format of returned months (one,two,short or long) *
* @param string $format (optional) format of returned months (one|two|short|long)
*
* @return array ordered array of week day names * @return array ordered array of week day names
* @access public * @access public
*/ */
function orderedWeekdays($format='long') function orderedWeekdays($format = 'long')
{ {
return Calendar_Util_Textual::orderedWeekdays($this->calendar,$format); return Calendar_Util_Textual::orderedWeekdays($this->calendar, $format);
} }
} }
?> ?>

View File

@@ -1,28 +1,40 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
// +----------------------------------------------------------------------+
//
// $Id: Uri.php,v 1.3 2004/08/16 09:04:20 hfuecks Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Decorator_Uri class
* @version $Id: Uri.php,v 1.3 2004/08/16 09:04:20 hfuecks Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Uri.php 300729 2010-06-24 12:05:53Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
@@ -49,26 +61,35 @@ require_once CALENDAR_ROOT.'Util'.DIRECTORY_SEPARATOR.'Uri.php';
* have a specific need to use a decorator * have a specific need to use a decorator
* <code> * <code>
* $Day = new Calendar_Day(2003, 10, 23); * $Day = new Calendar_Day(2003, 10, 23);
* $Uri = & new Calendar_Decorator_Uri($Day); * $Uri = new Calendar_Decorator_Uri($Day);
* $Uri->setFragments('year', 'month', 'day'); * $Uri->setFragments('year', 'month', 'day');
* echo $Uri->getPrev(); // Displays year=2003&month=10&day=22 * echo $Uri->getPrev(); // Displays year=2003&month=10&day=22
* </code> * </code>
* @see Calendar_Util_Uri *
* @package Calendar * @category Date and Time
* @access public * @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @see Calendar_Util_Uri
* @access public
*/ */
class Calendar_Decorator_Uri extends Calendar_Decorator class Calendar_Decorator_Uri extends Calendar_Decorator
{ {
/** /**
* @var Calendar_Util_Uri * @var Calendar_Util_Uri
* @access private * @access private
*/ */
var $Uri; var $Uri;
/** /**
* Constructs Calendar_Decorator_Uri * Constructs Calendar_Decorator_Uri
* @param object subclass of Calendar *
* @param object &$Calendar subclass of Calendar
*
* @access public * @access public
*/ */
function Calendar_Decorator_Uri(&$Calendar) function Calendar_Decorator_Uri(&$Calendar)
@@ -78,22 +99,27 @@ class Calendar_Decorator_Uri extends Calendar_Decorator
/** /**
* Sets the URI fragment names * Sets the URI fragment names
* @param string URI fragment for year *
* @param string (optional) URI fragment for month * @param string $y URI fragment for year
* @param string (optional) URI fragment for day * @param string $m (optional) URI fragment for month
* @param string (optional) URI fragment for hour * @param string $d (optional) URI fragment for day
* @param string (optional) URI fragment for minute * @param string $h (optional) URI fragment for hour
* @param string (optional) URI fragment for second * @param string $i (optional) URI fragment for minute
* @param string $s (optional) URI fragment for second
*
* @return void * @return void
* @access public * @access public
*/ */
function setFragments($y, $m=null, $d=null, $h=null, $i=null, $s=null) { function setFragments($y, $m = null, $d = null, $h = null, $i = null, $s = null)
$this->Uri = & new Calendar_Util_Uri($y, $m, $d, $h, $i, $s); {
$this->Uri = new Calendar_Util_Uri($y, $m, $d, $h, $i, $s);
} }
/** /**
* Sets the separator string between fragments * Sets the separator string between fragments
* @param string separator e.g. / *
* @param string $separator url fragment separator e.g. /
*
* @return void * @return void
* @access public * @access public
*/ */
@@ -103,20 +129,23 @@ class Calendar_Decorator_Uri extends Calendar_Decorator
} }
/** /**
* Puts Uri decorator into "scalar mode" - URI variable names are not * Puts Uri decorator into "scalar mode" - URI variable names are not returned
* returned *
* @param boolean (optional) * @param boolean $state (optional)
*
* @return void * @return void
* @access public * @access public
*/ */
function setScalar($state=true) function setScalar($state = true)
{ {
$this->Uri->scalar = $state; $this->Uri->scalar = $state;
} }
/** /**
* Gets the URI string for the previous calendar unit * Gets the URI string for the previous calendar unit
* @param string calendar unit to fetch uri for (year,month,week or day etc) *
* @param string $method calendar unit to fetch uri for (year, month, week or day etc)
*
* @return string * @return string
* @access public * @access public
*/ */
@@ -127,7 +156,9 @@ class Calendar_Decorator_Uri extends Calendar_Decorator
/** /**
* Gets the URI string for the current calendar unit * Gets the URI string for the current calendar unit
* @param string calendar unit to fetch uri for (year,month,week or day etc) *
* @param string $method calendar unit to fetch uri for (year,month,week or day etc)
*
* @return string * @return string
* @access public * @access public
*/ */
@@ -138,7 +169,9 @@ class Calendar_Decorator_Uri extends Calendar_Decorator
/** /**
* Gets the URI string for the next calendar unit * Gets the URI string for the next calendar unit
* @param string calendar unit to fetch uri for (year,month,week or day etc) *
* @param string $method calendar unit to fetch uri for (year,month,week or day etc)
*
* @return string * @return string
* @access public * @access public
*/ */
@@ -146,6 +179,5 @@ class Calendar_Decorator_Uri extends Calendar_Decorator
{ {
return $this->Uri->next($this, $method); return $this->Uri->next($this, $method);
} }
} }
?> ?>

View File

@@ -1,28 +1,40 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
// +----------------------------------------------------------------------+
//
// $Id: Weekday.php,v 1.3 2004/08/16 12:25:15 hfuecks Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Decorator_Weekday class
* @version $Id: Weekday.php,v 1.3 2004/08/16 12:25:15 hfuecks Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Weekday.php 300729 2010-06-24 12:05:53Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
@@ -46,12 +58,19 @@ require_once CALENDAR_ROOT.'Day.php';
* Decorator for fetching the day of the week * Decorator for fetching the day of the week
* <code> * <code>
* $Day = new Calendar_Day(2003, 10, 23); * $Day = new Calendar_Day(2003, 10, 23);
* $Weekday = & new Calendar_Decorator_Weekday($Day); * $Weekday = new Calendar_Decorator_Weekday($Day);
* $Weekday->setFirstDay(0); // Set first day of week to Sunday (default Mon) * $Weekday->setFirstDay(0); // Set first day of week to Sunday (default Mon)
* echo $Weekday->thisWeekDay(); // Displays 5 - fifth day of week relative to Sun * echo $Weekday->thisWeekDay(); // Displays 5 - fifth day of week relative to Sun
* </code> * </code>
* @package Calendar *
* @access public * @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @access public
*/ */
class Calendar_Decorator_Weekday extends Calendar_Decorator class Calendar_Decorator_Weekday extends Calendar_Decorator
{ {
@@ -64,84 +83,112 @@ class Calendar_Decorator_Weekday extends Calendar_Decorator
/** /**
* Constructs Calendar_Decorator_Weekday * Constructs Calendar_Decorator_Weekday
* @param object subclass of Calendar *
* @param object &$Calendar subclass of Calendar
*
* @access public * @access public
*/ */
function Calendar_Decorator_Weekday(& $Calendar) function Calendar_Decorator_Weekday(&$Calendar)
{ {
parent::Calendar_Decorator($Calendar); parent::Calendar_Decorator($Calendar);
} }
/** /**
* Sets the first day of the week (0 = Sunday, 1 = Monday (default) etc) * Sets the first day of the week (0 = Sunday, 1 = Monday (default) etc)
* @param int first day of week *
* @param int $firstDay first day of week
*
* @return void * @return void
* @access public * @access public
*/ */
function setFirstDay($firstDay) { function setFirstDay($firstDay)
{
$this->firstDay = (int)$firstDay; $this->firstDay = (int)$firstDay;
} }
/** /**
* Returns the previous weekday * Returns the previous weekday
* @param string (default = 'int') return value format *
* @return int numeric day of week or timestamp * @param string $format (default = 'int') return value format
*
* @return int $format numeric day of week or timestamp
* @access public * @access public
*/ */
function prevWeekDay($format = 'int') function prevWeekDay($format = 'int')
{ {
$ts = $this->calendar->prevDay('timestamp'); $ts = $this->calendar->prevDay('timestamp');
$Day = new Calendar_Day(2000,1,1); $Day = new Calendar_Day(2000, 1, 1);
$Day->setTimeStamp($ts); $Day->setTimeStamp($ts);
$day = $this->calendar->cE->getDayOfWeek($Day->thisYear(),$Day->thisMonth(),$Day->thisDay()); $day = $this->calendar->cE->getDayOfWeek(
$Day->thisYear(),
$Day->thisMonth(),
$Day->thisDay()
);
$day = $this->adjustWeekScale($day); $day = $this->adjustWeekScale($day);
return $this->returnValue('Day', $format, $ts, $day); return $this->returnValue('Day', $format, $ts, $day);
} }
/** /**
* Returns the current weekday * Returns the current weekday
* @param string (default = 'int') return value format *
* @param string $format (default = 'int') return value format
*
* @return int numeric day of week or timestamp * @return int numeric day of week or timestamp
* @access public * @access public
*/ */
function thisWeekDay($format = 'int') function thisWeekDay($format = 'int')
{ {
$ts = $this->calendar->thisDay('timestamp'); $ts = $this->calendar->thisDay('timestamp');
$day = $this->calendar->cE->getDayOfWeek($this->calendar->year,$this->calendar->month,$this->calendar->day); $day = $this->calendar->cE->getDayOfWeek(
$this->calendar->year,
$this->calendar->month,
$this->calendar->day
);
$day = $this->adjustWeekScale($day); $day = $this->adjustWeekScale($day);
return $this->returnValue('Day', $format, $ts, $day); return $this->returnValue('Day', $format, $ts, $day);
} }
/** /**
* Returns the next weekday * Returns the next weekday
* @param string (default = 'int') return value format *
* @param string $format (default = 'int') return value format
*
* @return int numeric day of week or timestamp * @return int numeric day of week or timestamp
* @access public * @access public
*/ */
function nextWeekDay($format = 'int') function nextWeekDay($format = 'int')
{ {
$ts = $this->calendar->nextDay('timestamp'); $ts = $this->calendar->nextDay('timestamp');
$Day = new Calendar_Day(2000,1,1); $Day = new Calendar_Day(2000, 1, 1);
$Day->setTimeStamp($ts); $Day->setTimeStamp($ts);
$day = $this->calendar->cE->getDayOfWeek($Day->thisYear(),$Day->thisMonth(),$Day->thisDay()); $day = $this->calendar->cE->getDayOfWeek(
$Day->thisYear(),
$Day->thisMonth(),
$Day->thisDay()
);
$day = $this->adjustWeekScale($day); $day = $this->adjustWeekScale($day);
return $this->returnValue('Day', $format, $ts, $day); return $this->returnValue('Day', $format, $ts, $day);
} }
/** /**
* Adjusts the day of the week relative to the first day of the week * Adjusts the day of the week relative to the first day of the week
* @param int day of week calendar from Calendar_Engine *
* @param int $dayOfWeek day of week calendar from Calendar_Engine
*
* @return int day of week adjusted to first day * @return int day of week adjusted to first day
* @access private * @access private
*/ */
function adjustWeekScale($dayOfWeek) { function adjustWeekScale($dayOfWeek)
{
$dayOfWeek = $dayOfWeek - $this->firstDay; $dayOfWeek = $dayOfWeek - $this->firstDay;
if ( $dayOfWeek >= 0 ) { if ($dayOfWeek >= 0) {
return $dayOfWeek; return $dayOfWeek;
} else { } else {
return $this->calendar->cE->getDaysInWeek( return $this->calendar->cE->getDaysInWeek(
$this->calendar->year,$this->calendar->month,$this->calendar->day $this->calendar->year,
) + $dayOfWeek; $this->calendar->month,
$this->calendar->day
) + $dayOfWeek;
} }
} }
} }

View File

@@ -1,28 +1,40 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
// +----------------------------------------------------------------------+
//
// $Id: Wrapper.php,v 1.2 2005/11/03 20:35:03 quipo Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Decorator_Wrapper class
* @version $Id: Wrapper.php,v 1.2 2005/11/03 20:35:03 quipo Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Wrapper.php 300729 2010-06-24 12:05:53Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
@@ -40,14 +52,23 @@ require_once CALENDAR_ROOT.'Decorator.php';
/** /**
* Decorator to help with wrapping built children in another decorator * Decorator to help with wrapping built children in another decorator
* @package Calendar *
* @access public * @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @access public
*/ */
class Calendar_Decorator_Wrapper extends Calendar_Decorator class Calendar_Decorator_Wrapper extends Calendar_Decorator
{ {
/** /**
* Constructs Calendar_Decorator_Wrapper * Constructs Calendar_Decorator_Wrapper
* @param object subclass of Calendar *
* @param object &$Calendar subclass of Calendar
*
* @access public * @access public
*/ */
function Calendar_Decorator_Wrapper(&$Calendar) function Calendar_Decorator_Wrapper(&$Calendar)
@@ -57,7 +78,9 @@ class Calendar_Decorator_Wrapper extends Calendar_Decorator
/** /**
* Wraps objects returned from fetch in the named Decorator class * Wraps objects returned from fetch in the named Decorator class
* @param string name of Decorator class to wrap with *
* @param string $decorator name of Decorator class to wrap with
*
* @return object instance of named decorator * @return object instance of named decorator
* @access public * @access public
*/ */
@@ -65,7 +88,7 @@ class Calendar_Decorator_Wrapper extends Calendar_Decorator
{ {
$Calendar = parent::fetch(); $Calendar = parent::fetch();
if ($Calendar) { if ($Calendar) {
$ret =& new $decorator($Calendar); $ret = new $decorator($Calendar);
} else { } else {
$ret = false; $ret = false;
} }
@@ -74,7 +97,9 @@ class Calendar_Decorator_Wrapper extends Calendar_Decorator
/** /**
* Wraps the returned calendar objects from fetchAll in the named decorator * Wraps the returned calendar objects from fetchAll in the named decorator
* @param string name of Decorator class to wrap with *
* @param string $decorator name of Decorator class to wrap with
*
* @return array * @return array
* @access public * @access public
*/ */
@@ -82,7 +107,7 @@ class Calendar_Decorator_Wrapper extends Calendar_Decorator
{ {
$children = parent::fetchAll(); $children = parent::fetchAll();
foreach ($children as $key => $Calendar) { foreach ($children as $key => $Calendar) {
$children[$key] = & new $decorator($Calendar); $children[$key] = new $decorator($Calendar);
} }
return $children; return $children;
} }

View File

@@ -1,32 +1,53 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// +----------------------------------------------------------------------+
//
// $Id: Interface.php,v 1.5 2004/08/16 12:29:18 hfuecks Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Engine_Interface class (interface)
* @version $Id: Interface.php,v 1.5 2004/08/16 12:29:18 hfuecks Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Interface.php 269074 2008-11-15 21:21:42Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
* The methods the classes implementing the Calendar_Engine must implement. * The methods the classes implementing the Calendar_Engine must implement.
* Note this class is not used but simply to help development * Note this class is not used but simply to help development
* @package Calendar *
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @access protected * @access protected
*/ */
class Calendar_Engine_Interface class Calendar_Engine_Interface
@@ -36,7 +57,9 @@ class Calendar_Engine_Interface
* into human dates is only performed once per timestamp. * into human dates is only performed once per timestamp.
* Typically called "internally" by methods like stampToYear. * Typically called "internally" by methods like stampToYear.
* Return value can vary, depending on the specific implementation * Return value can vary, depending on the specific implementation
* @param int timestamp (depending on implementation) *
* @param int $stamp timestamp (depending on implementation)
*
* @return mixed * @return mixed
* @access protected * @access protected
*/ */
@@ -46,7 +69,9 @@ class Calendar_Engine_Interface
/** /**
* Returns a numeric year given a timestamp * Returns a numeric year given a timestamp
* @param int timestamp (depending on implementation) *
* @param int $stamp timestamp (depending on implementation)
*
* @return int year (e.g. 2003) * @return int year (e.g. 2003)
* @access protected * @access protected
*/ */
@@ -56,7 +81,9 @@ class Calendar_Engine_Interface
/** /**
* Returns a numeric month given a timestamp * Returns a numeric month given a timestamp
* @param int timestamp (depending on implementation) *
* @param int $stamp timestamp (depending on implementation)
*
* @return int month (e.g. 9) * @return int month (e.g. 9)
* @access protected * @access protected
*/ */
@@ -66,7 +93,9 @@ class Calendar_Engine_Interface
/** /**
* Returns a numeric day given a timestamp * Returns a numeric day given a timestamp
* @param int timestamp (depending on implementation) *
* @param int $stamp timestamp (depending on implementation)
*
* @return int day (e.g. 15) * @return int day (e.g. 15)
* @access protected * @access protected
*/ */
@@ -76,7 +105,9 @@ class Calendar_Engine_Interface
/** /**
* Returns a numeric hour given a timestamp * Returns a numeric hour given a timestamp
* @param int timestamp (depending on implementation) *
* @param int $stamp timestamp (depending on implementation)
*
* @return int hour (e.g. 13) * @return int hour (e.g. 13)
* @access protected * @access protected
*/ */
@@ -86,7 +117,9 @@ class Calendar_Engine_Interface
/** /**
* Returns a numeric minute given a timestamp * Returns a numeric minute given a timestamp
* @param int timestamp (depending on implementation) *
* @param int $stamp timestamp (depending on implementation)
*
* @return int minute (e.g. 34) * @return int minute (e.g. 34)
* @access protected * @access protected
*/ */
@@ -96,7 +129,9 @@ class Calendar_Engine_Interface
/** /**
* Returns a numeric second given a timestamp * Returns a numeric second given a timestamp
* @param int timestamp (depending on implementation) *
* @param int $stamp timestamp (depending on implementation)
*
* @return int second (e.g. 51) * @return int second (e.g. 51)
* @access protected * @access protected
*/ */
@@ -105,25 +140,27 @@ class Calendar_Engine_Interface
} }
/** /**
* Returns a timestamp. Can be worth "caching" generated * Returns a timestamp. Can be worth "caching" generated timestamps in a
* timestamps in a static variable, identified by the * static variable, identified by the params this method accepts,
* params this method accepts, to timestamp will only * to timestamp will only be calculated once.
* be calculated once. *
* @param int year (e.g. 2003) * @param int $y year (e.g. 2003)
* @param int month (e.g. 9) * @param int $m month (e.g. 9)
* @param int day (e.g. 13) * @param int $d day (e.g. 13)
* @param int hour (e.g. 13) * @param int $h hour (e.g. 13)
* @param int minute (e.g. 34) * @param int $i minute (e.g. 34)
* @param int second (e.g. 53) * @param int $s second (e.g. 53)
*
* @return int (depends on implementation) * @return int (depends on implementation)
* @access protected * @access protected
*/ */
function dateToStamp($y,$m,$d,$h,$i,$s) function dateToStamp($y, $m, $d, $h, $i, $s)
{ {
} }
/** /**
* The upper limit on years that the Calendar Engine can work with * The upper limit on years that the Calendar Engine can work with
*
* @return int (e.g. 2037) * @return int (e.g. 2037)
* @access protected * @access protected
*/ */
@@ -133,6 +170,7 @@ class Calendar_Engine_Interface
/** /**
* The lower limit on years that the Calendar Engine can work with * The lower limit on years that the Calendar Engine can work with
*
* @return int (e.g 1902) * @return int (e.g 1902)
* @access protected * @access protected
*/ */
@@ -142,7 +180,9 @@ class Calendar_Engine_Interface
/** /**
* Returns the number of months in a year * Returns the number of months in a year
* @param int (optional) year to get months for *
* @param int $y (optional) year to get months for
*
* @return int (e.g. 12) * @return int (e.g. 12)
* @access protected * @access protected
*/ */
@@ -152,8 +192,10 @@ class Calendar_Engine_Interface
/** /**
* Returns the number of days in a month, given year and month * Returns the number of days in a month, given year and month
* @param int year (e.g. 2003) *
* @param int month (e.g. 9) * @param int $y year (e.g. 2003)
* @param int $m month (e.g. 9)
*
* @return int days in month * @return int days in month
* @access protected * @access protected
*/ */
@@ -164,8 +206,10 @@ class Calendar_Engine_Interface
/** /**
* Returns numeric representation of the day of the week in a month, * Returns numeric representation of the day of the week in a month,
* given year and month * given year and month
* @param int year (e.g. 2003) *
* @param int month (e.g. 9) * @param int $y year (e.g. 2003)
* @param int $m month (e.g. 9)
*
* @return int * @return int
* @access protected * @access protected
*/ */
@@ -175,21 +219,25 @@ class Calendar_Engine_Interface
/** /**
* Returns the number of days in a week * Returns the number of days in a week
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (4) * @param int $m month (9)
* @param int $d day (4)
*
* @return int (e.g. 7) * @return int (e.g. 7)
* @access protected * @access protected
*/ */
function getDaysInWeek($y=NULL, $m=NULL, $d=NULL) function getDaysInWeek($y=null, $m=null, $d=null)
{ {
} }
/** /**
* Returns the number of the week in the year (ISO-8601), given a date * Returns the number of the week in the year (ISO-8601), given a date
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (4) * @param int $m month (9)
* @param int $d day (4)
*
* @return int week number * @return int week number
* @access protected * @access protected
*/ */
@@ -199,10 +247,12 @@ class Calendar_Engine_Interface
/** /**
* Returns the number of the week in the month, given a date * Returns the number of the week in the month, given a date
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (4) * @param int $m month (9)
* @param int first day of the week (default: 1 - monday) * @param int $d day (4)
* @param int $firstDay first day of the week (default: 1 - monday)
*
* @return int week number * @return int week number
* @access protected * @access protected
*/ */
@@ -212,9 +262,10 @@ class Calendar_Engine_Interface
/** /**
* Returns the number of weeks in the month * Returns the number of weeks in the month
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int first day of the week (default: 1 - monday) * @param int $m month (9)
*
* @return int weeks number * @return int weeks number
* @access protected * @access protected
*/ */
@@ -224,9 +275,11 @@ class Calendar_Engine_Interface
/** /**
* Returns the number of the day of the week (0=sunday, 1=monday...) * Returns the number of the day of the week (0=sunday, 1=monday...)
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (4) * @param int $m month (9)
* @param int $d day (4)
*
* @return int weekday number * @return int weekday number
* @access protected * @access protected
*/ */
@@ -236,33 +289,41 @@ class Calendar_Engine_Interface
/** /**
* Returns the numeric values of the days of the week. * Returns the numeric values of the days of the week.
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (4) * @param int $m month (9)
* @param int $d day (4)
*
* @return array list of numeric values of days in week, beginning 0 * @return array list of numeric values of days in week, beginning 0
* @access protected * @access protected
*/ */
function getWeekDays($y=NULL, $m=NULL, $d=NULL) function getWeekDays($y=null, $m=null, $d=null)
{ {
} }
/** /**
* Returns the default first day of the week as an integer. Must be a * Returns the default first day of the week as an integer. Must be a
* member of the array returned from getWeekDays * member of the array returned from getWeekDays
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (4) * @param int $m month (9)
* @param int $d day (4)
*
* @return int (e.g. 1 for Monday) * @return int (e.g. 1 for Monday)
* @see getWeekDays * @see getWeekDays
* @access protected * @access protected
*/ */
function getFirstDayOfWeek($y=NULL, $m=NULL, $d=NULL) function getFirstDayOfWeek($y=null, $m=null, $d=null)
{ {
} }
/** /**
* Returns the number of hours in a day<br> * Returns the number of hours in a day
* @param int (optional) day to get hours for *
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
*
* @return int (e.g. 24) * @return int (e.g. 24)
* @access protected * @access protected
*/ */
@@ -272,7 +333,12 @@ class Calendar_Engine_Interface
/** /**
* Returns the number of minutes in an hour * Returns the number of minutes in an hour
* @param int (optional) hour to get minutes for *
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
* @param int $h hour
*
* @return int * @return int
* @access protected * @access protected
*/ */
@@ -282,12 +348,30 @@ class Calendar_Engine_Interface
/** /**
* Returns the number of seconds in a minutes * Returns the number of seconds in a minutes
* @param int (optional) minute to get seconds for *
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
* @param int $h hour
* @param int $i minute
*
* @return int * @return int
* @access protected * @access protected
*/ */
function getSecondsInMinute($y=null,$m=null,$d=null,$h=null,$i=null) function getSecondsInMinute($y=null,$m=null,$d=null,$h=null,$i=null)
{ {
} }
/**
* Checks if the given day is the current day
*
* @param int timestamp (depending on implementation)
*
* @return boolean
* @access protected
*/
function isToday($stamp)
{
}
} }
?> ?>

View File

@@ -1,28 +1,41 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Lorenzo Alberton <l dot alberton at quipo dot it> |
// +----------------------------------------------------------------------+
//
// $Id: PearDate.php,v 1.8 2004/08/20 20:00:55 quipo Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Engine_PearDate class
* @version $Id: PearDate.php,v 1.8 2004/08/20 20:00:55 quipo Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: PearDate.php 269076 2008-11-15 21:41:38Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
* Load PEAR::Date class * Load PEAR::Date class
*/ */
@@ -31,7 +44,13 @@ require_once 'Date.php';
/** /**
* Performs calendar calculations based on the PEAR::Date class * Performs calendar calculations based on the PEAR::Date class
* Timestamps are in the ISO-8601 format (YYYY-MM-DD HH:MM:SS) * Timestamps are in the ISO-8601 format (YYYY-MM-DD HH:MM:SS)
* @package Calendar *
* @category Date and Time
* @package Calendar
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @access protected * @access protected
*/ */
class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
@@ -40,7 +59,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
* Makes sure a given timestamp is only ever parsed once * Makes sure a given timestamp is only ever parsed once
* Uses a static variable to prevent date() being used twice * Uses a static variable to prevent date() being used twice
* for a date which is already known * for a date which is already known
* @param mixed Any timestamp format recognized by Pear::Date *
* @param mixed $stamp Any timestamp format recognized by Pear::Date
*
* @return object Pear::Date object * @return object Pear::Date object
* @access protected * @access protected
*/ */
@@ -55,7 +76,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* Returns a numeric year given a iso-8601 datetime * Returns a numeric year given a iso-8601 datetime
* @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS) *
* @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
*
* @return int year (e.g. 2003) * @return int year (e.g. 2003)
* @access protected * @access protected
*/ */
@@ -67,7 +90,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* Returns a numeric month given a iso-8601 datetime * Returns a numeric month given a iso-8601 datetime
* @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS) *
* @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
*
* @return int month (e.g. 9) * @return int month (e.g. 9)
* @access protected * @access protected
*/ */
@@ -79,7 +104,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* Returns a numeric day given a iso-8601 datetime * Returns a numeric day given a iso-8601 datetime
* @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS) *
* @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
*
* @return int day (e.g. 15) * @return int day (e.g. 15)
* @access protected * @access protected
*/ */
@@ -91,7 +118,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* Returns a numeric hour given a iso-8601 datetime * Returns a numeric hour given a iso-8601 datetime
* @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS) *
* @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
*
* @return int hour (e.g. 13) * @return int hour (e.g. 13)
* @access protected * @access protected
*/ */
@@ -103,7 +132,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* Returns a numeric minute given a iso-8601 datetime * Returns a numeric minute given a iso-8601 datetime
* @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS) *
* @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
*
* @return int minute (e.g. 34) * @return int minute (e.g. 34)
* @access protected * @access protected
*/ */
@@ -115,7 +146,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* Returns a numeric second given a iso-8601 datetime * Returns a numeric second given a iso-8601 datetime
* @param string iso-8601 datetime (YYYY-MM-DD HH:MM:SS) *
* @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS)
*
* @return int second (e.g. 51) * @return int second (e.g. 51)
* @access protected * @access protected
*/ */
@@ -127,12 +160,14 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* Returns a iso-8601 datetime * Returns a iso-8601 datetime
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (13) * @param int $m month (9)
* @param int hour (13) * @param int $d day (13)
* @param int minute (34) * @param int $h hour (13)
* @param int second (53) * @param int $i minute (34)
* @param int $s second (53)
*
* @return string iso-8601 datetime * @return string iso-8601 datetime
* @access protected * @access protected
*/ */
@@ -150,12 +185,15 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* Set the correct date values (useful for math operations on dates) * Set the correct date values (useful for math operations on dates)
* @param int year (2003) *
* @param int month (9) * @param int &$y year (2003)
* @param int day (13) * @param int &$m month (9)
* @param int hour (13) * @param int &$d day (13)
* @param int minute (34) * @param int &$h hour (13)
* @param int second (53) * @param int &$i minute (34)
* @param int &$s second (53)
*
* @return void
* @access protected * @access protected
*/ */
function adjustDate(&$y, &$m, &$d, &$h, &$i, &$s) function adjustDate(&$y, &$m, &$d, &$h, &$i, &$s)
@@ -209,6 +247,7 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* The upper limit on years that the Calendar Engine can work with * The upper limit on years that the Calendar Engine can work with
*
* @return int 9999 * @return int 9999
* @access protected * @access protected
*/ */
@@ -219,6 +258,7 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* The lower limit on years that the Calendar Engine can work with * The lower limit on years that the Calendar Engine can work with
*
* @return int 0 * @return int 0
* @access protected * @access protected
*/ */
@@ -229,6 +269,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* Returns the number of months in a year * Returns the number of months in a year
*
* @param int $y year
*
* @return int (12) * @return int (12)
* @access protected * @access protected
*/ */
@@ -239,8 +282,10 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* Returns the number of days in a month, given year and month * Returns the number of days in a month, given year and month
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int $m month (9)
*
* @return int days in month * @return int days in month
* @access protected * @access protected
*/ */
@@ -252,8 +297,10 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* Returns numeric representation of the day of the week in a month, * Returns numeric representation of the day of the week in a month,
* given year and month * given year and month
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int $m month (9)
*
* @return int from 0 to 7 * @return int from 0 to 7
* @access protected * @access protected
*/ */
@@ -264,36 +311,44 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* Returns the number of days in a week * Returns the number of days in a week
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (4) * @param int $m month (9)
* @param int $d day (4)
*
* @return int (7) * @return int (7)
* @access protected * @access protected
*/ */
function getDaysInWeek($y=NULL, $m=NULL, $d=NULL) function getDaysInWeek($y=null, $m=null, $d=null)
{ {
return 7; return 7;
} }
/** /**
* Returns the number of the week in the year (ISO-8601), given a date * Returns the number of the week in the year (ISO-8601), given a date
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (4) * @param int $m month (9)
* @param int $d day (4)
*
* @return int week number * @return int week number
* @access protected * @access protected
*/ */
function getWeekNInYear($y, $m, $d) function getWeekNInYear($y, $m, $d)
{ {
return Date_Calc::weekOfYear($d, $m, $y); //beware, Date_Calc doesn't follow ISO-8601 standard! //return Date_Calc::weekOfYear($d, $m, $y); //beware, Date_Calc doesn't follow ISO-8601 standard!
list($nYear, $nWeek) = Date_Calc::weekOfYear4th($d, $m, $y);
return $nWeek;
} }
/** /**
* Returns the number of the week in the month, given a date * Returns the number of the week in the month, given a date
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (4) * @param int $m month (9)
* @param int first day of the week (default: monday) * @param int $d day (4)
* @param int $firstDay first day of the week (default: monday)
*
* @return int week number * @return int week number
* @access protected * @access protected
*/ */
@@ -311,9 +366,11 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* Returns the number of weeks in the month * Returns the number of weeks in the month
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int first day of the week (default: monday) * @param int $m month (9)
* @param int $firstDay first day of the week (default: monday)
*
* @return int weeks number * @return int weeks number
* @access protected * @access protected
*/ */
@@ -337,9 +394,11 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* Returns the number of the day of the week (0=sunday, 1=monday...) * Returns the number of the day of the week (0=sunday, 1=monday...)
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (4) * @param int $m month (9)
* @param int $d day (4)
*
* @return int weekday number * @return int weekday number
* @access protected * @access protected
*/ */
@@ -350,32 +409,41 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* Returns a list of integer days of the week beginning 0 * Returns a list of integer days of the week beginning 0
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (4) * @param int $m month (9)
* @param int $d day (4)
*
* @return array (0, 1, 2, 3, 4, 5, 6) 1 = Monday * @return array (0, 1, 2, 3, 4, 5, 6) 1 = Monday
* @access protected * @access protected
*/ */
function getWeekDays($y=NULL, $m=NULL, $d=NULL) function getWeekDays($y=null, $m=null, $d=null)
{ {
return array(0, 1, 2, 3, 4, 5, 6); return array(0, 1, 2, 3, 4, 5, 6);
} }
/** /**
* Returns the default first day of the week * Returns the default first day of the week
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (4) * @param int $m month (9)
* @param int $d day (4)
*
* @return int (default 1 = Monday) * @return int (default 1 = Monday)
* @access protected * @access protected
*/ */
function getFirstDayOfWeek($y=NULL, $m=NULL, $d=NULL) function getFirstDayOfWeek($y=null, $m=null, $d=null)
{ {
return 1; return 1;
} }
/** /**
* Returns the number of hours in a day * Returns the number of hours in a day
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
*
* @return int (24) * @return int (24)
* @access protected * @access protected
*/ */
@@ -386,6 +454,12 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* Returns the number of minutes in an hour * Returns the number of minutes in an hour
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
* @param int $h hour
*
* @return int (60) * @return int (60)
* @access protected * @access protected
*/ */
@@ -396,6 +470,13 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/** /**
* Returns the number of seconds in a minutes * Returns the number of seconds in a minutes
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
* @param int $h hour
* @param int $i minute
*
* @return int (60) * @return int (60)
* @access protected * @access protected
*/ */
@@ -403,5 +484,26 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
{ {
return 60; return 60;
} }
/**
* Checks if the given day is the current day
*
* @param mixed $stamp Any timestamp format recognized by Pear::Date
*
* @return boolean
* @access protected
*/
function isToday($stamp)
{
static $today = null;
if (is_null($today)) {
$today = new Date();
}
$date = Calendar_Engine_PearDate::stampCollection($stamp);
return ( $date->day == $today->getDay()
&& $date->month == $today->getMonth()
&& $date->year == $today->getYear()
);
}
} }
?> ?>

View File

@@ -1,33 +1,52 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// +----------------------------------------------------------------------+
//
// $Id: UnixTS.php,v 1.9 2004/08/20 20:00:55 quipo Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Engine_UnixTS class
* @version $Id: UnixTS.php,v 1.9 2004/08/20 20:00:55 quipo Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: UnixTS.php 269074 2008-11-15 21:21:42Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
* Performs calendar calculations based on the PHP date() function and * Performs calendar calculations based on the PHP date() function and
* Unix timestamps (using PHP's mktime() function). * Unix timestamps (using PHP's mktime() function).
* @package Calendar *
* @access protected * @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @access protected
*/ */
class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
{ {
@@ -48,7 +67,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
* </pre> * </pre>
* Uses a static variable to prevent date() being used twice * Uses a static variable to prevent date() being used twice
* for a date which is already known * for a date which is already known
* @param int Unix timestamp *
* @param int $stamp Unix timestamp
*
* @return array * @return array
* @access protected * @access protected
*/ */
@@ -56,7 +77,7 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
{ {
static $stamps = array(); static $stamps = array();
if ( !isset($stamps[$stamp]) ) { if ( !isset($stamps[$stamp]) ) {
$date = @date('Y n j H i s t W w',$stamp); $date = @date('Y n j H i s t W w', $stamp);
$stamps[$stamp] = sscanf($date, "%d %d %d %d %d %d %d %d %d"); $stamps[$stamp] = sscanf($date, "%d %d %d %d %d %d %d %d %d");
} }
return $stamps[$stamp]; return $stamps[$stamp];
@@ -64,7 +85,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/** /**
* Returns a numeric year given a timestamp * Returns a numeric year given a timestamp
* @param int Unix timestamp *
* @param int $stamp Unix timestamp
*
* @return int year (e.g. 2003) * @return int year (e.g. 2003)
* @access protected * @access protected
*/ */
@@ -76,7 +99,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/** /**
* Returns a numeric month given a timestamp * Returns a numeric month given a timestamp
* @param int Unix timestamp *
* @param int $stamp Unix timestamp
*
* @return int month (e.g. 9) * @return int month (e.g. 9)
* @access protected * @access protected
*/ */
@@ -88,7 +113,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/** /**
* Returns a numeric day given a timestamp * Returns a numeric day given a timestamp
* @param int Unix timestamp *
* @param int $stamp Unix timestamp
*
* @return int day (e.g. 15) * @return int day (e.g. 15)
* @access protected * @access protected
*/ */
@@ -100,7 +127,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/** /**
* Returns a numeric hour given a timestamp * Returns a numeric hour given a timestamp
* @param int Unix timestamp *
* @param int $stamp Unix timestamp
*
* @return int hour (e.g. 13) * @return int hour (e.g. 13)
* @access protected * @access protected
*/ */
@@ -112,7 +141,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/** /**
* Returns a numeric minute given a timestamp * Returns a numeric minute given a timestamp
* @param int Unix timestamp *
* @param int $stamp Unix timestamp
*
* @return int minute (e.g. 34) * @return int minute (e.g. 34)
* @access protected * @access protected
*/ */
@@ -124,7 +155,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/** /**
* Returns a numeric second given a timestamp * Returns a numeric second given a timestamp
* @param int Unix timestamp *
* @param int $stamp Unix timestamp
*
* @return int second (e.g. 51) * @return int second (e.g. 51)
* @access protected * @access protected
*/ */
@@ -136,19 +169,21 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/** /**
* Returns a timestamp * Returns a timestamp
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (13) * @param int $m month (9)
* @param int hour (13) * @param int $d day (13)
* @param int minute (34) * @param int $h hour (13)
* @param int second (53) * @param int $i minute (34)
* @param int $s second (53)
*
* @return int Unix timestamp * @return int Unix timestamp
* @access protected * @access protected
*/ */
function dateToStamp($y, $m, $d, $h=0, $i=0, $s=0) function dateToStamp($y, $m, $d, $h=0, $i=0, $s=0)
{ {
static $dates = array(); static $dates = array();
if ( !isset($dates[$y][$m][$d][$h][$i][$s]) ) { if (!isset($dates[$y][$m][$d][$h][$i][$s])) {
$dates[$y][$m][$d][$h][$i][$s] = @mktime($h, $i, $s, $m, $d, $y); $dates[$y][$m][$d][$h][$i][$s] = @mktime($h, $i, $s, $m, $d, $y);
} }
return $dates[$y][$m][$d][$h][$i][$s]; return $dates[$y][$m][$d][$h][$i][$s];
@@ -156,6 +191,7 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/** /**
* The upper limit on years that the Calendar Engine can work with * The upper limit on years that the Calendar Engine can work with
*
* @return int (2037) * @return int (2037)
* @access protected * @access protected
*/ */
@@ -166,6 +202,7 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/** /**
* The lower limit on years that the Calendar Engine can work with * The lower limit on years that the Calendar Engine can work with
*
* @return int (1970 if it's Windows and 1902 for all other OSs) * @return int (1970 if it's Windows and 1902 for all other OSs)
* @access protected * @access protected
*/ */
@@ -176,8 +213,11 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/** /**
* Returns the number of months in a year * Returns the number of months in a year
*
* @param int $y year
*
* @return int (12) * @return int (12)
* @access protected * @access protected
*/ */
function getMonthsInYear($y=null) function getMonthsInYear($y=null)
{ {
@@ -186,73 +226,83 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/** /**
* Returns the number of days in a month, given year and month * Returns the number of days in a month, given year and month
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int $m month (9)
*
* @return int days in month * @return int days in month
* @access protected * @access protected
*/ */
function getDaysInMonth($y, $m) function getDaysInMonth($y, $m)
{ {
$stamp = Calendar_Engine_UnixTS::dateToStamp($y,$m,1); $stamp = Calendar_Engine_UnixTS::dateToStamp($y, $m, 1);
$date = Calendar_Engine_UnixTS::stampCollection($stamp); $date = Calendar_Engine_UnixTS::stampCollection($stamp);
return $date[6]; return $date[6];
} }
/** /**
* Returns numeric representation of the day of the week in a month, * Returns numeric representation of the day of the week in a month,
* given year and month * given year and month
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int $m month (9)
*
* @return int from 0 to 6 * @return int from 0 to 6
* @access protected * @access protected
*/ */
function getFirstDayInMonth($y, $m) function getFirstDayInMonth($y, $m)
{ {
$stamp = Calendar_Engine_UnixTS::dateToStamp($y,$m,1); $stamp = Calendar_Engine_UnixTS::dateToStamp($y, $m, 1);
$date = Calendar_Engine_UnixTS::stampCollection($stamp); $date = Calendar_Engine_UnixTS::stampCollection($stamp);
return $date[8]; return $date[8];
} }
/** /**
* Returns the number of days in a week * Returns the number of days in a week
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (4) * @param int $m month (9)
* @param int $d day (4)
*
* @return int (7) * @return int (7)
* @access protected * @access protected
*/ */
function getDaysInWeek($y=NULL, $m=NULL, $d=NULL) function getDaysInWeek($y=null, $m=null, $d=null)
{ {
return 7; return 7;
} }
/** /**
* Returns the number of the week in the year (ISO-8601), given a date * Returns the number of the week in the year (ISO-8601), given a date
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (4) * @param int $m month (9)
* @param int $d day (4)
*
* @return int week number * @return int week number
* @access protected * @access protected
*/ */
function getWeekNInYear($y, $m, $d) function getWeekNInYear($y, $m, $d)
{ {
$stamp = Calendar_Engine_UnixTS::dateToStamp($y,$m,$d); $stamp = Calendar_Engine_UnixTS::dateToStamp($y, $m, $d);
$date = Calendar_Engine_UnixTS::stampCollection($stamp); $date = Calendar_Engine_UnixTS::stampCollection($stamp);
return $date[7]; return $date[7];
} }
/** /**
* Returns the number of the week in the month, given a date * Returns the number of the week in the month, given a date
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (4) * @param int $m month (9)
* @param int first day of the week (default: monday) * @param int $d day (4)
* @param int $firstDay first day of the week (default: monday)
*
* @return int week number * @return int week number
* @access protected * @access protected
*/ */
function getWeekNInMonth($y, $m, $d, $firstDay=1) function getWeekNInMonth($y, $m, $d, $firstDay=1)
{ {
$weekEnd = ($firstDay == 0) ? $this->getDaysInWeek()-1 : $firstDay-1; $weekEnd = (0 == $firstDay) ? $this->getDaysInWeek()-1 : $firstDay-1;
$end_of_week = 1; $end_of_week = 1;
while (@date('w', @mktime(0, 0, 0, $m, $end_of_week, $y)) != $weekEnd) { while (@date('w', @mktime(0, 0, 0, $m, $end_of_week, $y)) != $weekEnd) {
++$end_of_week; //find first weekend of the month ++$end_of_week; //find first weekend of the month
@@ -267,13 +317,15 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/** /**
* Returns the number of weeks in the month * Returns the number of weeks in the month
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int first day of the week (default: monday) * @param int $m month (9)
* @param int $firstDay first day of the week (default: monday)
*
* @return int weeks number * @return int weeks number
* @access protected * @access protected
*/ */
function getWeeksInMonth($y, $m, $firstDay=1) function getWeeksInMonth($y, $m, $firstDay = 1)
{ {
$FDOM = $this->getFirstDayInMonth($y, $m); $FDOM = $this->getFirstDayInMonth($y, $m);
if ($FDOM == 0) { if ($FDOM == 0) {
@@ -293,73 +345,119 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/** /**
* Returns the number of the day of the week (0=sunday, 1=monday...) * Returns the number of the day of the week (0=sunday, 1=monday...)
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (4) * @param int $m month (9)
* @param int $d day (4)
*
* @return int weekday number * @return int weekday number
* @access protected * @access protected
*/ */
function getDayOfWeek($y, $m, $d) function getDayOfWeek($y, $m, $d)
{ {
$stamp = Calendar_Engine_UnixTS::dateToStamp($y,$m,$d); $stamp = Calendar_Engine_UnixTS::dateToStamp($y, $m, $d);
$date = Calendar_Engine_UnixTS::stampCollection($stamp); $date = Calendar_Engine_UnixTS::stampCollection($stamp);
return $date[8]; return $date[8];
} }
/** /**
* Returns a list of integer days of the week beginning 0 * Returns a list of integer days of the week beginning 0
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (4) * @param int $m month (9)
* @param int $d day (4)
*
* @return array (0,1,2,3,4,5,6) 1 = Monday * @return array (0,1,2,3,4,5,6) 1 = Monday
* @access protected * @access protected
*/ */
function getWeekDays($y=NULL, $m=NULL, $d=NULL) function getWeekDays($y=null, $m=null, $d=null)
{ {
return array(0, 1, 2, 3, 4, 5, 6); return array(0, 1, 2, 3, 4, 5, 6);
} }
/** /**
* Returns the default first day of the week * Returns the default first day of the week
* @param int year (2003) *
* @param int month (9) * @param int $y year (2003)
* @param int day (4) * @param int $m month (9)
* @param int $d day (4)
*
* @return int (default 1 = Monday) * @return int (default 1 = Monday)
* @access protected * @access protected
*/ */
function getFirstDayOfWeek($y=NULL, $m=NULL, $d=NULL) function getFirstDayOfWeek($y=null, $m=null, $d=null)
{ {
return 1; return 1;
} }
/** /**
* Returns the number of hours in a day * Returns the number of hours in a day
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
*
* @return int (24) * @return int (24)
* @access protected * @access protected
*/ */
function getHoursInDay($y=null,$m=null,$d=null) function getHoursInDay($y=null, $m=null, $d=null)
{ {
return 24; return 24;
} }
/** /**
* Returns the number of minutes in an hour * Returns the number of minutes in an hour
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
* @param int $h hour
*
* @return int (60) * @return int (60)
* @access protected * @access protected
*/ */
function getMinutesInHour($y=null,$m=null,$d=null,$h=null) function getMinutesInHour($y=null, $m=null, $d=null, $h=null)
{ {
return 60; return 60;
} }
/** /**
* Returns the number of seconds in a minutes * Returns the number of seconds in a minutes
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
* @param int $h hour
* @param int $i minute
*
* @return int (60) * @return int (60)
* @access protected * @access protected
*/ */
function getSecondsInMinute($y=null,$m=null,$d=null,$h=null,$i=null) function getSecondsInMinute($y=null, $m=null, $d=null, $h=null, $i=null)
{ {
return 60; return 60;
} }
/**
* Checks if the given day is the current day
*
* @param mixed $stamp Any timestamp format recognized by Pear::Date
*
* @return boolean
* @access protected
*/
function isToday($stamp)
{
static $today = null;
if (is_null($today)) {
$today_date = @date('Y n j');
$today = sscanf($today_date, '%d %d %d');
}
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
return ( $date[2] == $today[2]
&& $date[1] == $today[1]
&& $date[0] == $today[0]
);
}
} }
?> ?>

View File

@@ -1,28 +1,40 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
// +----------------------------------------------------------------------+
//
// $Id: Factory.php,v 1.3 2005/10/22 10:08:47 quipo Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Factory class
* @version $Id: Factory.php,v 1.3 2005/10/22 10:08:47 quipo Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Factory.php 246404 2007-11-18 21:46:43Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
@@ -52,92 +64,103 @@ require_once CALENDAR_ROOT.'Calendar.php';
* It defaults to building Calendar_Month objects.<br> * It defaults to building Calendar_Month objects.<br>
* Use the constract CALENDAR_FIRST_DAY_OF_WEEK to control the first day of the week * Use the constract CALENDAR_FIRST_DAY_OF_WEEK to control the first day of the week
* for Month or Week objects (e.g. 0 = Sunday, 6 = Saturday) * for Month or Week objects (e.g. 0 = Sunday, 6 = Saturday)
* @package Calendar *
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @access protected * @access protected
*/ */
class Calendar_Factory class Calendar_Factory
{ {
/** /**
* Creates a calendar object given the type and units * Creates a calendar object given the type and units
* @param string class of calendar object to create *
* @param int year * @param string $type class of calendar object to create
* @param int month * @param int $y year
* @param int day * @param int $m month
* @param int hour * @param int $d day
* @param int minute * @param int $h hour
* @param int second * @param int $i minute
* @param int $s second
*
* @return object subclass of Calendar * @return object subclass of Calendar
* @access public * @access public
* @static * @static
*/ */
function create($type, $y = 2000, $m = 1, $d = 1, $h = 0, $i = 0, $s = 0) static function create($type, $y = 2000, $m = 1, $d = 1, $h = 0, $i = 0, $s = 0)
{ {
$firstDay = defined('CALENDAR_FIRST_DAY_OF_WEEK') ? CALENDAR_FIRST_DAY_OF_WEEK : 1; $firstDay = defined('CALENDAR_FIRST_DAY_OF_WEEK') ? CALENDAR_FIRST_DAY_OF_WEEK : 1;
switch ($type) { switch ($type) {
case 'Day': case 'Day':
require_once CALENDAR_ROOT.'Day.php'; include_once CALENDAR_ROOT.'Day.php';
return new Calendar_Day($y,$m,$d); return new Calendar_Day($y, $m, $d);
case 'Month': case 'Month':
// Set default state for which month type to build // Set default state for which month type to build
if (!defined('CALENDAR_MONTH_STATE')) { if (!defined('CALENDAR_MONTH_STATE')) {
define('CALENDAR_MONTH_STATE', CALENDAR_USE_MONTH); define('CALENDAR_MONTH_STATE', CALENDAR_USE_MONTH);
} }
switch (CALENDAR_MONTH_STATE) { switch (CALENDAR_MONTH_STATE) {
case CALENDAR_USE_MONTH_WEEKDAYS: case CALENDAR_USE_MONTH_WEEKDAYS:
require_once CALENDAR_ROOT.'Month/Weekdays.php'; include_once CALENDAR_ROOT.'Month/Weekdays.php';
$class = 'Calendar_Month_Weekdays'; $class = 'Calendar_Month_Weekdays';
break; break;
case CALENDAR_USE_MONTH_WEEKS: case CALENDAR_USE_MONTH_WEEKS:
require_once CALENDAR_ROOT.'Month/Weeks.php'; include_once CALENDAR_ROOT.'Month/Weeks.php';
$class = 'Calendar_Month_Weeks'; $class = 'Calendar_Month_Weeks';
break; break;
case CALENDAR_USE_MONTH: case CALENDAR_USE_MONTH:
default:
require_once CALENDAR_ROOT.'Month.php';
$class = 'Calendar_Month';
break;
}
return new $class($y, $m, $firstDay);
case 'Week':
require_once CALENDAR_ROOT.'Week.php';
return new Calendar_Week($y, $m, $d, $firstDay);
case 'Hour':
require_once CALENDAR_ROOT.'Hour.php';
return new Calendar_Hour($y, $m, $d, $h);
case 'Minute':
require_once CALENDAR_ROOT.'Minute.php';
return new Calendar_Minute($y, $m, $d, $h, $i);
case 'Second':
require_once CALENDAR_ROOT.'Second.php';
return new Calendar_Second($y,$m,$d,$h,$i,$s);
case 'Year':
require_once CALENDAR_ROOT.'Year.php';
return new Calendar_Year($y);
default: default:
require_once 'PEAR.php'; include_once CALENDAR_ROOT.'Month.php';
PEAR::raiseError( $class = 'Calendar_Month';
'Calendar_Factory::create() unrecognised type: '.$type, null, PEAR_ERROR_TRIGGER, break;
E_USER_NOTICE, 'Calendar_Factory::create()'); }
return false; return new $class($y, $m, $firstDay);
case 'Week':
include_once CALENDAR_ROOT.'Week.php';
return new Calendar_Week($y, $m, $d, $firstDay);
case 'Hour':
include_once CALENDAR_ROOT.'Hour.php';
return new Calendar_Hour($y, $m, $d, $h);
case 'Minute':
include_once CALENDAR_ROOT.'Minute.php';
return new Calendar_Minute($y, $m, $d, $h, $i);
case 'Second':
include_once CALENDAR_ROOT.'Second.php';
return new Calendar_Second($y, $m, $d, $h, $i, $s);
case 'Year':
include_once CALENDAR_ROOT.'Year.php';
return new Calendar_Year($y);
default:
include_once 'PEAR.php';
PEAR::raiseError('Calendar_Factory::create() unrecognised type: '.$type,
null, PEAR_ERROR_TRIGGER, E_USER_NOTICE, 'Calendar_Factory::create()');
return false;
} }
} }
/** /**
* Creates an instance of a calendar object, given a type and timestamp * Creates an instance of a calendar object, given a type and timestamp
* @param string type of object to create *
* @param mixed timestamp (depending on Calendar engine being used) * @param string $type type of object to create
* @param mixed $stamp timestamp (depending on Calendar engine being used)
*
* @return object subclass of Calendar * @return object subclass of Calendar
* @access public * @access public
* @static * @static
*/ */
function & createByTimestamp($type, $stamp) static function & createByTimestamp($type, $stamp)
{ {
$cE = & Calendar_Engine_Factory::getEngine(); $cE = & Calendar_Engine_Factory::getEngine();
$y = $cE->stampToYear($stamp); $y = $cE->stampToYear($stamp);
$m = $cE->stampToMonth($stamp); $m = $cE->stampToMonth($stamp);
$d = $cE->stampToDay($stamp); $d = $cE->stampToDay($stamp);
$h = $cE->stampToHour($stamp); $h = $cE->stampToHour($stamp);
$i = $cE->stampToMinute($stamp); $i = $cE->stampToMinute($stamp);
$s = $cE->stampToSecond($stamp); $s = $cE->stampToSecond($stamp);
$cal = Calendar_Factory::create($type, $y, $m, $d, $h, $i, $s); $cal = Calendar_Factory::create($type, $y, $m, $d, $h, $i, $s);
return $cal; return $cal;
} }

View File

@@ -1,27 +1,39 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// +----------------------------------------------------------------------+
//
// $Id: Hour.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Hour class
* @version $Id: Hour.php,v 1.1 2004/05/24 22:25:42 quipo Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Hour.php 300729 2010-06-24 12:05:53Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
@@ -41,43 +53,53 @@ require_once CALENDAR_ROOT.'Calendar.php';
* Represents an Hour and builds Minutes * Represents an Hour and builds Minutes
* <code> * <code>
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Hour.php'; * require_once 'Calendar'.DIRECTORY_SEPARATOR.'Hour.php';
* $Hour = & new Calendar_Hour(2003, 10, 21, 15); // Oct 21st 2003, 3pm * $Hour = new Calendar_Hour(2003, 10, 21, 15); // Oct 21st 2003, 3pm
* $Hour->build(); // Build Calendar_Minute objects * $Hour->build(); // Build Calendar_Minute objects
* while ($Minute = & $Hour->fetch()) { * while ($Minute = & $Hour->fetch()) {
* echo $Minute->thisMinute().'<br />'; * echo $Minute->thisMinute().'<br />';
* } * }
* </code> * </code>
* @package Calendar *
* @access public * @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @access public
*/ */
class Calendar_Hour extends Calendar class Calendar_Hour extends Calendar
{ {
/** /**
* Constructs Calendar_Hour * Constructs Calendar_Hour
* @param int year e.g. 2003 *
* @param int month e.g. 5 * @param int $y year e.g. 2003
* @param int day e.g. 11 * @param int $m month e.g. 5
* @param int hour e.g. 13 * @param int $d day e.g. 11
* @param int $h hour e.g. 13
*
* @access public * @access public
*/ */
function Calendar_Hour($y, $m, $d, $h) function Calendar_Hour($y, $m, $d, $h)
{ {
Calendar::Calendar($y, $m, $d, $h); parent::Calendar($y, $m, $d, $h);
} }
/** /**
* Builds the Minutes in the Hour * Builds the Minutes in the Hour
* @param array (optional) Calendar_Minute objects representing selected dates *
* @param array $sDates (optional) Calendar_Minute objects representing selected dates
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
function build($sDates=array()) function build($sDates = array())
{ {
require_once CALENDAR_ROOT.'Minute.php'; include_once CALENDAR_ROOT.'Minute.php';
$mIH = $this->cE->getMinutesInHour($this->year, $this->month, $this->day, $mIH = $this->cE->getMinutesInHour($this->year, $this->month, $this->day,
$this->hour); $this->hour);
for ($i=0; $i < $mIH; $i++) { for ($i=0; $i < $mIH; $i++) {
$this->children[$i]= $this->children[$i] =
new Calendar_Minute($this->year, $this->month, $this->day, new Calendar_Minute($this->year, $this->month, $this->day,
$this->hour, $i); $this->hour, $i);
} }
@@ -89,7 +111,9 @@ class Calendar_Hour extends Calendar
/** /**
* Called from build() * Called from build()
* @param array *
* @param array $sDates Calendar_Minute objects representing selected dates
*
* @return void * @return void
* @access private * @access private
*/ */

View File

@@ -1,27 +1,39 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// +----------------------------------------------------------------------+
//
// $Id: Minute.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Minute class
* @version $Id: Minute.php,v 1.1 2004/05/24 22:25:42 quipo Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Minute.php 300729 2010-06-24 12:05:53Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
@@ -41,40 +53,50 @@ require_once CALENDAR_ROOT.'Calendar.php';
* Represents a Minute and builds Seconds * Represents a Minute and builds Seconds
* <code> * <code>
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Minute.php'; * require_once 'Calendar'.DIRECTORY_SEPARATOR.'Minute.php';
* $Minute = & new Calendar_Minute(2003, 10, 21, 15, 31); // Oct 21st 2003, 3:31pm * $Minute = new Calendar_Minute(2003, 10, 21, 15, 31); // Oct 21st 2003, 3:31pm
* $Minute->build(); // Build Calendar_Second objects * $Minute->build(); // Build Calendar_Second objects
* while ($Second = & $Minute->fetch()) { * while ($Second = & $Minute->fetch()) {
* echo $Second->thisSecond().'<br />'; * echo $Second->thisSecond().'<br />';
* } * }
* </code> * </code>
* @package Calendar *
* @access public * @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @access public
*/ */
class Calendar_Minute extends Calendar class Calendar_Minute extends Calendar
{ {
/** /**
* Constructs Minute * Constructs Minute
* @param int year e.g. 2003 *
* @param int month e.g. 5 * @param int $y year e.g. 2003
* @param int day e.g. 11 * @param int $m month e.g. 5
* @param int hour e.g. 13 * @param int $d day e.g. 11
* @param int minute e.g. 31 * @param int $h hour e.g. 13
* @param int $i minute e.g. 31
*
* @access public * @access public
*/ */
function Calendar_Minute($y, $m, $d, $h, $i) function Calendar_Minute($y, $m, $d, $h, $i)
{ {
Calendar::Calendar($y, $m, $d, $h, $i); parent::Calendar($y, $m, $d, $h, $i);
} }
/** /**
* Builds the Calendar_Second objects * Builds the Calendar_Second objects
* @param array (optional) Calendar_Second objects representing selected dates *
* @param array $sDates (optional) Calendar_Second objects representing selected dates
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
function build($sDates=array()) function build($sDates = array())
{ {
require_once CALENDAR_ROOT.'Second.php'; include_once CALENDAR_ROOT.'Second.php';
$sIM = $this->cE->getSecondsInMinute($this->year, $this->month, $sIM = $this->cE->getSecondsInMinute($this->year, $this->month,
$this->day, $this->hour, $this->minute); $this->day, $this->hour, $this->minute);
for ($i=0; $i < $sIM; $i++) { for ($i=0; $i < $sIM; $i++) {
@@ -89,7 +111,9 @@ class Calendar_Minute extends Calendar
/** /**
* Called from build() * Called from build()
* @param array *
* @param array $sDates Calendar_Second objects representing selected dates
*
* @return void * @return void
* @access private * @access private
*/ */

View File

@@ -1,27 +1,39 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// +----------------------------------------------------------------------+
//
// $Id: Month.php,v 1.3 2005/10/22 10:10:26 quipo Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Month class
* @version $Id: Month.php,v 1.3 2005/10/22 10:10:26 quipo Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Month.php 300729 2010-06-24 12:05:53Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
@@ -41,40 +53,50 @@ require_once CALENDAR_ROOT.'Calendar.php';
* Represents a Month and builds Days * Represents a Month and builds Days
* <code> * <code>
* require_once 'Calendar/Month.php'; * require_once 'Calendar/Month.php';
* $Month = & new Calendar_Month(2003, 10); // Oct 2003 * $Month = new Calendar_Month(2003, 10); // Oct 2003
* $Month->build(); // Build Calendar_Day objects * $Month->build(); // Build Calendar_Day objects
* while ($Day = & $Month->fetch()) { * while ($Day = & $Month->fetch()) {
* echo $Day->thisDay().'<br />'; * echo $Day->thisDay().'<br />';
* } * }
* </code> * </code>
* @package Calendar *
* @access public * @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @access public
*/ */
class Calendar_Month extends Calendar class Calendar_Month extends Calendar
{ {
/** /**
* Constructs Calendar_Month * Constructs Calendar_Month
* @param int $y year e.g. 2003 *
* @param int $m month e.g. 5 * @param int $y year e.g. 2003
* @param int $m month e.g. 5
* @param int $firstDay first day of the week [optional] * @param int $firstDay first day of the week [optional]
*
* @access public * @access public
*/ */
function Calendar_Month($y, $m, $firstDay=null) function Calendar_Month($y, $m, $firstDay=null)
{ {
Calendar::Calendar($y, $m); parent::Calendar($y, $m);
$this->firstDay = $this->defineFirstDayOfWeek($firstDay); $this->firstDay = $this->defineFirstDayOfWeek($firstDay);
} }
/** /**
* Builds Day objects for this Month. Creates as many Calendar_Day objects * Builds Day objects for this Month. Creates as many Calendar_Day objects
* as there are days in the month * as there are days in the month
* @param array (optional) Calendar_Day objects representing selected dates *
* @param array $sDates (optional) Calendar_Day objects representing selected dates
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
function build($sDates=array()) function build($sDates = array())
{ {
require_once CALENDAR_ROOT.'Day.php'; include_once CALENDAR_ROOT.'Day.php';
$daysInMonth = $this->cE->getDaysInMonth($this->year, $this->month); $daysInMonth = $this->cE->getDaysInMonth($this->year, $this->month);
for ($i=1; $i<=$daysInMonth; $i++) { for ($i=1; $i<=$daysInMonth; $i++) {
$this->children[$i] = new Calendar_Day($this->year, $this->month, $i); $this->children[$i] = new Calendar_Day($this->year, $this->month, $i);
@@ -87,7 +109,9 @@ class Calendar_Month extends Calendar
/** /**
* Called from build() * Called from build()
* @param array *
* @param array $sDates Calendar_Day objects representing selected dates
*
* @return void * @return void
* @access private * @access private
*/ */

View File

@@ -1,27 +1,39 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// +----------------------------------------------------------------------+
//
// $Id: Weekdays.php,v 1.4 2005/10/22 10:28:49 quipo Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Month_Weekdays class
* @version $Id: Weekdays.php,v 1.4 2005/10/22 10:28:49 quipo Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Weekdays.php 300729 2010-06-24 12:05:53Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
@@ -46,7 +58,7 @@ require_once CALENDAR_ROOT.'Month.php';
* Represents a Month and builds Days in tabular form<br> * Represents a Month and builds Days in tabular form<br>
* <code> * <code>
* require_once 'Calendar/Month/Weekdays.php'; * require_once 'Calendar/Month/Weekdays.php';
* $Month = & new Calendar_Month_Weekdays(2003, 10); // Oct 2003 * $Month = new Calendar_Month_Weekdays(2003, 10); // Oct 2003
* $Month->build(); // Build Calendar_Day objects * $Month->build(); // Build Calendar_Day objects
* while ($Day = & $Month->fetch()) { * while ($Day = & $Month->fetch()) {
* if ($Day->isFirst()) { * if ($Day->isFirst()) {
@@ -62,8 +74,14 @@ require_once CALENDAR_ROOT.'Month.php';
* } * }
* } * }
* </code> * </code>
* @package Calendar *
* @access public * @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @access public
*/ */
class Calendar_Month_Weekdays extends Calendar_Month class Calendar_Month_Weekdays extends Calendar_Month
{ {
@@ -83,31 +101,35 @@ class Calendar_Month_Weekdays extends Calendar_Month
/** /**
* Constructs Calendar_Month_Weekdays * Constructs Calendar_Month_Weekdays
* @param int year e.g. 2003 *
* @param int month e.g. 5 * @param int $y year e.g. 2003
* @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.) * @param int $m month e.g. 5
* @param int $firstDay (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
*
* @access public * @access public
*/ */
function Calendar_Month_Weekdays($y, $m, $firstDay=null) function Calendar_Month_Weekdays($y, $m, $firstDay=null)
{ {
Calendar_Month::Calendar_Month($y, $m, $firstDay); parent::Calendar_Month($y, $m, $firstDay);
} }
/** /**
* Builds Day objects in tabular form, to allow display of calendar month * Builds Day objects in tabular form, to allow display of calendar month
* with empty cells if the first day of the week does not fall on the first * with empty cells if the first day of the week does not fall on the first
* day of the month. * day of the month.
*
* @param array $sDates (optional) Calendar_Day objects representing selected dates
*
* @return boolean
* @access public
* @see Calendar_Day::isEmpty() * @see Calendar_Day::isEmpty()
* @see Calendar_Day_Base::isFirst() * @see Calendar_Day_Base::isFirst()
* @see Calendar_Day_Base::isLast() * @see Calendar_Day_Base::isLast()
* @param array (optional) Calendar_Day objects representing selected dates
* @return boolean
* @access public
*/ */
function build($sDates=array()) function build($sDates = array())
{ {
require_once CALENDAR_ROOT.'Table/Helper.php'; include_once CALENDAR_ROOT.'Table/Helper.php';
$this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay); $this->tableHelper = new Calendar_Table_Helper($this, $this->firstDay);
Calendar_Month::build($sDates); Calendar_Month::build($sDates);
$this->buildEmptyDaysBefore(); $this->buildEmptyDaysBefore();
$this->shiftDays(); $this->shiftDays();
@@ -118,6 +140,7 @@ class Calendar_Month_Weekdays extends Calendar_Month
/** /**
* Prepends empty days before the real days in the month * Prepends empty days before the real days in the month
*
* @return void * @return void
* @access private * @access private
*/ */
@@ -138,12 +161,13 @@ class Calendar_Month_Weekdays extends Calendar_Month
/** /**
* Shifts the array of children forward, if necessary * Shifts the array of children forward, if necessary
*
* @return void * @return void
* @access private * @access private
*/ */
function shiftDays() function shiftDays()
{ {
if (isset ($this->children[0])) { if (isset($this->children[0])) {
array_unshift($this->children, null); array_unshift($this->children, null);
unset($this->children[0]); unset($this->children[0]);
} }
@@ -151,14 +175,15 @@ class Calendar_Month_Weekdays extends Calendar_Month
/** /**
* Appends empty days after the real days in the month * Appends empty days after the real days in the month
*
* @return void * @return void
* @access private * @access private
*/ */
function buildEmptyDaysAfter() function buildEmptyDaysAfter()
{ {
$eAfter = $this->tableHelper->getEmptyDaysAfter(); $eAfter = $this->tableHelper->getEmptyDaysAfter();
$sDOM = $this->tableHelper->getNumTableDaysInMonth(); $sDOM = $this->tableHelper->getNumTableDaysInMonth();
for ($i = 1; $i <= $sDOM-$eAfter; $i++) { for ($i=1; $i <= $sDOM-$eAfter; $i++) {
$Day = new Calendar_Day($this->year, $this->month+1, $i); $Day = new Calendar_Day($this->year, $this->month+1, $i);
$Day->setEmpty(); $Day->setEmpty();
$Day->adjust(); $Day->adjust();
@@ -169,12 +194,13 @@ class Calendar_Month_Weekdays extends Calendar_Month
/** /**
* Sets the "markers" for the beginning and of a of week, in the * Sets the "markers" for the beginning and of a of week, in the
* built Calendar_Day children * built Calendar_Day children
*
* @return void * @return void
* @access private * @access private
*/ */
function setWeekMarkers() function setWeekMarkers()
{ {
$dIW = $this->cE->getDaysInWeek( $dIW = $this->cE->getDaysInWeek(
$this->thisYear(), $this->thisYear(),
$this->thisMonth(), $this->thisMonth(),
$this->thisDay() $this->thisDay()

View File

@@ -1,28 +1,40 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
// +----------------------------------------------------------------------+
//
// $Id: Weeks.php,v 1.3 2005/10/22 10:28:49 quipo Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Month_Weeks class
* @version $Id: Weeks.php,v 1.3 2005/10/22 10:28:49 quipo Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Weeks.php 300729 2010-06-24 12:05:53Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
@@ -47,14 +59,21 @@ require_once CALENDAR_ROOT.'Month.php';
* Represents a Month and builds Weeks * Represents a Month and builds Weeks
* <code> * <code>
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Month'.DIRECTORY_SEPARATOR.'Weeks.php'; * require_once 'Calendar'.DIRECTORY_SEPARATOR.'Month'.DIRECTORY_SEPARATOR.'Weeks.php';
* $Month = & new Calendar_Month_Weeks(2003, 10); // Oct 2003 * $Month = new Calendar_Month_Weeks(2003, 10); // Oct 2003
* $Month->build(); // Build Calendar_Day objects * $Month->build(); // Build Calendar_Day objects
* while ($Week = & $Month->fetch()) { * while ($Week = & $Month->fetch()) {
* echo $Week->thisWeek().'<br />'; * echo $Week->thisWeek().'<br />';
* } * }
* </code> * </code>
* @package Calendar *
* @access public * @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @access public
*/ */
class Calendar_Month_Weeks extends Calendar_Month class Calendar_Month_Weeks extends Calendar_Month
{ {
@@ -74,34 +93,40 @@ class Calendar_Month_Weeks extends Calendar_Month
/** /**
* Constructs Calendar_Month_Weeks * Constructs Calendar_Month_Weeks
* @param int year e.g. 2003 *
* @param int month e.g. 5 * @param int $y year e.g. 2003
* @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.) * @param int $m month e.g. 5
* @param int $firstDay (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
*
* @access public * @access public
*/ */
function Calendar_Month_Weeks($y, $m, $firstDay=null) function Calendar_Month_Weeks($y, $m, $firstDay=null)
{ {
Calendar_Month::Calendar_Month($y, $m, $firstDay); parent::Calendar_Month($y, $m, $firstDay);
} }
/** /**
* Builds Calendar_Week objects for the Month. Note that Calendar_Week * Builds Calendar_Week objects for the Month. Note that Calendar_Week
* builds Calendar_Day object in tabular form (with Calendar_Day->empty) * builds Calendar_Day object in tabular form (with Calendar_Day->empty)
* @param array (optional) Calendar_Week objects representing selected dates *
* @param array $sDates (optional) Calendar_Week objects representing selected dates
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
function build($sDates=array()) function build($sDates = array())
{ {
require_once CALENDAR_ROOT.'Table/Helper.php'; include_once CALENDAR_ROOT.'Table/Helper.php';
$this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay); $this->tableHelper = new Calendar_Table_Helper($this, $this->firstDay);
require_once CALENDAR_ROOT.'Week.php'; include_once CALENDAR_ROOT.'Week.php';
$numWeeks = $this->tableHelper->getNumWeeks(); $numWeeks = $this->tableHelper->getNumWeeks();
for ($i=1, $d=1; $i<=$numWeeks; $i++, for ($i=1, $d=1; $i<=$numWeeks; $i++,
$d+=$this->cE->getDaysInWeek( $d+=$this->cE->getDaysInWeek(
$this->thisYear(), $this->thisYear(),
$this->thisMonth(), $this->thisMonth(),
$this->thisDay()) ) { $this->thisDay()
)
) {
$this->children[$i] = new Calendar_Week( $this->children[$i] = new Calendar_Week(
$this->year, $this->month, $d, $this->tableHelper->getFirstDay()); $this->year, $this->month, $d, $this->tableHelper->getFirstDay());
} }
@@ -118,7 +143,9 @@ class Calendar_Month_Weeks extends Calendar_Month
/** /**
* Called from build() * Called from build()
* @param array *
* @param array $sDates Calendar_Week objects representing selected dates
*
* @return void * @return void
* @access private * @access private
*/ */

View File

@@ -1,27 +1,39 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// +----------------------------------------------------------------------+
//
// $Id: Second.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Second class
* @version $Id: Second.php,v 1.1 2004/05/24 22:25:42 quipo Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Second.php 300728 2010-06-24 11:43:56Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
@@ -41,26 +53,35 @@ require_once CALENDAR_ROOT.'Calendar.php';
* Represents a Second<br /> * Represents a Second<br />
* <b>Note:</b> Seconds do not build other objects * <b>Note:</b> Seconds do not build other objects
* so related methods are overridden to return NULL * so related methods are overridden to return NULL
* @package Calendar *
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @access public
*/ */
class Calendar_Second extends Calendar class Calendar_Second extends Calendar
{ {
/** /**
* Constructs Second * Constructs Second
* @param int year e.g. 2003 *
* @param int month e.g. 5 * @param int $y year e.g. 2003
* @param int day e.g. 11 * @param int $m month e.g. 5
* @param int hour e.g. 13 * @param int $d day e.g. 11
* @param int minute e.g. 31 * @param int $h hour e.g. 13
* @param int second e.g. 45 * @param int $i minute e.g. 31
* @param int $s second e.g. 45
*/ */
function Calendar_Second($y, $m, $d, $h, $i, $s) function Calendar_Second($y, $m, $d, $h, $i, $s)
{ {
Calendar::Calendar($y, $m, $d, $h, $i, $s); parent::Calendar($y, $m, $d, $h, $i, $s);
} }
/** /**
* Overwrite build * Overwrite build
*
* @return NULL * @return NULL
*/ */
function build() function build()
@@ -70,6 +91,7 @@ class Calendar_Second extends Calendar
/** /**
* Overwrite fetch * Overwrite fetch
*
* @return NULL * @return NULL
*/ */
function fetch() function fetch()
@@ -79,6 +101,7 @@ class Calendar_Second extends Calendar
/** /**
* Overwrite fetchAll * Overwrite fetchAll
*
* @return NULL * @return NULL
*/ */
function fetchAll() function fetchAll()
@@ -88,6 +111,7 @@ class Calendar_Second extends Calendar
/** /**
* Overwrite size * Overwrite size
*
* @return NULL * @return NULL
*/ */
function size() function size()

View File

@@ -1,34 +1,52 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// +----------------------------------------------------------------------+
//
// $Id: Helper.php,v 1.5 2005/10/22 09:51:53 quipo Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Decorator_Wrapper class
* @version $Id: Helper.php,v 1.5 2005/10/22 09:51:53 quipo Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Helper.php 246317 2007-11-16 20:05:32Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
* Used by Calendar_Month_Weekdays, Calendar_Month_Weeks and Calendar_Week to * Used by Calendar_Month_Weekdays, Calendar_Month_Weeks and Calendar_Week to
* help with building the calendar in tabular form * help with building the calendar in tabular form
* @package Calendar *
* @access protected * @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @access public
*/ */
class Calendar_Table_Helper class Calendar_Table_Helper
{ {
@@ -90,8 +108,10 @@ class Calendar_Table_Helper
/** /**
* Constructs Calendar_Table_Helper * Constructs Calendar_Table_Helper
* @param object Calendar_Month_Weekdays, Calendar_Month_Weeks, Calendar_Week *
* @param int (optional) first day of the week e.g. 1 for Monday * @param object &$calendar Calendar_Month_Weekdays, Calendar_Month_Weeks, Calendar_Week
* @param int $firstDay (optional) first day of the week e.g. 1 for Monday
*
* @access protected * @access protected
*/ */
function Calendar_Table_Helper(& $calendar, $firstDay=null) function Calendar_Table_Helper(& $calendar, $firstDay=null)
@@ -112,6 +132,7 @@ class Calendar_Table_Helper
/** /**
* Constructs $this->daysOfWeek based on $this->firstDay * Constructs $this->daysOfWeek based on $this->firstDay
*
* @return void * @return void
* @access private * @access private
*/ */
@@ -140,6 +161,7 @@ class Calendar_Table_Helper
/** /**
* Constructs $this->daysOfMonth * Constructs $this->daysOfMonth
*
* @return void * @return void
* @access private * @access private
*/ */
@@ -174,9 +196,10 @@ class Calendar_Table_Helper
/** /**
* Returns the first day of the month * Returns the first day of the month
* @see Calendar_Engine_Interface::getFirstDayOfWeek() *
* @return int * @return int
* @access protected * @access protected
* @see Calendar_Engine_Interface::getFirstDayOfWeek()
*/ */
function getFirstDay() function getFirstDay()
{ {
@@ -185,6 +208,7 @@ class Calendar_Table_Helper
/** /**
* Returns the order array of days in a week * Returns the order array of days in a week
*
* @return int * @return int
* @access protected * @access protected
*/ */
@@ -195,6 +219,7 @@ class Calendar_Table_Helper
/** /**
* Returns the number of tabular weeks in a month * Returns the number of tabular weeks in a month
*
* @return int * @return int
* @access protected * @access protected
*/ */
@@ -205,6 +230,7 @@ class Calendar_Table_Helper
/** /**
* Returns the number of real days + empty days * Returns the number of real days + empty days
*
* @return int * @return int
* @access protected * @access protected
*/ */
@@ -215,6 +241,7 @@ class Calendar_Table_Helper
/** /**
* Returns the number of empty days before the real days begin * Returns the number of empty days before the real days begin
*
* @return int * @return int
* @access protected * @access protected
*/ */
@@ -225,6 +252,7 @@ class Calendar_Table_Helper
/** /**
* Returns the index of the last real day in the month * Returns the index of the last real day in the month
*
* @todo Potential performance optimization with static * @todo Potential performance optimization with static
* @return int * @return int
* @access protected * @access protected
@@ -232,17 +260,18 @@ class Calendar_Table_Helper
function getEmptyDaysAfter() function getEmptyDaysAfter()
{ {
// Causes bug when displaying more than one month // Causes bug when displaying more than one month
// static $index; //static $index;
// if (!isset($index)) { //if (!isset($index)) {
$index = $this->getEmptyDaysBefore() + $this->cE->getDaysInMonth( $index = $this->getEmptyDaysBefore() + $this->cE->getDaysInMonth(
$this->calendar->thisYear(), $this->calendar->thisMonth()); $this->calendar->thisYear(), $this->calendar->thisMonth());
// } //}
return $index; return $index;
} }
/** /**
* Returns the index of the last real day in the month, relative to the * Returns the index of the last real day in the month, relative to the
* beginning of the tabular week it is part of * beginning of the tabular week it is part of
*
* @return int * @return int
* @access protected * @access protected
*/ */
@@ -254,11 +283,18 @@ class Calendar_Table_Helper
$this->calendar->thisYear(), $this->calendar->thisYear(),
$this->calendar->thisMonth(), $this->calendar->thisMonth(),
$this->calendar->thisDay() $this->calendar->thisDay()
) * ($this->numWeeks-1) ); ) * ($this->numWeeks-1));
} }
/** /**
* Returns the timestamp of the first day of the current week * Returns the timestamp of the first day of the current week
*
* @param int $y year
* @param int $m month
* @param int $d day
* @param int $firstDay first day of the week (default 1 = Monday)
*
* @return int timestamp
*/ */
function getWeekStart($y, $m, $d, $firstDay=1) function getWeekStart($y, $m, $d, $firstDay=1)
{ {

View File

@@ -1,28 +1,45 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+ /**
// | PHP Version 4 | * Contains the Calendar_Util_Textual class
// +----------------------------------------------------------------------+ *
// | Copyright (c) 1997-2002 The PHP Group | * PHP versions 4 and 5
// +----------------------------------------------------------------------+ *
// | This source file is subject to version 2.02 of the PHP license, | * LICENSE: Redistribution and use in source and binary forms, with or without
// | that is bundled with this package in the file LICENSE, and is | * modification, are permitted provided that the following conditions are met:
// | available at through the world-wide-web at | * 1. Redistributions of source code must retain the above copyright
// | http://www.php.net/license/3_0.txt. | * notice, this list of conditions and the following disclaimer.
// | If you did not receive a copy of the PHP license and are unable to | * 2. Redistributions in binary form must reproduce the above copyright
// | obtain it through the world-wide-web, please send a note to | * notice, this list of conditions and the following disclaimer in the
// | license@php.net so we can mail you a copy immediately. | * documentation and/or other materials provided with the distribution.
// +----------------------------------------------------------------------+ * 3. The name of the author may not be used to endorse or promote products
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> | * derived from this software without specific prior written permission.
// | Lorenzo Alberton <l dot alberton at quipo dot it> | *
// +----------------------------------------------------------------------+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
// * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// $Id: Textual.php,v 1.2 2004/08/16 13:13:09 hfuecks Exp $ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Textual.php 247250 2007-11-28 19:42:01Z quipo $
* @link http://pear.php.net/package/Calendar
*/
/** /**
* @package Calendar * @package Calendar
* @version $Id: Textual.php,v 1.2 2004/08/16 13:13:09 hfuecks Exp $ * @version $Id: Textual.php 247250 2007-11-28 19:42:01Z quipo $
*/ */
/** /**
@@ -41,23 +58,37 @@ require_once CALENDAR_ROOT.'Decorator.php';
/** /**
* Static utlities to help with fetching textual representations of months and * Static utlities to help with fetching textual representations of months and
* days of the week. * days of the week.
* @package Calendar *
* @access public * @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @access public
*/ */
class Calendar_Util_Textual class Calendar_Util_Textual
{ {
/** /**
* Returns an array of 12 month names (first index = 1) * Returns an array of 12 month names (first index = 1)
* @param string (optional) format of returned months (one,two,short or long) *
* @param string $format (optional) format of returned months (one|two|short|long)
*
* @return array * @return array
* @access public * @access public
* @static * @static
*/ */
function monthNames($format='long') function monthNames($format = 'long')
{ {
$formats = array('one'=>'%b', 'two'=>'%b', 'short'=>'%b', 'long'=>'%B'); $formats = array(
if (!array_key_exists($format,$formats)) { 'one' => '%b',
'two' => '%b',
'short' => '%b',
'long' => '%B',
);
if (!array_key_exists($format, $formats)) {
$format = 'long'; $format = 'long';
} }
$months = array(); $months = array();
@@ -65,11 +96,11 @@ class Calendar_Util_Textual
$stamp = mktime(0, 0, 0, $i, 1, 2003); $stamp = mktime(0, 0, 0, $i, 1, 2003);
$month = strftime($formats[$format], $stamp); $month = strftime($formats[$format], $stamp);
switch($format) { switch($format) {
case 'one': case 'one':
$month = substr($month, 0, 1); $month = substr($month, 0, 1);
break; break;
case 'two': case 'two':
$month = substr($month, 0, 2); $month = substr($month, 0, 2);
break; break;
} }
$months[$i] = $month; $months[$i] = $month;
@@ -79,15 +110,22 @@ class Calendar_Util_Textual
/** /**
* Returns an array of 7 week day names (first index = 0) * Returns an array of 7 week day names (first index = 0)
* @param string (optional) format of returned days (one,two,short or long) *
* @param string $format (optional) format of returned days (one,two,short or long)
*
* @return array * @return array
* @access public * @access public
* @static * @static
*/ */
function weekdayNames($format='long') function weekdayNames($format = 'long')
{ {
$formats = array('one'=>'%a', 'two'=>'%a', 'short'=>'%a', 'long'=>'%A'); $formats = array(
if (!array_key_exists($format,$formats)) { 'one' => '%a',
'two' => '%a',
'short' => '%a',
'long' => '%A',
);
if (!array_key_exists($format, $formats)) {
$format = 'long'; $format = 'long';
} }
$days = array(); $days = array();
@@ -95,11 +133,11 @@ class Calendar_Util_Textual
$stamp = mktime(0, 0, 0, 11, $i+2, 2003); $stamp = mktime(0, 0, 0, 11, $i+2, 2003);
$day = strftime($formats[$format], $stamp); $day = strftime($formats[$format], $stamp);
switch($format) { switch($format) {
case 'one': case 'one':
$day = substr($day, 0, 1); $day = substr($day, 0, 1);
break; break;
case 'two': case 'two':
$day = substr($day, 0, 2); $day = substr($day, 0, 2);
break; break;
} }
$days[$i] = $day; $days[$i] = $day;
@@ -109,13 +147,15 @@ class Calendar_Util_Textual
/** /**
* Returns textual representation of the previous month of the decorated calendar object * Returns textual representation of the previous month of the decorated calendar object
* @param object subclass of Calendar e.g. Calendar_Month *
* @param string (optional) format of returned months (one,two,short or long) * @param object $Calendar subclass of Calendar e.g. Calendar_Month
* @param string $format (optional) format of returned months (one,two,short or long)
*
* @return string * @return string
* @access public * @access public
* @static * @static
*/ */
function prevMonthName($Calendar, $format='long') function prevMonthName($Calendar, $format = 'long')
{ {
$months = Calendar_Util_Textual::monthNames($format); $months = Calendar_Util_Textual::monthNames($format);
return $months[$Calendar->prevMonth()]; return $months[$Calendar->prevMonth()];
@@ -123,13 +163,15 @@ class Calendar_Util_Textual
/** /**
* Returns textual representation of the month of the decorated calendar object * Returns textual representation of the month of the decorated calendar object
* @param object subclass of Calendar e.g. Calendar_Month *
* @param string (optional) format of returned months (one,two,short or long) * @param object $Calendar subclass of Calendar e.g. Calendar_Month
* @param string $format (optional) format of returned months (one,two,short or long)
*
* @return string * @return string
* @access public * @access public
* @static * @static
*/ */
function thisMonthName($Calendar, $format='long') function thisMonthName($Calendar, $format = 'long')
{ {
$months = Calendar_Util_Textual::monthNames($format); $months = Calendar_Util_Textual::monthNames($format);
return $months[$Calendar->thisMonth()]; return $months[$Calendar->thisMonth()];
@@ -137,13 +179,15 @@ class Calendar_Util_Textual
/** /**
* Returns textual representation of the next month of the decorated calendar object * Returns textual representation of the next month of the decorated calendar object
* @param object subclass of Calendar e.g. Calendar_Month *
* @param string (optional) format of returned months (one,two,short or long) * @param object $Calendar subclass of Calendar e.g. Calendar_Month
* @param string $format (optional) format of returned months (one,two,short or long)
*
* @return string * @return string
* @access public * @access public
* @static * @static
*/ */
function nextMonthName($Calendar, $format='long') function nextMonthName($Calendar, $format = 'long')
{ {
$months = Calendar_Util_Textual::monthNames($format); $months = Calendar_Util_Textual::monthNames($format);
return $months[$Calendar->nextMonth()]; return $months[$Calendar->nextMonth()];
@@ -152,18 +196,20 @@ class Calendar_Util_Textual
/** /**
* Returns textual representation of the previous day of week of the decorated calendar object * Returns textual representation of the previous day of week of the decorated calendar object
* <b>Note:</b> Requires PEAR::Date * <b>Note:</b> Requires PEAR::Date
* @param object subclass of Calendar e.g. Calendar_Month *
* @param string (optional) format of returned months (one,two,short or long) * @param object $Calendar subclass of Calendar e.g. Calendar_Month
* @param string $format (optional) format of returned months (one,two,short or long)
*
* @return string * @return string
* @access public * @access public
* @static * @static
*/ */
function prevDayName($Calendar, $format='long') function prevDayName($Calendar, $format = 'long')
{ {
$days = Calendar_Util_Textual::weekdayNames($format); $days = Calendar_Util_Textual::weekdayNames($format);
$stamp = $Calendar->prevDay('timestamp'); $stamp = $Calendar->prevDay('timestamp');
$cE = $Calendar->getEngine(); $cE = $Calendar->getEngine();
require_once 'Date/Calc.php'; include_once 'Date/Calc.php';
$day = Date_Calc::dayOfWeek($cE->stampToDay($stamp), $day = Date_Calc::dayOfWeek($cE->stampToDay($stamp),
$cE->stampToMonth($stamp), $cE->stampToYear($stamp)); $cE->stampToMonth($stamp), $cE->stampToYear($stamp));
return $days[$day]; return $days[$day];
@@ -172,8 +218,10 @@ class Calendar_Util_Textual
/** /**
* Returns textual representation of the day of week of the decorated calendar object * Returns textual representation of the day of week of the decorated calendar object
* <b>Note:</b> Requires PEAR::Date * <b>Note:</b> Requires PEAR::Date
* @param object subclass of Calendar e.g. Calendar_Month *
* @param string (optional) format of returned months (one,two,short or long) * @param object $Calendar subclass of Calendar e.g. Calendar_Month
* @param string $format (optional) format of returned months (one,two,short or long)
*
* @return string * @return string
* @access public * @access public
* @static * @static
@@ -181,15 +229,17 @@ class Calendar_Util_Textual
function thisDayName($Calendar, $format='long') function thisDayName($Calendar, $format='long')
{ {
$days = Calendar_Util_Textual::weekdayNames($format); $days = Calendar_Util_Textual::weekdayNames($format);
require_once 'Date/Calc.php'; include_once 'Date/Calc.php';
$day = Date_Calc::dayOfWeek($Calendar->thisDay(), $Calendar->thisMonth(), $Calendar->thisYear()); $day = Date_Calc::dayOfWeek($Calendar->thisDay(), $Calendar->thisMonth(), $Calendar->thisYear());
return $days[$day]; return $days[$day];
} }
/** /**
* Returns textual representation of the next day of week of the decorated calendar object * Returns textual representation of the next day of week of the decorated calendar object
* @param object subclass of Calendar e.g. Calendar_Month *
* @param string (optional) format of returned months (one,two,short or long) * @param object $Calendar subclass of Calendar e.g. Calendar_Month
* @param string $format (optional) format of returned months (one,two,short or long)
*
* @return string * @return string
* @access public * @access public
* @static * @static
@@ -199,7 +249,7 @@ class Calendar_Util_Textual
$days = Calendar_Util_Textual::weekdayNames($format); $days = Calendar_Util_Textual::weekdayNames($format);
$stamp = $Calendar->nextDay('timestamp'); $stamp = $Calendar->nextDay('timestamp');
$cE = $Calendar->getEngine(); $cE = $Calendar->getEngine();
require_once 'Date/Calc.php'; include_once 'Date/Calc.php';
$day = Date_Calc::dayOfWeek($cE->stampToDay($stamp), $day = Date_Calc::dayOfWeek($cE->stampToDay($stamp),
$cE->stampToMonth($stamp), $cE->stampToYear($stamp)); $cE->stampToMonth($stamp), $cE->stampToYear($stamp));
return $days[$day]; return $days[$day];
@@ -209,21 +259,36 @@ class Calendar_Util_Textual
* Returns the days of the week using the order defined in the decorated * Returns the days of the week using the order defined in the decorated
* calendar object. Only useful for Calendar_Month_Weekdays, Calendar_Month_Weeks * calendar object. Only useful for Calendar_Month_Weekdays, Calendar_Month_Weeks
* and Calendar_Week. Otherwise the returned array will begin on Sunday * and Calendar_Week. Otherwise the returned array will begin on Sunday
* @param object subclass of Calendar e.g. Calendar_Month *
* @param string (optional) format of returned months (one,two,short or long) * @param object $Calendar subclass of Calendar e.g. Calendar_Month
* @param string $format (optional) format of returned months (one,two,short or long)
*
* @return array ordered array of week day names * @return array ordered array of week day names
* @access public * @access public
* @static * @static
*/ */
function orderedWeekdays($Calendar, $format='long') function orderedWeekdays($Calendar, $format = 'long')
{ {
$days = Calendar_Util_Textual::weekdayNames($format); $days = Calendar_Util_Textual::weekdayNames($format);
// Not so good - need methods to access this information perhaps...
if (isset($Calendar->tableHelper)) { if (isset($Calendar->tableHelper)) {
$ordereddays = $Calendar->tableHelper->daysOfWeek; $ordereddays = $Calendar->tableHelper->getDaysOfWeek();
} else { } else {
$ordereddays = array(0, 1, 2, 3, 4, 5, 6); //default: start from Sunday
$firstDay = 0;
//check if defined / set
if (defined('CALENDAR_FIRST_DAY_OF_WEEK')) {
$firstDay = CALENDAR_FIRST_DAY_OF_WEEK;
} elseif(isset($Calendar->firstDay)) {
$firstDay = $Calendar->firstDay;
}
$ordereddays = array();
for ($i = $firstDay; $i < 7; $i++) {
$ordereddays[] = $i;
}
for ($i = 0; $i < $firstDay; $i++) {
$ordereddays[] = $i;
}
} }
$ordereddays = array_flip($ordereddays); $ordereddays = array_flip($ordereddays);

View File

@@ -1,35 +1,47 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
// +----------------------------------------------------------------------+
//
// $Id: Uri.php,v 1.1 2004/08/16 09:03:55 hfuecks Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Util_Uri class
* @version $Id: Uri.php,v 1.1 2004/08/16 09:03:55 hfuecks Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Uri.php 300729 2010-06-24 12:05:53Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
* Utility to help building HTML links for navigating the calendar<br /> * Utility to help building HTML links for navigating the calendar<br />
* <code> * <code>
* $Day = new Calendar_Day(2003, 10, 23); * $Day = new Calendar_Day(2003, 10, 23);
* $Uri = & new Calendar_Util_Uri('year', 'month', 'day'); * $Uri = new Calendar_Util_Uri('year', 'month', 'day');
* echo $Uri->prev($Day,'month'); // Displays year=2003&amp;month=10 * echo $Uri->prev($Day,'month'); // Displays year=2003&amp;month=10
* echo $Uri->prev($Day,'day'); // Displays year=2003&amp;month=10&amp;day=22 * echo $Uri->prev($Day,'day'); // Displays year=2003&amp;month=10&amp;day=22
* $Uri->seperator = '/'; * $Uri->seperator = '/';
@@ -37,8 +49,15 @@
* echo $Uri->prev($Day,'month'); // Displays 2003/10 * echo $Uri->prev($Day,'month'); // Displays 2003/10
* echo $Uri->prev($Day,'day'); // Displays 2003/10/22 * echo $Uri->prev($Day,'day'); // Displays 2003/10/22
* </code> * </code>
* @package Calendar *
* @access public * @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @access public
*/ */
class Calendar_Util_Uri class Calendar_Util_Uri
{ {
@@ -69,12 +88,14 @@ class Calendar_Util_Uri
/** /**
* Constructs Calendar_Decorator_Uri * Constructs Calendar_Decorator_Uri
* The term "fragment" means <i>name</i> of a calendar GET variables in the URL * The term "fragment" means <i>name</i> of a calendar GET variables in the URL
* @param string URI fragment for year *
* @param string (optional) URI fragment for month * @param string $y URI fragment for year
* @param string (optional) URI fragment for day * @param string $m (optional) URI fragment for month
* @param string (optional) URI fragment for hour * @param string $d (optional) URI fragment for day
* @param string (optional) URI fragment for minute * @param string $h (optional) URI fragment for hour
* @param string (optional) URI fragment for second * @param string $i (optional) URI fragment for minute
* @param string $s (optional) URI fragment for second
*
* @access public * @access public
*/ */
function Calendar_Util_Uri($y, $m=null, $d=null, $h=null, $i=null, $s=null) function Calendar_Util_Uri($y, $m=null, $d=null, $h=null, $i=null, $s=null)
@@ -84,16 +105,19 @@ class Calendar_Util_Uri
/** /**
* Sets the URI fragment names * Sets the URI fragment names
* @param string URI fragment for year *
* @param string (optional) URI fragment for month * @param string $y URI fragment for year
* @param string (optional) URI fragment for day * @param string $m (optional) URI fragment for month
* @param string (optional) URI fragment for hour * @param string $d (optional) URI fragment for day
* @param string (optional) URI fragment for minute * @param string $h (optional) URI fragment for hour
* @param string (optional) URI fragment for second * @param string $i (optional) URI fragment for minute
* @param string $s (optional) URI fragment for second
*
* @return void * @return void
* @access public * @access public
*/ */
function setFragments($y, $m=null, $d=null, $h=null, $i=null, $s=null) { function setFragments($y, $m=null, $d=null, $h=null, $i=null, $s=null)
{
if (!is_null($y)) $this->uris['Year'] = $y; if (!is_null($y)) $this->uris['Year'] = $y;
if (!is_null($m)) $this->uris['Month'] = $m; if (!is_null($m)) $this->uris['Month'] = $m;
if (!is_null($d)) $this->uris['Day'] = $d; if (!is_null($d)) $this->uris['Day'] = $d;
@@ -104,8 +128,10 @@ class Calendar_Util_Uri
/** /**
* Gets the URI string for the previous calendar unit * Gets the URI string for the previous calendar unit
* @param object subclassed from Calendar e.g. Calendar_Month *
* @param string calendar unit ( must be year, month, week, day, hour, minute or second) * @param object $Calendar subclassed from Calendar e.g. Calendar_Month
* @param string $unit calendar unit (year|month|week|day|hour|minute|second)
*
* @return string * @return string
* @access public * @access public
*/ */
@@ -118,22 +144,26 @@ class Calendar_Util_Uri
/** /**
* Gets the URI string for the current calendar unit * Gets the URI string for the current calendar unit
* @param object subclassed from Calendar e.g. Calendar_Month *
* @param string calendar unit ( must be year, month, week, day, hour, minute or second) * @param object $Calendar subclassed from Calendar e.g. Calendar_Month
* @param string $unit calendar unit (year|month|week|day|hour|minute|second)
*
* @return string * @return string
* @access public * @access public
*/ */
function this($Calendar, $unit) function this($Calendar, $unit)
{ {
$method = 'this'.$unit; $method = 'this'.$unit;
$stamp = $Calendar->{$method}('timestamp'); $stamp = $Calendar->{$method}('timestamp');
return $this->buildUriString($Calendar, $method, $stamp); return $this->buildUriString($Calendar, $method, $stamp);
} }
/** /**
* Gets the URI string for the next calendar unit * Gets the URI string for the next calendar unit
* @param object subclassed from Calendar e.g. Calendar_Month *
* @param string calendar unit ( must be year, month, week, day, hour, minute or second) * @param object $Calendar subclassed from Calendar e.g. Calendar_Month
* @param string $unit calendar unit (year|month|week|day|hour|minute|second)
*
* @return string * @return string
* @access public * @access public
*/ */
@@ -146,8 +176,11 @@ class Calendar_Util_Uri
/** /**
* Build the URI string * Build the URI string
* @param string method substring *
* @param int timestamp * @param object $Calendar subclassed from Calendar e.g. Calendar_Month
* @param string $method method substring
* @param int $stamp timestamp
*
* @return string build uri string * @return string build uri string
* @access private * @access private
*/ */
@@ -159,7 +192,9 @@ class Calendar_Util_Uri
foreach ($this->uris as $unit => $uri) { foreach ($this->uris as $unit => $uri) {
$call = 'stampTo'.$unit; $call = 'stampTo'.$unit;
$uriString .= $separator; $uriString .= $separator;
if (!$this->scalar) $uriString .= $uri.'='; if (!$this->scalar) {
$uriString .= $uri.'=';
}
$uriString .= $cE->{$call}($stamp); $uriString .= $cE->{$call}($stamp);
$separator = $this->separator; $separator = $this->separator;
} }

View File

@@ -1,27 +1,39 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// +----------------------------------------------------------------------+
//
// $Id: Validator.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Validator class
* @version $Id: Validator.php,v 1.1 2004/05/24 22:25:42 quipo Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Validator.php 247251 2007-11-28 19:42:33Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
@@ -37,9 +49,15 @@ if (!defined('CALENDAR_VALUE_TOOLARGE')) {
/** /**
* Used to validate any given Calendar date object. Instances of this class * Used to validate any given Calendar date object. Instances of this class
* can be obtained from any data object using the getValidator method * can be obtained from any data object using the getValidator method
* @see Calendar::getValidator() *
* @package Calendar * @category Date and Time
* @access public * @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @see Calendar::getValidator()
* @access public
*/ */
class Calendar_Validator class Calendar_Validator
{ {
@@ -66,17 +84,20 @@ class Calendar_Validator
/** /**
* Constructs Calendar_Validator * Constructs Calendar_Validator
* @param object subclass of Calendar *
* @param object &$calendar subclass of Calendar
*
* @access public * @access public
*/ */
function Calendar_Validator(& $calendar) function Calendar_Validator(&$calendar)
{ {
$this->calendar = & $calendar; $this->calendar = & $calendar;
$this->cE = & $calendar->getEngine(); $this->cE = & $calendar->getEngine();
} }
/** /**
* Calls all the other isValidXXX() methods in the validator * Calls all the other isValidXXX() methods in the validator
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
@@ -84,7 +105,7 @@ class Calendar_Validator
{ {
$checks = array('isValidYear', 'isValidMonth', 'isValidDay', $checks = array('isValidYear', 'isValidMonth', 'isValidDay',
'isValidHour', 'isValidMinute', 'isValidSecond'); 'isValidHour', 'isValidMinute', 'isValidSecond');
$valid = true; $valid = true;
foreach ($checks as $check) { foreach ($checks as $check) {
if (!$this->{$check}()) { if (!$this->{$check}()) {
$valid = false; $valid = false;
@@ -95,15 +116,16 @@ class Calendar_Validator
/** /**
* Check whether this is a valid year * Check whether this is a valid year
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
function isValidYear() function isValidYear()
{ {
$y = $this->calendar->thisYear(); $y = $this->calendar->thisYear();
$min = $this->cE->getMinYears(); $min = $this->cE->getMinYears();
if ($min > $y) { if ($min > $y) {
$this->errors[] = new Calendar_Validation_Error( $this->errors[] = new Calendar_Validation_Error(
'Year', $y, CALENDAR_VALUE_TOOSMALL.$min); 'Year', $y, CALENDAR_VALUE_TOOSMALL.$min);
return false; return false;
} }
@@ -118,12 +140,13 @@ class Calendar_Validator
/** /**
* Check whether this is a valid month * Check whether this is a valid month
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
function isValidMonth() function isValidMonth()
{ {
$m = $this->calendar->thisMonth(); $m = $this->calendar->thisMonth();
$min = 1; $min = 1;
if ($min > $m) { if ($min > $m) {
$this->errors[] = new Calendar_Validation_Error( $this->errors[] = new Calendar_Validation_Error(
@@ -141,12 +164,13 @@ class Calendar_Validator
/** /**
* Check whether this is a valid day * Check whether this is a valid day
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
function isValidDay() function isValidDay()
{ {
$d = $this->calendar->thisDay(); $d = $this->calendar->thisDay();
$min = 1; $min = 1;
if ($min > $d) { if ($min > $d) {
$this->errors[] = new Calendar_Validation_Error( $this->errors[] = new Calendar_Validation_Error(
@@ -154,7 +178,9 @@ class Calendar_Validator
return false; return false;
} }
$max = $this->cE->getDaysInMonth( $max = $this->cE->getDaysInMonth(
$this->calendar->thisYear(), $this->calendar->thisMonth()); $this->calendar->thisYear(),
$this->calendar->thisMonth()
);
if ($d > $max) { if ($d > $max) {
$this->errors[] = new Calendar_Validation_Error( $this->errors[] = new Calendar_Validation_Error(
'Day', $d, CALENDAR_VALUE_TOOLARGE.$max); 'Day', $d, CALENDAR_VALUE_TOOLARGE.$max);
@@ -165,12 +191,13 @@ class Calendar_Validator
/** /**
* Check whether this is a valid hour * Check whether this is a valid hour
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
function isValidHour() function isValidHour()
{ {
$h = $this->calendar->thisHour(); $h = $this->calendar->thisHour();
$min = 0; $min = 0;
if ($min > $h) { if ($min > $h) {
$this->errors[] = new Calendar_Validation_Error( $this->errors[] = new Calendar_Validation_Error(
@@ -188,12 +215,13 @@ class Calendar_Validator
/** /**
* Check whether this is a valid minute * Check whether this is a valid minute
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
function isValidMinute() function isValidMinute()
{ {
$i = $this->calendar->thisMinute(); $i = $this->calendar->thisMinute();
$min = 0; $min = 0;
if ($min > $i) { if ($min > $i) {
$this->errors[] = new Calendar_Validation_Error( $this->errors[] = new Calendar_Validation_Error(
@@ -211,12 +239,13 @@ class Calendar_Validator
/** /**
* Check whether this is a valid second * Check whether this is a valid second
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
function isValidSecond() function isValidSecond()
{ {
$s = $this->calendar->thisSecond(); $s = $this->calendar->thisSecond();
$min = 0; $min = 0;
if ($min > $s) { if ($min > $s) {
$this->errors[] = new Calendar_Validation_Error( $this->errors[] = new Calendar_Validation_Error(
@@ -234,12 +263,13 @@ class Calendar_Validator
/** /**
* Iterates over any validation errors * Iterates over any validation errors
*
* @return mixed either Calendar_Validation_Error or false * @return mixed either Calendar_Validation_Error or false
* @access public * @access public
*/ */
function fetch() function fetch()
{ {
$error = each ($this->errors); $error = each($this->errors);
if ($error) { if ($error) {
return $error['value']; return $error['value'];
} else { } else {
@@ -251,9 +281,15 @@ class Calendar_Validator
/** /**
* For Validation Error messages * For Validation Error messages
* @see Calendar::fetch() *
* @package Calendar * @category Date and Time
* @access public * @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @see Calendar::fetch()
* @access public
*/ */
class Calendar_Validation_Error class Calendar_Validation_Error
{ {
@@ -280,12 +316,14 @@ class Calendar_Validation_Error
/** /**
* Constructs Calendar_Validation_Error * Constructs Calendar_Validation_Error
* @param string Date unit (e.g. month,hour,second) *
* @param int Value of unit which failed test * @param string $unit Date unit (e.g. month,hour,second)
* @param string Validation error message * @param int $value Value of unit which failed test
* @param string $message Validation error message
*
* @access protected * @access protected
*/ */
function Calendar_Validation_Error($unit,$value,$message) function Calendar_Validation_Error($unit, $value, $message)
{ {
$this->unit = $unit; $this->unit = $unit;
$this->value = $value; $this->value = $value;
@@ -294,6 +332,7 @@ class Calendar_Validation_Error
/** /**
* Returns the Date unit * Returns the Date unit
*
* @return string * @return string
* @access public * @access public
*/ */
@@ -304,6 +343,7 @@ class Calendar_Validation_Error
/** /**
* Returns the value of the unit * Returns the value of the unit
*
* @return int * @return int
* @access public * @access public
*/ */
@@ -314,6 +354,7 @@ class Calendar_Validation_Error
/** /**
* Returns the validation error message * Returns the validation error message
*
* @return string * @return string
* @access public * @access public
*/ */
@@ -324,6 +365,7 @@ class Calendar_Validation_Error
/** /**
* Returns a string containing the unit, value and error message * Returns a string containing the unit, value and error message
*
* @return string * @return string
* @access public * @access public
*/ */

View File

@@ -1,28 +1,40 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// | Lorenzo Alberton <l dot alberton at quipo dot it> |
// +----------------------------------------------------------------------+
//
// $Id: Week.php,v 1.7 2005/10/22 10:26:49 quipo Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Week class
* @version $Id: Week.php,v 1.7 2005/10/22 10:26:49 quipo Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Week.php 300729 2010-06-24 12:05:53Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
@@ -41,8 +53,8 @@ require_once CALENDAR_ROOT.'Calendar.php';
/** /**
* Represents a Week and builds Days in tabular format<br> * Represents a Week and builds Days in tabular format<br>
* <code> * <code>
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Week.php'; * require_once 'Calendar/Week.php';
* $Week = & new Calendar_Week(2003, 10, 1); Oct 2003, 1st tabular week * $Week = new Calendar_Week(2003, 10, 1); Oct 2003, 1st tabular week
* echo '<tr>'; * echo '<tr>';
* while ($Day = & $Week->fetch()) { * while ($Day = & $Week->fetch()) {
* if ($Day->isEmpty()) { * if ($Day->isEmpty()) {
@@ -53,8 +65,14 @@ require_once CALENDAR_ROOT.'Calendar.php';
* } * }
* echo '</tr>'; * echo '</tr>';
* </code> * </code>
* @package Calendar *
* @access public * @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
*/ */
class Calendar_Week extends Calendar class Calendar_Week extends Calendar
{ {
@@ -109,33 +127,49 @@ class Calendar_Week extends Calendar
/** /**
* Constructs Week * Constructs Week
* @param int year e.g. 2003 *
* @param int month e.g. 5 * @param int $y year e.g. 2003
* @param int a day of the desired week * @param int $m month e.g. 5
* @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.) * @param int $d a day of the desired week
* @param int $firstDay (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
*
* @access public * @access public
*/ */
function Calendar_Week($y, $m, $d, $firstDay=null) function Calendar_Week($y, $m, $d, $firstDay = null)
{ {
require_once CALENDAR_ROOT.'Table/Helper.php'; include_once CALENDAR_ROOT.'Table/Helper.php';
Calendar::Calendar($y, $m, $d); parent::Calendar($y, $m, $d);
$this->firstDay = $this->defineFirstDayOfWeek($firstDay); $this->firstDay = $this->defineFirstDayOfWeek($firstDay);
$this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay); $this->tableHelper = new Calendar_Table_Helper($this, $this->firstDay);
$this->thisWeek = $this->tableHelper->getWeekStart($y, $m, $d, $this->firstDay); $this->thisWeek = $this->tableHelper->getWeekStart($y, $m, $d, $this->firstDay);
$this->prevWeek = $this->tableHelper->getWeekStart($y, $m, $d - $this->cE->getDaysInWeek( $this->prevWeek = $this->tableHelper->getWeekStart(
$this->thisYear(), $y,
$this->thisMonth(), $m,
$this->thisDay()), $this->firstDay); $d - $this->cE->getDaysInWeek(
$this->nextWeek = $this->tableHelper->getWeekStart($y, $m, $d + $this->cE->getDaysInWeek( $this->thisYear(),
$this->thisYear(), $this->thisMonth(),
$this->thisMonth(), $this->thisDay()
$this->thisDay()), $this->firstDay); ),
$this->firstDay
);
$this->nextWeek = $this->tableHelper->getWeekStart(
$y,
$m,
$d + $this->cE->getDaysInWeek(
$this->thisYear(),
$this->thisMonth(),
$this->thisDay()
),
$this->firstDay
);
} }
/** /**
* Defines the calendar by a timestamp (Unix or ISO-8601), replacing values * Defines the calendar by a timestamp (Unix or ISO-8601), replacing values
* passed to the constructor * passed to the constructor
* @param int|string Unix or ISO-8601 timestamp *
* @param int|string $ts Unix or ISO-8601 timestamp
*
* @return void * @return void
* @access public * @access public
*/ */
@@ -146,28 +180,38 @@ class Calendar_Week extends Calendar
$this->year, $this->month, $this->day, $this->firstDay $this->year, $this->month, $this->day, $this->firstDay
); );
$this->prevWeek = $this->tableHelper->getWeekStart( $this->prevWeek = $this->tableHelper->getWeekStart(
$this->year, $this->month, $this->day - $this->cE->getDaysInWeek( $this->year,
$this->month,
$this->day - $this->cE->getDaysInWeek(
$this->thisYear(), $this->thisYear(),
$this->thisMonth(), $this->thisMonth(),
$this->thisDay()), $this->firstDay $this->thisDay()
),
$this->firstDay
); );
$this->nextWeek = $this->tableHelper->getWeekStart( $this->nextWeek = $this->tableHelper->getWeekStart(
$this->year, $this->month, $this->day + $this->cE->getDaysInWeek( $this->year,
$this->month,
$this->day + $this->cE->getDaysInWeek(
$this->thisYear(), $this->thisYear(),
$this->thisMonth(), $this->thisMonth(),
$this->thisDay()), $this->firstDay $this->thisDay()
),
$this->firstDay
); );
} }
/** /**
* Builds Calendar_Day objects for this Week * Builds Calendar_Day objects for this Week
* @param array (optional) Calendar_Day objects representing selected dates *
* @param array $sDates (optional) Calendar_Day objects representing selected dates
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
function build($sDates = array()) function build($sDates = array())
{ {
require_once CALENDAR_ROOT.'Day.php'; include_once CALENDAR_ROOT.'Day.php';
$year = $this->cE->stampToYear($this->thisWeek); $year = $this->cE->stampToYear($this->thisWeek);
$month = $this->cE->stampToMonth($this->thisWeek); $month = $this->cE->stampToMonth($this->thisWeek);
$day = $this->cE->stampToDay($this->thisWeek); $day = $this->cE->stampToDay($this->thisWeek);
@@ -180,9 +224,10 @@ class Calendar_Week extends Calendar
for ($i=1; $i <= $end; $i++) { for ($i=1; $i <= $end; $i++) {
$stamp = $this->cE->dateToStamp($year, $month, $day++); $stamp = $this->cE->dateToStamp($year, $month, $day++);
$this->children[$i] = new Calendar_Day( $this->children[$i] = new Calendar_Day(
$this->cE->stampToYear($stamp), $this->cE->stampToYear($stamp),
$this->cE->stampToMonth($stamp), $this->cE->stampToMonth($stamp),
$this->cE->stampToDay($stamp)); $this->cE->stampToDay($stamp)
);
} }
//set empty days (@see Calendar_Month_Weeks::build()) //set empty days (@see Calendar_Month_Weeks::build())
@@ -206,28 +251,36 @@ class Calendar_Week extends Calendar
} }
/** /**
* @param boolean * Set as first week of the month
*
* @param boolean $state whether it's first or not
*
* @return void * @return void
* @access private * @access private
*/ */
function setFirst($state=true) function setFirst($state = true)
{ {
$this->firstWeek = $state; $this->firstWeek = $state;
} }
/** /**
* @param boolean * Set as last week of the month
*
* @param boolean $state whether it's lasst or not
*
* @return void * @return void
* @access private * @access private
*/ */
function setLast($state=true) function setLast($state = true)
{ {
$this->lastWeek = $state; $this->lastWeek = $state;
} }
/** /**
* Called from build() * Called from build()
* @param array *
* @param array $sDates Calendar_Day objects representing selected dates
*
* @return void * @return void
* @access private * @access private
*/ */
@@ -247,37 +300,66 @@ class Calendar_Week extends Calendar
reset($this->children); reset($this->children);
} }
/**
* Returns the value for this year
*
* When a on the first/last week of the year, the year of the week is
* calculated according to ISO-8601
*
* @param string $format return value format ['int' | 'timestamp' | 'object' | 'array']
*
* @return int e.g. 2003 or timestamp
* @access public
*/
function thisYear($format = 'int')
{
if (null !== $this->thisWeek) {
$tmp_cal = new Calendar();
$tmp_cal->setTimestamp($this->thisWeek);
$first_dow = $tmp_cal->thisDay('array');
$days_in_week = $tmp_cal->cE->getDaysInWeek($tmp_cal->year, $tmp_cal->month, $tmp_cal->day);
$tmp_cal->day += $days_in_week;
$last_dow = $tmp_cal->thisDay('array');
if ($first_dow['year'] == $last_dow['year']) {
return $first_dow['year'];
}
if ($last_dow['day'] > floor($days_in_week / 2)) {
return $last_dow['year'];
}
return $first_dow['year'];
}
return parent::thisYear();
}
/** /**
* Gets the value of the previous week, according to the requested format * Gets the value of the previous week, according to the requested format
* *
* @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array'] * @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
*
* @return mixed * @return mixed
* @access public * @access public
*/ */
function prevWeek($format = 'n_in_month') function prevWeek($format = 'n_in_month')
{ {
switch (strtolower($format)) { switch (strtolower($format)) {
case 'int': case 'int':
case 'n_in_month': case 'n_in_month':
return ($this->firstWeek) ? null : $this->thisWeek('n_in_month') -1; return ($this->firstWeek) ? null : $this->thisWeek('n_in_month') -1;
break; case 'n_in_year':
case 'n_in_year': return $this->cE->getWeekNInYear(
return $this->cE->getWeekNInYear( $this->cE->stampToYear($this->prevWeek),
$this->cE->stampToYear($this->prevWeek), $this->cE->stampToMonth($this->prevWeek),
$this->cE->stampToMonth($this->prevWeek), $this->cE->stampToDay($this->prevWeek));
$this->cE->stampToDay($this->prevWeek)); case 'array':
break; return $this->toArray($this->prevWeek);
case 'array': case 'object':
return $this->toArray($this->prevWeek); include_once CALENDAR_ROOT.'Factory.php';
break; return Calendar_Factory::createByTimestamp('Week', $this->prevWeek);
case 'object': case 'timestamp':
require_once CALENDAR_ROOT.'Factory.php'; default:
return Calendar_Factory::createByTimestamp('Week', $this->prevWeek); return $this->prevWeek;
break;
case 'timestamp':
default:
return $this->prevWeek;
break;
} }
} }
@@ -285,46 +367,42 @@ class Calendar_Week extends Calendar
* Gets the value of the current week, according to the requested format * Gets the value of the current week, according to the requested format
* *
* @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array'] * @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
*
* @return mixed * @return mixed
* @access public * @access public
*/ */
function thisWeek($format = 'n_in_month') function thisWeek($format = 'n_in_month')
{ {
switch (strtolower($format)) { switch (strtolower($format)) {
case 'int': case 'int':
case 'n_in_month': case 'n_in_month':
if ($this->firstWeek) { if ($this->firstWeek) {
return 1; return 1;
} }
if ($this->lastWeek) { if ($this->lastWeek) {
return $this->cE->getWeeksInMonth( return $this->cE->getWeeksInMonth(
$this->thisYear(),
$this->thisMonth(),
$this->firstDay);
}
return $this->cE->getWeekNInMonth(
$this->thisYear(), $this->thisYear(),
$this->thisMonth(), $this->thisMonth(),
$this->thisDay(),
$this->firstDay); $this->firstDay);
break; }
case 'n_in_year': return $this->cE->getWeekNInMonth(
return $this->cE->getWeekNInYear( $this->thisYear(),
$this->cE->stampToYear($this->thisWeek), $this->thisMonth(),
$this->cE->stampToMonth($this->thisWeek), $this->thisDay(),
$this->cE->stampToDay($this->thisWeek)); $this->firstDay);
break; case 'n_in_year':
case 'array': return $this->cE->getWeekNInYear(
return $this->toArray($this->thisWeek); $this->cE->stampToYear($this->thisWeek),
break; $this->cE->stampToMonth($this->thisWeek),
case 'object': $this->cE->stampToDay($this->thisWeek));
require_once CALENDAR_ROOT.'Factory.php'; case 'array':
return Calendar_Factory::createByTimestamp('Week', $this->thisWeek); return $this->toArray($this->thisWeek);
break; case 'object':
case 'timestamp': include_once CALENDAR_ROOT.'Factory.php';
default: return Calendar_Factory::createByTimestamp('Week', $this->thisWeek);
return $this->thisWeek; case 'timestamp':
break; default:
return $this->thisWeek;
} }
} }
@@ -332,39 +410,36 @@ class Calendar_Week extends Calendar
* Gets the value of the following week, according to the requested format * Gets the value of the following week, according to the requested format
* *
* @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array'] * @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
*
* @return mixed * @return mixed
* @access public * @access public
*/ */
function nextWeek($format = 'n_in_month') function nextWeek($format = 'n_in_month')
{ {
switch (strtolower($format)) { switch (strtolower($format)) {
case 'int': case 'int':
case 'n_in_month': case 'n_in_month':
return ($this->lastWeek) ? null : $this->thisWeek('n_in_month') +1; return ($this->lastWeek) ? null : $this->thisWeek('n_in_month') +1;
break; case 'n_in_year':
case 'n_in_year': return $this->cE->getWeekNInYear(
return $this->cE->getWeekNInYear( $this->cE->stampToYear($this->nextWeek),
$this->cE->stampToYear($this->nextWeek), $this->cE->stampToMonth($this->nextWeek),
$this->cE->stampToMonth($this->nextWeek), $this->cE->stampToDay($this->nextWeek));
$this->cE->stampToDay($this->nextWeek)); case 'array':
break; return $this->toArray($this->nextWeek);
case 'array': case 'object':
return $this->toArray($this->nextWeek); include_once CALENDAR_ROOT.'Factory.php';
break; return Calendar_Factory::createByTimestamp('Week', $this->nextWeek);
case 'object': case 'timestamp':
require_once CALENDAR_ROOT.'Factory.php'; default:
return Calendar_Factory::createByTimestamp('Week', $this->nextWeek); return $this->nextWeek;
break;
case 'timestamp':
default:
return $this->nextWeek;
break;
} }
} }
/** /**
* Returns the instance of Calendar_Table_Helper. * Returns the instance of Calendar_Table_Helper.
* Called from Calendar_Validator::isValidWeek * Called from Calendar_Validator::isValidWeek
*
* @return Calendar_Table_Helper * @return Calendar_Table_Helper
* @access protected * @access protected
*/ */
@@ -375,6 +450,7 @@ class Calendar_Week extends Calendar
/** /**
* Makes sure theres a value for $this->day * Makes sure theres a value for $this->day
*
* @return void * @return void
* @access private * @access private
*/ */

View File

@@ -1,27 +1,39 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */ /* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
// +----------------------------------------------------------------------+
//
// $Id: Year.php,v 1.4 2005/10/22 10:25:39 quipo Exp $
//
/** /**
* @package Calendar * Contains the Calendar_Minute class
* @version $Id: Year.php,v 1.4 2005/10/22 10:25:39 quipo Exp $ *
* PHP versions 4 and 5
*
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Year.php 300728 2010-06-24 11:43:56Z quipo $
* @link http://pear.php.net/package/Calendar
*/ */
/** /**
@@ -47,19 +59,27 @@ require_once CALENDAR_ROOT.'Calendar.php';
* echo $Month->thisMonth().'<br />'; * echo $Month->thisMonth().'<br />';
* } * }
* </code> * </code>
* @package Calendar *
* @access public * @category Date and Time
* @package Calendar
* @author Harry Fuecks <hfuecks@phppatterns.com>
* @copyright 2003-2007 Harry Fuecks
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Calendar
* @access public
*/ */
class Calendar_Year extends Calendar class Calendar_Year extends Calendar
{ {
/** /**
* Constructs Calendar_Year * Constructs Calendar_Year
* @param int year e.g. 2003 *
* @param int $y year e.g. 2003
*
* @access public * @access public
*/ */
function Calendar_Year($y) function Calendar_Year($y)
{ {
Calendar::Calendar($y); parent::Calendar($y);
} }
/** /**
@@ -73,16 +93,20 @@ class Calendar_Year extends Calendar
* // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH); // Use Calendar_Month * // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH); // Use Calendar_Month
* </code> * </code>
* It defaults to building Calendar_Month objects. * It defaults to building Calendar_Month objects.
* @param array (optional) array of Calendar_Month objects representing selected dates *
* @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.) * @param array $sDates (optional) array of Calendar_Month objects
* representing selected dates
* @param int $firstDay (optional) first day of week
* (e.g. 0 for Sunday, 2 for Tuesday etc.)
*
* @return boolean * @return boolean
* @access public * @access public
*/ */
function build($sDates = array(), $firstDay = null) function build($sDates = array(), $firstDay = null)
{ {
require_once CALENDAR_ROOT.'Factory.php'; include_once CALENDAR_ROOT.'Factory.php';
$this->firstDay = $this->defineFirstDayOfWeek($firstDay); $this->firstDay = $this->defineFirstDayOfWeek($firstDay);
$monthsInYear = $this->cE->getMonthsInYear($this->thisYear()); $monthsInYear = $this->cE->getMonthsInYear($this->thisYear());
for ($i=1; $i <= $monthsInYear; $i++) { for ($i=1; $i <= $monthsInYear; $i++) {
$this->children[$i] = Calendar_Factory::create('Month', $this->year, $i); $this->children[$i] = Calendar_Factory::create('Month', $this->year, $i);
} }
@@ -94,11 +118,14 @@ class Calendar_Year extends Calendar
/** /**
* Called from build() * Called from build()
* @param array *
* @param array $sDates array of Calendar_Month objects representing selected dates
*
* @return void * @return void
* @access private * @access private
*/ */
function setSelection($sDates) { function setSelection($sDates)
{
foreach ($sDates as $sDate) { foreach ($sDates as $sDate) {
if ($this->year == $sDate->thisYear()) { if ($this->year == $sDate->thisYear()) {
$key = $sDate->thisMonth(); $key = $sDate->thisMonth();