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
/* 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: Calendar.php,v 1.3 2005/10/22 10:07:11 quipo Exp $
//
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* @package Calendar
* @version $Id: Calendar.php,v 1.3 2005/10/22 10:07:11 quipo Exp $
* Contains the Calendar and Calendar_Engine_Factory classes
*
* 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
* Calendar_Engines. The engine used can be controlled with the constant
* CALENDAR_ENGINE
* @see Calendar_Engine_Interface
* @package Calendar
* @access protected
*
* @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
* @see Calendar_Engine_Interface
* @access protected
*/
class Calendar_Engine_Factory
{
/**
* Returns an instance of the engine
*
* @return object instance of a calendar calculation engine
* @access protected
*/
function & getEngine()
static function & getEngine()
{
static $engine = false;
switch (CALENDAR_ENGINE) {
case 'PearDate':
$class = 'Calendar_Engine_PearDate';
break;
case 'UnixTS':
default:
$class = 'Calendar_Engine_UnixTS';
case 'PearDate':
$class = 'Calendar_Engine_PearDate';
break;
case 'UnixTS':
default:
$class = 'Calendar_Engine_UnixTS';
break;
}
if (!$engine) {
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;
}
@@ -86,10 +106,16 @@ class Calendar_Engine_Factory
}
/**
* Base class for Calendar API. This class should not be instantiated
* directly.
* Base class for Calendar API. This class should not be instantiated 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
* @package Calendar
*/
class Calendar
{
@@ -113,7 +139,7 @@ class Calendar
* @access private
* @var int
*/
var $year;
var $year;
/**
* Month for this calendar object e.g. 9
@@ -167,12 +193,14 @@ class Calendar
/**
* Constructs the Calendar
* @param int year
* @param int month
* @param int day
* @param int hour
* @param int minute
* @param int second
*
* @param int $y year
* @param int $m month
* @param int $d day
* @param int $h hour
* @param int $i minute
* @param int $s second
*
* @access protected
*/
function Calendar($y = 2000, $m = 1, $d = 1, $h = 0, $i = 0, $s = 0)
@@ -181,7 +209,7 @@ class Calendar
if (!isset($cE)) {
$cE = & Calendar_Engine_Factory::getEngine();
}
$this->cE = & $cE;
$this->cE = & $cE;
$this->year = (int)$y;
$this->month = (int)$m;
$this->day = (int)$d;
@@ -193,7 +221,9 @@ class Calendar
/**
* Defines the calendar by a timestamp (Unix or ISO-8601), replacing values
* passed to the constructor
* @param int|string Unix or ISO-8601 timestamp
*
* @param int|string $ts Unix or ISO-8601 timestamp
*
* @return void
* @access public
*/
@@ -210,6 +240,7 @@ class Calendar
/**
* Returns a timestamp from the current date / time values. Format of
* timestamp depends on Calendar_Engine implementation being used
*
* @return int|string timestamp
* @access public
*/
@@ -222,7 +253,9 @@ class Calendar
/**
* Defines calendar object as selected (e.g. for today)
* @param boolean state whether Calendar subclass
*
* @param boolean $state whether Calendar subclass
*
* @return void
* @access public
*/
@@ -233,6 +266,7 @@ class Calendar
/**
* True if the calendar subclass object is selected (e.g. today)
*
* @return boolean
* @access public
*/
@@ -241,14 +275,26 @@ class Calendar
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)
*
* @return void
* @access public
*/
function adjust()
{
$stamp = $this->getTimeStamp();
$stamp = $this->getTimeStamp();
$this->year = $this->cE->stampToYear($stamp);
$this->month = $this->cE->stampToMonth($stamp);
$this->day = $this->cE->stampToDay($stamp);
@@ -259,7 +305,9 @@ class Calendar
/**
* 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
* @access public
*/
@@ -280,59 +328,64 @@ class Calendar
/**
* 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 mixed timestamp (depending on Calendar engine being used)
* @param int integer default value (i.e. give me the answer quick)
*
* @param string $returnType type of date object that return value represents
* @param string $format ['int' | 'array' | 'timestamp' | 'object']
* @param mixed $stamp timestamp (depending on Calendar engine being used)
* @param int $default default value (i.e. give me the answer quick)
*
* @return mixed
* @access private
*/
function returnValue($returnType, $format, $stamp, $default)
{
switch (strtolower($format)) {
case 'int':
return $default;
case 'array':
return $this->toArray($stamp);
break;
case 'object':
require_once CALENDAR_ROOT.'Factory.php';
return Calendar_Factory::createByTimestamp($returnType,$stamp);
break;
case 'timestamp':
default:
return $stamp;
break;
case 'int':
return $default;
case 'array':
return $this->toArray($stamp);
break;
case 'object':
include_once CALENDAR_ROOT.'Factory.php';
return Calendar_Factory::createByTimestamp($returnType, $stamp);
break;
case 'timestamp':
default:
return $stamp;
break;
}
}
/**
* Abstract method for building the children of a calendar object.
* Implemented by Calendar subclasses
* @param array containing Calendar objects to select (optional)
*
* @param array $sDates array containing Calendar objects to select (optional)
*
* @return boolean
* @access public
* @abstract
*/
function build($sDates = array())
{
require_once 'PEAR.php';
PEAR::raiseError(
'Calendar::build is abstract', null, PEAR_ERROR_TRIGGER,
include_once 'PEAR.php';
PEAR::raiseError('Calendar::build is abstract', null, PEAR_ERROR_TRIGGER,
E_USER_NOTICE, 'Calendar::build()');
return false;
}
/**
* Abstract method for selected data objects called from build
* @param array
*
* @param array $sDates array of Calendar objects to select
*
* @return boolean
* @access public
* @abstract
*/
function setSelection($sDates)
{
require_once 'PEAR.php';
include_once 'PEAR.php';
PEAR::raiseError(
'Calendar::setSelection is abstract', null, PEAR_ERROR_TRIGGER,
E_USER_NOTICE, 'Calendar::setSelection()');
@@ -344,6 +397,7 @@ class Calendar
* (e.g. a minute from an hour object). On reaching the end of
* the collection, returns false and resets the collection for
* further iteratations.
*
* @return mixed either an object subclass of Calendar or false
* @access public
*/
@@ -360,6 +414,7 @@ class Calendar
/**
* Fetches all child from the current collection of children
*
* @return array
* @access public
*/
@@ -369,8 +424,8 @@ class Calendar
}
/**
* Get the number Calendar subclass objects stored in the internal
* collection.
* Get the number Calendar subclass objects stored in the internal collection
*
* @return int
* @access public
*/
@@ -381,8 +436,8 @@ class Calendar
/**
* Determine whether this date is valid, with the bounds determined by
* the Calendar_Engine. The call is passed on to
* Calendar_Validator::isValid
* the Calendar_Engine. The call is passed on to Calendar_Validator::isValid
*
* @return boolean
* @access public
*/
@@ -394,14 +449,15 @@ class Calendar
/**
* Returns an instance of Calendar_Validator
*
* @return Calendar_Validator
* @access public
*/
function & getValidator()
{
if (!isset($this->validator)) {
require_once CALENDAR_ROOT.'Validator.php';
$this->validator = & new Calendar_Validator($this);
include_once CALENDAR_ROOT.'Validator.php';
$this->validator = new Calendar_Validator($this);
}
return $this->validator;
}
@@ -409,6 +465,7 @@ class Calendar
/**
* Returns a reference to the current Calendar_Engine being used. Useful
* for Calendar_Table_Helper and Calendar_Validator
*
* @return object implementing Calendar_Engine_Inteface
* @access protected
*/
@@ -420,11 +477,13 @@ class Calendar
/**
* Set the CALENDAR_FIRST_DAY_OF_WEEK constant to the $firstDay value
* 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
* CALENDAR_FIRST_DAY_OF_WEEK constant is already defined and
* 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
*/
function defineFirstDayOfWeek($firstDay = null)
@@ -450,7 +509,9 @@ class Calendar
/**
* 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
* @access public
*/
@@ -462,7 +523,9 @@ class Calendar
/**
* 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
* @access public
*/
@@ -474,7 +537,9 @@ class Calendar
/**
* 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
* @access public
*/
@@ -486,7 +551,9 @@ class Calendar
/**
* 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
* @access public
*/
@@ -498,7 +565,9 @@ class Calendar
/**
* 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
* @access public
*/
@@ -510,7 +579,9 @@ class Calendar
/**
* 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
* @access public
*/
@@ -522,7 +593,9 @@ class Calendar
/**
* 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
* @access public
*/
@@ -535,7 +608,9 @@ class Calendar
/**
* 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
* @access public
*/
@@ -548,7 +623,9 @@ class Calendar
/**
* 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
* @access public
*/
@@ -561,7 +638,9 @@ class Calendar
/**
* 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
* @access public
*/
@@ -574,7 +653,9 @@ class Calendar
/**
* 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
* @access public
*/
@@ -587,7 +668,9 @@ class Calendar
/**
* 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
* @access public
*/
@@ -600,7 +683,9 @@ class Calendar
/**
* 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
* @access public
*/
@@ -614,7 +699,9 @@ class Calendar
/**
* 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
* @access public
*/
@@ -628,7 +715,9 @@ class Calendar
/**
* 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
* @access public
*/
@@ -642,7 +731,9 @@ class Calendar
/**
* 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
* @access public
*/
@@ -656,7 +747,9 @@ class Calendar
/**
* 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
* @access public
*/
@@ -670,7 +763,9 @@ class Calendar
/**
* 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
* @access public
*/

View File

@@ -1,27 +1,39 @@
<?php
/* 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
* @version $Id: Day.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
* Contains the Calendar_Day class
*
* 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.
* <code>
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Day.php';
* $Day = & new Calendar_Day(2003, 10, 21); // Oct 21st 2003
* require_once 'Calendar/Day.php';
* $Day = new Calendar_Day(2003, 10, 21); // Oct 21st 2003
* while ($Hour = & $Day->fetch()) {
* echo $Hour->thisHour().'<br />';
* }
* </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
{
@@ -60,7 +78,7 @@ class Calendar_Day extends Calendar
/**
* Marks the Day at the end of a week
* @access private
* @access private
* @var boolean
*/
var $last = false;
@@ -75,29 +93,33 @@ class Calendar_Day extends Calendar
/**
* Constructs Calendar_Day
* @param int year e.g. 2003
* @param int month e.g. 8
* @param int day e.g. 15
*
* @param int $y year e.g. 2003
* @param int $m month e.g. 8
* @param int $d day e.g. 15
*
* @access public
*/
function Calendar_Day($y, $m, $d)
{
Calendar::Calendar($y, $m, $d);
parent::Calendar($y, $m, $d);
}
/**
* 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
* @access public
*/
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);
for ($i=0; $i < $hID; $i++) {
$this->children[$i]=
$this->children[$i] =
new Calendar_Hour($this->year, $this->month, $this->day, $i);
}
if (count($sDates) > 0) {
@@ -108,7 +130,9 @@ class Calendar_Day extends Calendar
/**
* Called from build()
* @param array
*
* @param array $sDates dates to be selected
*
* @return void
* @access private
*/
@@ -131,11 +155,13 @@ class Calendar_Day extends Calendar
/**
* Defines Day object as first in a week
* Only used by Calendar_Month_Weekdays::build()
* @param boolean state
*
* @param boolean $state set this day as first in week
*
* @return void
* @access private
*/
function setFirst ($state = true)
function setFirst($state = true)
{
$this->first = $state;
}
@@ -143,7 +169,9 @@ class Calendar_Day extends Calendar
/**
* Defines Day object as last in a week
* Used only following Calendar_Month_Weekdays::build()
* @param boolean state
*
* @param boolean $state set this day as last in week
*
* @return void
* @access private
*/
@@ -155,16 +183,19 @@ class Calendar_Day extends Calendar
/**
* Returns true if Day object is first in a Week
* Only relevant when Day is created by Calendar_Month_Weekdays::build()
*
* @return boolean
* @access public
*/
function isFirst() {
function isFirst()
{
return $this->first;
}
/**
* Returns true if Day object is last in a Week
* Only relevant when Day is created by Calendar_Month_Weekdays::build()
*
* @return boolean
* @access public
*/
@@ -176,7 +207,9 @@ class Calendar_Day extends Calendar
/**
* Defines Day object as empty
* Only used by Calendar_Month_Weekdays::build()
* @param boolean state
*
* @param boolean $state set this day as empty
*
* @return void
* @access private
*/
@@ -186,6 +219,8 @@ class Calendar_Day extends Calendar
}
/**
* Check if this day is empty
*
* @return boolean
* @access public
*/

View File

@@ -1,28 +1,41 @@
<?php
/* 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
* @version $Id: Decorator.php,v 1.3 2005/10/22 10:29:46 quipo Exp $
* Contains the Calendar_Decorator class
*
* 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.
* Create a subclass of this class for your own "decoration".
@@ -36,12 +49,18 @@
.* return date('D', $day);
* }
* }
* $Day = & new Calendar_Day(2003, 10, 25);
* $DayDecorator = & new DayDecorator($Day);
* $Day = new Calendar_Day(2003, 10, 25);
* $DayDecorator = new DayDecorator($Day);
* echo $DayDecorator->thisDay(); // Outputs "Sat"
* </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
* @package Calendar
*/
class Calendar_Decorator
{
@@ -54,9 +73,10 @@ class 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;
}
@@ -64,7 +84,9 @@ class Calendar_Decorator
/**
* Defines the calendar by a Unix timestamp, replacing values
* passed to the constructor
* @param int Unix timestamp
*
* @param int $ts Unix timestamp
*
* @return void
* @access public
*/
@@ -76,7 +98,8 @@ class Calendar_Decorator
/**
* Returns a timestamp from the current date / time values. Format of
* timestamp depends on Calendar_Engine implementation being used
* @return int timestamp
*
* @return int $ts timestamp
* @access public
*/
function getTimestamp()
@@ -86,7 +109,9 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
@@ -97,6 +122,7 @@ class Calendar_Decorator
/**
* True if the calendar subclass object is selected (e.g. today)
*
* @return boolean
* @access public
*/
@@ -107,6 +133,7 @@ class Calendar_Decorator
/**
* Adjusts the date (helper method)
*
* @return void
* @access public
*/
@@ -117,21 +144,25 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
function toArray($stamp=null)
function toArray($stamp = null)
{
return $this->calendar->toArray($stamp);
}
/**
* 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 mixed timestamp (depending on Calendar engine being used)
* @param int integer default value (i.e. give me the answer quick)
*
* @param string $returnType type of date object that return value represents
* @param string $format ['int'|'timestamp'|'object'|'array']
* @param mixed $stamp timestamp (depending on Calendar engine being used)
* @param integer $default default value (i.e. give me the answer quick)
*
* @return mixed
* @access private
*/
@@ -143,13 +174,15 @@ class Calendar_Decorator
/**
* Defines Day object as first in a week
* Only used by Calendar_Month_Weekdays::build()
* @param boolean state
*
* @param boolean $state whether it's first or not
*
* @return void
* @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);
}
}
@@ -157,13 +190,15 @@ class Calendar_Decorator
/**
* Defines Day object as last in a week
* Used only following Calendar_Month_Weekdays::build()
* @param boolean state
*
* @param boolean $state whether it's last or not
*
* @return void
* @access private
*/
function setLast($state = true)
{
if ( method_exists($this->calendar,'setLast') ) {
if (method_exists($this->calendar, 'setLast')) {
$this->calendar->setLast($state);
}
}
@@ -171,11 +206,13 @@ class Calendar_Decorator
/**
* Returns true if Day object is first in a Week
* Only relevant when Day is created by Calendar_Month_Weekdays::build()
*
* @return boolean
* @access public
*/
function isFirst() {
if ( method_exists($this->calendar,'isFirst') ) {
function isFirst()
{
if (method_exists($this->calendar, 'isFirst')) {
return $this->calendar->isFirst();
}
}
@@ -183,12 +220,13 @@ class Calendar_Decorator
/**
* Returns true if Day object is last in a Week
* Only relevant when Day is created by Calendar_Month_Weekdays::build()
*
* @return boolean
* @access public
*/
function isLast()
{
if ( method_exists($this->calendar,'isLast') ) {
if (method_exists($this->calendar, 'isLast')) {
return $this->calendar->isLast();
}
}
@@ -196,31 +234,37 @@ class Calendar_Decorator
/**
* Defines Day object as empty
* Only used by Calendar_Month_Weekdays::build()
* @param boolean state
*
* @param boolean $state whether it's empty or not
*
* @return void
* @access private
*/
function setEmpty ($state = true)
{
if ( method_exists($this->calendar,'setEmpty') ) {
if (method_exists($this->calendar, 'setEmpty')) {
$this->calendar->setEmpty($state);
}
}
/**
* Check if the current object is empty
*
* @return boolean
* @access public
*/
function isEmpty()
{
if ( method_exists($this->calendar,'isEmpty') ) {
if (method_exists($this->calendar, 'isEmpty')) {
return $this->calendar->isEmpty();
}
}
/**
* Build the children
* @param array containing Calendar objects to select (optional)
*
* @param array $sDates array containing Calendar objects to select (optional)
*
* @return boolean
* @access public
* @abstract
@@ -235,6 +279,7 @@ class Calendar_Decorator
* (e.g. a minute from an hour object). On reaching the end of
* the collection, returns false and resets the collection for
* further iteratations.
*
* @return mixed either an object subclass of Calendar or false
* @access public
*/
@@ -245,6 +290,7 @@ class Calendar_Decorator
/**
* Fetches all child from the current collection of children
*
* @return array
* @access public
*/
@@ -254,8 +300,8 @@ class Calendar_Decorator
}
/**
* Get the number Calendar subclass objects stored in the internal
* collection.
* Get the number Calendar subclass objects stored in the internal collection
*
* @return int
* @access public
*/
@@ -266,8 +312,8 @@ class Calendar_Decorator
/**
* Determine whether this date is valid, with the bounds determined by
* the Calendar_Engine. The call is passed on to
* Calendar_Validator::isValid
* the Calendar_Engine. The call is passed on to Calendar_Validator::isValid
*
* @return boolean
* @access public
*/
@@ -278,6 +324,7 @@ class Calendar_Decorator
/**
* Returns an instance of Calendar_Validator
*
* @return Calendar_Validator
* @access public
*/
@@ -290,17 +337,21 @@ class Calendar_Decorator
/**
* Returns a reference to the current Calendar_Engine being used. Useful
* for Calendar_Table_Helper and Calendar_Validator
*
* @return object implementing Calendar_Engine_Inteface
* @access private
*/
function & getEngine()
{
return $this->calendar->getEngine();
$engine = $this->calendar->getEngine();
return $engine;
}
/**
* 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
* @access public
*/
@@ -311,7 +362,9 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
@@ -322,7 +375,9 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
@@ -333,7 +388,9 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
@@ -344,7 +401,9 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
@@ -355,7 +414,9 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
@@ -366,16 +427,18 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
function prevWeek($format = 'n_in_month')
{
if ( method_exists($this->calendar,'prevWeek') ) {
if ( method_exists($this->calendar, 'prevWeek')) {
return $this->calendar->prevWeek($format);
} else {
require_once 'PEAR.php';
include_once 'PEAR.php';
PEAR::raiseError(
'Cannot call prevWeek on Calendar object of type: '.
get_class($this->calendar), 133, PEAR_ERROR_TRIGGER,
@@ -386,16 +449,18 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
function thisWeek($format = 'n_in_month')
{
if ( method_exists($this->calendar,'thisWeek') ) {
if ( method_exists($this->calendar, 'thisWeek')) {
return $this->calendar->thisWeek($format);
} else {
require_once 'PEAR.php';
include_once 'PEAR.php';
PEAR::raiseError(
'Cannot call thisWeek on Calendar object of type: '.
get_class($this->calendar), 133, PEAR_ERROR_TRIGGER,
@@ -406,16 +471,18 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
function nextWeek($format = 'n_in_month')
{
if ( method_exists($this->calendar,'nextWeek') ) {
if ( method_exists($this->calendar, 'nextWeek')) {
return $this->calendar->nextWeek($format);
} else {
require_once 'PEAR.php';
include_once 'PEAR.php';
PEAR::raiseError(
'Cannot call thisWeek on Calendar object of type: '.
get_class($this->calendar), 133, PEAR_ERROR_TRIGGER,
@@ -426,17 +493,22 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
function prevDay($format = 'int') {
function prevDay($format = 'int')
{
return $this->calendar->prevDay($format);
}
/**
* 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
* @access public
*/
@@ -447,7 +519,9 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
@@ -458,7 +532,9 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
@@ -469,7 +545,9 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
@@ -480,7 +558,9 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
@@ -491,7 +571,9 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
@@ -502,7 +584,9 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
@@ -513,18 +597,22 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
function nextMinute($format = 'int')
function nextMinute($format = 'int')
{
return $this->calendar->nextMinute($format);
}
/**
* 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
* @access public
*/
@@ -535,7 +623,9 @@ class Calendar_Decorator
/**
* 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
* @access public
*/
@@ -546,7 +636,9 @@ class Calendar_Decorator
/**
* 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
* @access public
*/

View File

@@ -1,28 +1,40 @@
<?php
/* 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
* @version $Id: Textual.php,v 1.3 2004/08/16 13:02:44 hfuecks Exp $
* Contains the Calendar_Decorator_Wrapper class
*
* 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.
* <b>Note:</b> for performance you should prefer Calendar_Util_Textual unless you
* 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
{
/**
* Constructs Calendar_Decorator_Textual
* @param object subclass of Calendar
*
* @param object &$Calendar subclass of Calendar
*
* @access public
*/
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)
* @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
* @access public
* @static
*/
function monthNames($format='long')
function monthNames($format = 'long')
{
return Calendar_Util_Textual::monthNames($format);
}
/**
* 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
* @access public
* @static
*/
function weekdayNames($format='long')
function weekdayNames($format = 'long')
{
return Calendar_Util_Textual::weekdayNames($format);
}
/**
* 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
* @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
* @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
* @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
* @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
* @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
* @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
* @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
* @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
* @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
* @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
* @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
* calendar object. Only useful for Calendar_Month_Weekdays, Calendar_Month_Weeks
* 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
* @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
/* 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
* @version $Id: Uri.php,v 1.3 2004/08/16 09:04:20 hfuecks Exp $
* Contains the Calendar_Decorator_Uri class
*
* 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
* <code>
* $Day = new Calendar_Day(2003, 10, 23);
* $Uri = & new Calendar_Decorator_Uri($Day);
* $Uri = new Calendar_Decorator_Uri($Day);
* $Uri->setFragments('year', 'month', 'day');
* echo $Uri->getPrev(); // Displays year=2003&month=10&day=22
* </code>
* @see Calendar_Util_Uri
* @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
* @see Calendar_Util_Uri
* @access public
*/
class Calendar_Decorator_Uri extends Calendar_Decorator
{
/**
* @var Calendar_Util_Uri
* @access private
*/
* @var Calendar_Util_Uri
* @access private
*/
var $Uri;
/**
* Constructs Calendar_Decorator_Uri
* @param object subclass of Calendar
*
* @param object &$Calendar subclass of Calendar
*
* @access public
*/
function Calendar_Decorator_Uri(&$Calendar)
@@ -78,22 +99,27 @@ class Calendar_Decorator_Uri extends Calendar_Decorator
/**
* Sets the URI fragment names
* @param string URI fragment for year
* @param string (optional) URI fragment for month
* @param string (optional) URI fragment for day
* @param string (optional) URI fragment for hour
* @param string (optional) URI fragment for minute
* @param string (optional) URI fragment for second
*
* @param string $y URI fragment for year
* @param string $m (optional) URI fragment for month
* @param string $d (optional) URI fragment for day
* @param string $h (optional) URI fragment for hour
* @param string $i (optional) URI fragment for minute
* @param string $s (optional) URI fragment for second
*
* @return void
* @access public
*/
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);
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);
}
/**
* Sets the separator string between fragments
* @param string separator e.g. /
*
* @param string $separator url fragment separator e.g. /
*
* @return void
* @access public
*/
@@ -103,20 +129,23 @@ class Calendar_Decorator_Uri extends Calendar_Decorator
}
/**
* Puts Uri decorator into "scalar mode" - URI variable names are not
* returned
* @param boolean (optional)
* Puts Uri decorator into "scalar mode" - URI variable names are not returned
*
* @param boolean $state (optional)
*
* @return void
* @access public
*/
function setScalar($state=true)
function setScalar($state = true)
{
$this->Uri->scalar = $state;
}
/**
* 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
* @access public
*/
@@ -127,7 +156,9 @@ class Calendar_Decorator_Uri extends Calendar_Decorator
/**
* 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
* @access public
*/
@@ -138,7 +169,9 @@ class Calendar_Decorator_Uri extends Calendar_Decorator
/**
* 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
* @access public
*/
@@ -146,6 +179,5 @@ class Calendar_Decorator_Uri extends Calendar_Decorator
{
return $this->Uri->next($this, $method);
}
}
?>

View File

@@ -1,28 +1,40 @@
<?php
/* 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
* @version $Id: Weekday.php,v 1.3 2004/08/16 12:25:15 hfuecks Exp $
* Contains the Calendar_Decorator_Weekday class
*
* 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
* <code>
* $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)
* echo $Weekday->thisWeekDay(); // Displays 5 - fifth day of week relative to Sun
* </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
{
@@ -64,84 +83,112 @@ class Calendar_Decorator_Weekday extends Calendar_Decorator
/**
* Constructs Calendar_Decorator_Weekday
* @param object subclass of Calendar
*
* @param object &$Calendar subclass of Calendar
*
* @access public
*/
function Calendar_Decorator_Weekday(& $Calendar)
function Calendar_Decorator_Weekday(&$Calendar)
{
parent::Calendar_Decorator($Calendar);
}
/**
* 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
* @access public
*/
function setFirstDay($firstDay) {
function setFirstDay($firstDay)
{
$this->firstDay = (int)$firstDay;
}
/**
* 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
*/
function prevWeekDay($format = 'int')
{
$ts = $this->calendar->prevDay('timestamp');
$Day = new Calendar_Day(2000,1,1);
$ts = $this->calendar->prevDay('timestamp');
$Day = new Calendar_Day(2000, 1, 1);
$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);
return $this->returnValue('Day', $format, $ts, $day);
}
/**
* 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
* @access public
*/
function thisWeekDay($format = 'int')
{
$ts = $this->calendar->thisDay('timestamp');
$day = $this->calendar->cE->getDayOfWeek($this->calendar->year,$this->calendar->month,$this->calendar->day);
$ts = $this->calendar->thisDay('timestamp');
$day = $this->calendar->cE->getDayOfWeek(
$this->calendar->year,
$this->calendar->month,
$this->calendar->day
);
$day = $this->adjustWeekScale($day);
return $this->returnValue('Day', $format, $ts, $day);
}
/**
* 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
* @access public
*/
function nextWeekDay($format = 'int')
{
$ts = $this->calendar->nextDay('timestamp');
$Day = new Calendar_Day(2000,1,1);
$ts = $this->calendar->nextDay('timestamp');
$Day = new Calendar_Day(2000, 1, 1);
$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);
return $this->returnValue('Day', $format, $ts, $day);
}
/**
* 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
* @access private
*/
function adjustWeekScale($dayOfWeek) {
function adjustWeekScale($dayOfWeek)
{
$dayOfWeek = $dayOfWeek - $this->firstDay;
if ( $dayOfWeek >= 0 ) {
if ($dayOfWeek >= 0) {
return $dayOfWeek;
} else {
return $this->calendar->cE->getDaysInWeek(
$this->calendar->year,$this->calendar->month,$this->calendar->day
) + $dayOfWeek;
$this->calendar->year,
$this->calendar->month,
$this->calendar->day
) + $dayOfWeek;
}
}
}

View File

@@ -1,28 +1,40 @@
<?php
/* 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
* @version $Id: Wrapper.php,v 1.2 2005/11/03 20:35:03 quipo Exp $
* Contains the Calendar_Decorator_Wrapper class
*
* 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
* @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
{
/**
* Constructs Calendar_Decorator_Wrapper
* @param object subclass of Calendar
*
* @param object &$Calendar subclass of Calendar
*
* @access public
*/
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
* @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
* @access public
*/
@@ -65,7 +88,7 @@ class Calendar_Decorator_Wrapper extends Calendar_Decorator
{
$Calendar = parent::fetch();
if ($Calendar) {
$ret =& new $decorator($Calendar);
$ret = new $decorator($Calendar);
} else {
$ret = false;
}
@@ -74,7 +97,9 @@ class Calendar_Decorator_Wrapper extends Calendar_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
* @access public
*/
@@ -82,7 +107,7 @@ class Calendar_Decorator_Wrapper extends Calendar_Decorator
{
$children = parent::fetchAll();
foreach ($children as $key => $Calendar) {
$children[$key] = & new $decorator($Calendar);
$children[$key] = new $decorator($Calendar);
}
return $children;
}

View File

@@ -1,32 +1,53 @@
<?php
/* 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
* @version $Id: Interface.php,v 1.5 2004/08/16 12:29:18 hfuecks Exp $
* Contains the Calendar_Engine_Interface class (interface)
*
* 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.
* 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
*/
class Calendar_Engine_Interface
@@ -36,7 +57,9 @@ class Calendar_Engine_Interface
* into human dates is only performed once per timestamp.
* Typically called "internally" by methods like stampToYear.
* Return value can vary, depending on the specific implementation
* @param int timestamp (depending on implementation)
*
* @param int $stamp timestamp (depending on implementation)
*
* @return mixed
* @access protected
*/
@@ -46,7 +69,9 @@ class Calendar_Engine_Interface
/**
* 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)
* @access protected
*/
@@ -56,7 +81,9 @@ class Calendar_Engine_Interface
/**
* 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)
* @access protected
*/
@@ -66,7 +93,9 @@ class Calendar_Engine_Interface
/**
* 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)
* @access protected
*/
@@ -76,7 +105,9 @@ class Calendar_Engine_Interface
/**
* 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)
* @access protected
*/
@@ -86,7 +117,9 @@ class Calendar_Engine_Interface
/**
* 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)
* @access protected
*/
@@ -96,7 +129,9 @@ class Calendar_Engine_Interface
/**
* 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)
* @access protected
*/
@@ -105,25 +140,27 @@ class Calendar_Engine_Interface
}
/**
* Returns a timestamp. Can be worth "caching" generated
* timestamps in a static variable, identified by the
* params this method accepts, to timestamp will only
* be calculated once.
* @param int year (e.g. 2003)
* @param int month (e.g. 9)
* @param int day (e.g. 13)
* @param int hour (e.g. 13)
* @param int minute (e.g. 34)
* @param int second (e.g. 53)
* Returns a timestamp. Can be worth "caching" generated timestamps in a
* static variable, identified by the params this method accepts,
* to timestamp will only be calculated once.
*
* @param int $y year (e.g. 2003)
* @param int $m month (e.g. 9)
* @param int $d day (e.g. 13)
* @param int $h hour (e.g. 13)
* @param int $i minute (e.g. 34)
* @param int $s second (e.g. 53)
*
* @return int (depends on implementation)
* @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
*
* @return int (e.g. 2037)
* @access protected
*/
@@ -133,6 +170,7 @@ class Calendar_Engine_Interface
/**
* The lower limit on years that the Calendar Engine can work with
*
* @return int (e.g 1902)
* @access protected
*/
@@ -142,7 +180,9 @@ class Calendar_Engine_Interface
/**
* 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)
* @access protected
*/
@@ -152,8 +192,10 @@ class Calendar_Engine_Interface
/**
* 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
* @access protected
*/
@@ -164,8 +206,10 @@ class Calendar_Engine_Interface
/**
* Returns numeric representation of the day of the week 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
* @access protected
*/
@@ -175,21 +219,25 @@ class Calendar_Engine_Interface
/**
* Returns the number of days in a week
* @param int year (2003)
* @param int month (9)
* @param int day (4)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
*
* @return int (e.g. 7)
* @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
* @param int year (2003)
* @param int month (9)
* @param int day (4)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
*
* @return int week number
* @access protected
*/
@@ -199,10 +247,12 @@ class Calendar_Engine_Interface
/**
* Returns the number of the week in the month, given a date
* @param int year (2003)
* @param int month (9)
* @param int day (4)
* @param int first day of the week (default: 1 - monday)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
* @param int $firstDay first day of the week (default: 1 - monday)
*
* @return int week number
* @access protected
*/
@@ -212,9 +262,10 @@ class Calendar_Engine_Interface
/**
* Returns the number of weeks in the month
* @param int year (2003)
* @param int month (9)
* @param int first day of the week (default: 1 - monday)
*
* @param int $y year (2003)
* @param int $m month (9)
*
* @return int weeks number
* @access protected
*/
@@ -224,9 +275,11 @@ class Calendar_Engine_Interface
/**
* Returns the number of the day of the week (0=sunday, 1=monday...)
* @param int year (2003)
* @param int month (9)
* @param int day (4)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
*
* @return int weekday number
* @access protected
*/
@@ -236,33 +289,41 @@ class Calendar_Engine_Interface
/**
* Returns the numeric values of the days of the week.
* @param int year (2003)
* @param int month (9)
* @param int day (4)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
*
* @return array list of numeric values of days in week, beginning 0
* @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
* member of the array returned from getWeekDays
* @param int year (2003)
* @param int month (9)
* @param int day (4)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
*
* @return int (e.g. 1 for Monday)
* @see getWeekDays
* @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>
* @param int (optional) day to get hours for
* 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 (e.g. 24)
* @access protected
*/
@@ -272,7 +333,12 @@ class Calendar_Engine_Interface
/**
* 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
* @access protected
*/
@@ -282,12 +348,30 @@ class Calendar_Engine_Interface
/**
* 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
* @access protected
*/
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
/* 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
* @version $Id: PearDate.php,v 1.8 2004/08/20 20:00:55 quipo Exp $
* Contains the Calendar_Engine_PearDate class
*
* 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
*/
@@ -31,7 +44,13 @@ require_once 'Date.php';
/**
* Performs calendar calculations based on the PEAR::Date class
* 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
*/
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
* Uses a static variable to prevent date() being used twice
* 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
* @access protected
*/
@@ -55,7 +76,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/**
* 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)
* @access protected
*/
@@ -67,7 +90,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/**
* 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)
* @access protected
*/
@@ -79,7 +104,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/**
* 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)
* @access protected
*/
@@ -91,7 +118,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/**
* 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)
* @access protected
*/
@@ -103,7 +132,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/**
* 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)
* @access protected
*/
@@ -115,7 +146,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/**
* 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)
* @access protected
*/
@@ -127,12 +160,14 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/**
* Returns a iso-8601 datetime
* @param int year (2003)
* @param int month (9)
* @param int day (13)
* @param int hour (13)
* @param int minute (34)
* @param int second (53)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (13)
* @param int $h hour (13)
* @param int $i minute (34)
* @param int $s second (53)
*
* @return string iso-8601 datetime
* @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)
* @param int year (2003)
* @param int month (9)
* @param int day (13)
* @param int hour (13)
* @param int minute (34)
* @param int second (53)
*
* @param int &$y year (2003)
* @param int &$m month (9)
* @param int &$d day (13)
* @param int &$h hour (13)
* @param int &$i minute (34)
* @param int &$s second (53)
*
* @return void
* @access protected
*/
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
*
* @return int 9999
* @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
*
* @return int 0
* @access protected
*/
@@ -229,6 +269,9 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/**
* Returns the number of months in a year
*
* @param int $y year
*
* @return int (12)
* @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
* @param int year (2003)
* @param int month (9)
*
* @param int $y year (2003)
* @param int $m month (9)
*
* @return int days in month
* @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,
* 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
* @access protected
*/
@@ -264,36 +311,44 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/**
* Returns the number of days in a week
* @param int year (2003)
* @param int month (9)
* @param int day (4)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
*
* @return int (7)
* @access protected
*/
function getDaysInWeek($y=NULL, $m=NULL, $d=NULL)
function getDaysInWeek($y=null, $m=null, $d=null)
{
return 7;
}
/**
* Returns the number of the week in the year (ISO-8601), given a date
* @param int year (2003)
* @param int month (9)
* @param int day (4)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
*
* @return int week number
* @access protected
*/
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
* @param int year (2003)
* @param int month (9)
* @param int day (4)
* @param int first day of the week (default: monday)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
* @param int $firstDay first day of the week (default: monday)
*
* @return int week number
* @access protected
*/
@@ -311,9 +366,11 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/**
* Returns the number of weeks in the month
* @param int year (2003)
* @param int month (9)
* @param int first day of the week (default: monday)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $firstDay first day of the week (default: monday)
*
* @return int weeks number
* @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...)
* @param int year (2003)
* @param int month (9)
* @param int day (4)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
*
* @return int weekday number
* @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
* @param int year (2003)
* @param int month (9)
* @param int day (4)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
*
* @return array (0, 1, 2, 3, 4, 5, 6) 1 = Monday
* @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);
}
/**
* Returns the default first day of the week
* @param int year (2003)
* @param int month (9)
* @param int day (4)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
*
* @return int (default 1 = Monday)
* @access protected
*/
function getFirstDayOfWeek($y=NULL, $m=NULL, $d=NULL)
function getFirstDayOfWeek($y=null, $m=null, $d=null)
{
return 1;
}
/**
* 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)
* @access protected
*/
@@ -386,6 +454,12 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/**
* 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)
* @access protected
*/
@@ -396,6 +470,13 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
/**
* 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)
* @access protected
*/
@@ -403,5 +484,26 @@ class Calendar_Engine_PearDate /* implements Calendar_Engine_Interface */
{
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
/* 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
* @version $Id: UnixTS.php,v 1.9 2004/08/20 20:00:55 quipo Exp $
* Contains the Calendar_Engine_UnixTS class
*
* 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
* 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 */
{
@@ -48,7 +67,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
* </pre>
* Uses a static variable to prevent date() being used twice
* for a date which is already known
* @param int Unix timestamp
*
* @param int $stamp Unix timestamp
*
* @return array
* @access protected
*/
@@ -56,7 +77,7 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
{
static $stamps = array();
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");
}
return $stamps[$stamp];
@@ -64,7 +85,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/**
* Returns a numeric year given a timestamp
* @param int Unix timestamp
*
* @param int $stamp Unix timestamp
*
* @return int year (e.g. 2003)
* @access protected
*/
@@ -76,7 +99,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/**
* Returns a numeric month given a timestamp
* @param int Unix timestamp
*
* @param int $stamp Unix timestamp
*
* @return int month (e.g. 9)
* @access protected
*/
@@ -88,7 +113,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/**
* Returns a numeric day given a timestamp
* @param int Unix timestamp
*
* @param int $stamp Unix timestamp
*
* @return int day (e.g. 15)
* @access protected
*/
@@ -100,7 +127,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/**
* Returns a numeric hour given a timestamp
* @param int Unix timestamp
*
* @param int $stamp Unix timestamp
*
* @return int hour (e.g. 13)
* @access protected
*/
@@ -112,7 +141,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/**
* Returns a numeric minute given a timestamp
* @param int Unix timestamp
*
* @param int $stamp Unix timestamp
*
* @return int minute (e.g. 34)
* @access protected
*/
@@ -124,7 +155,9 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/**
* Returns a numeric second given a timestamp
* @param int Unix timestamp
*
* @param int $stamp Unix timestamp
*
* @return int second (e.g. 51)
* @access protected
*/
@@ -136,19 +169,21 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/**
* Returns a timestamp
* @param int year (2003)
* @param int month (9)
* @param int day (13)
* @param int hour (13)
* @param int minute (34)
* @param int second (53)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (13)
* @param int $h hour (13)
* @param int $i minute (34)
* @param int $s second (53)
*
* @return int Unix timestamp
* @access protected
*/
function dateToStamp($y, $m, $d, $h=0, $i=0, $s=0)
{
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);
}
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
*
* @return int (2037)
* @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
*
* @return int (1970 if it's Windows and 1902 for all other OSs)
* @access protected
*/
@@ -176,8 +213,11 @@ class Calendar_Engine_UnixTS /* implements Calendar_Engine_Interface */
/**
* Returns the number of months in a year
*
* @param int $y year
*
* @return int (12)
* @access protected
* @access protected
*/
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
* @param int year (2003)
* @param int month (9)
*
* @param int $y year (2003)
* @param int $m month (9)
*
* @return int days in month
* @access protected
*/
function getDaysInMonth($y, $m)
{
$stamp = Calendar_Engine_UnixTS::dateToStamp($y,$m,1);
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
$stamp = Calendar_Engine_UnixTS::dateToStamp($y, $m, 1);
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
return $date[6];
}
/**
* Returns numeric representation of the day of the week 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 from 0 to 6
* @access protected
*/
function getFirstDayInMonth($y, $m)
{
$stamp = Calendar_Engine_UnixTS::dateToStamp($y,$m,1);
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
$stamp = Calendar_Engine_UnixTS::dateToStamp($y, $m, 1);
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
return $date[8];
}
/**
* Returns the number of days in a week
* @param int year (2003)
* @param int month (9)
* @param int day (4)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
*
* @return int (7)
* @access protected
*/
function getDaysInWeek($y=NULL, $m=NULL, $d=NULL)
function getDaysInWeek($y=null, $m=null, $d=null)
{
return 7;
}
/**
* Returns the number of the week in the year (ISO-8601), given a date
* @param int year (2003)
* @param int month (9)
* @param int day (4)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
*
* @return int week number
* @access protected
*/
function getWeekNInYear($y, $m, $d)
{
$stamp = Calendar_Engine_UnixTS::dateToStamp($y,$m,$d);
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
$stamp = Calendar_Engine_UnixTS::dateToStamp($y, $m, $d);
$date = Calendar_Engine_UnixTS::stampCollection($stamp);
return $date[7];
}
/**
* Returns the number of the week in the month, given a date
* @param int year (2003)
* @param int month (9)
* @param int day (4)
* @param int first day of the week (default: monday)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
* @param int $firstDay first day of the week (default: monday)
*
* @return int week number
* @access protected
*/
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;
while (@date('w', @mktime(0, 0, 0, $m, $end_of_week, $y)) != $weekEnd) {
++$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
* @param int year (2003)
* @param int month (9)
* @param int first day of the week (default: monday)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $firstDay first day of the week (default: monday)
*
* @return int weeks number
* @access protected
*/
function getWeeksInMonth($y, $m, $firstDay=1)
function getWeeksInMonth($y, $m, $firstDay = 1)
{
$FDOM = $this->getFirstDayInMonth($y, $m);
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...)
* @param int year (2003)
* @param int month (9)
* @param int day (4)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
*
* @return int weekday number
* @access protected
*/
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);
return $date[8];
}
/**
* Returns a list of integer days of the week beginning 0
* @param int year (2003)
* @param int month (9)
* @param int day (4)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
*
* @return array (0,1,2,3,4,5,6) 1 = Monday
* @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);
}
/**
* Returns the default first day of the week
* @param int year (2003)
* @param int month (9)
* @param int day (4)
*
* @param int $y year (2003)
* @param int $m month (9)
* @param int $d day (4)
*
* @return int (default 1 = Monday)
* @access protected
*/
function getFirstDayOfWeek($y=NULL, $m=NULL, $d=NULL)
function getFirstDayOfWeek($y=null, $m=null, $d=null)
{
return 1;
}
/**
* 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)
* @access protected
*/
function getHoursInDay($y=null,$m=null,$d=null)
function getHoursInDay($y=null, $m=null, $d=null)
{
return 24;
}
/**
* 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)
* @access protected
*/
function getMinutesInHour($y=null,$m=null,$d=null,$h=null)
function getMinutesInHour($y=null, $m=null, $d=null, $h=null)
{
return 60;
}
/**
* 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)
* @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;
}
/**
* 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
/* 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
* @version $Id: Factory.php,v 1.3 2005/10/22 10:08:47 quipo Exp $
* Contains the Calendar_Factory class
*
* 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>
* 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)
* @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
*/
class Calendar_Factory
{
/**
* Creates a calendar object given the type and units
* @param string class of calendar object to create
* @param int year
* @param int month
* @param int day
* @param int hour
* @param int minute
* @param int second
*
* @param string $type class of calendar object to create
* @param int $y year
* @param int $m month
* @param int $d day
* @param int $h hour
* @param int $i minute
* @param int $s second
*
* @return object subclass of Calendar
* @access public
* @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;
switch ($type) {
case 'Day':
require_once CALENDAR_ROOT.'Day.php';
return new Calendar_Day($y,$m,$d);
case 'Month':
// Set default state for which month type to build
if (!defined('CALENDAR_MONTH_STATE')) {
define('CALENDAR_MONTH_STATE', CALENDAR_USE_MONTH);
}
switch (CALENDAR_MONTH_STATE) {
case CALENDAR_USE_MONTH_WEEKDAYS:
require_once CALENDAR_ROOT.'Month/Weekdays.php';
$class = 'Calendar_Month_Weekdays';
break;
case CALENDAR_USE_MONTH_WEEKS:
require_once CALENDAR_ROOT.'Month/Weeks.php';
$class = 'Calendar_Month_Weeks';
break;
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);
case 'Day':
include_once CALENDAR_ROOT.'Day.php';
return new Calendar_Day($y, $m, $d);
case 'Month':
// Set default state for which month type to build
if (!defined('CALENDAR_MONTH_STATE')) {
define('CALENDAR_MONTH_STATE', CALENDAR_USE_MONTH);
}
switch (CALENDAR_MONTH_STATE) {
case CALENDAR_USE_MONTH_WEEKDAYS:
include_once CALENDAR_ROOT.'Month/Weekdays.php';
$class = 'Calendar_Month_Weekdays';
break;
case CALENDAR_USE_MONTH_WEEKS:
include_once CALENDAR_ROOT.'Month/Weeks.php';
$class = 'Calendar_Month_Weeks';
break;
case CALENDAR_USE_MONTH:
default:
require_once 'PEAR.php';
PEAR::raiseError(
'Calendar_Factory::create() unrecognised type: '.$type, null, PEAR_ERROR_TRIGGER,
E_USER_NOTICE, 'Calendar_Factory::create()');
return false;
include_once CALENDAR_ROOT.'Month.php';
$class = 'Calendar_Month';
break;
}
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
* @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
* @access public
* @static
*/
function & createByTimestamp($type, $stamp)
static function & createByTimestamp($type, $stamp)
{
$cE = & Calendar_Engine_Factory::getEngine();
$y = $cE->stampToYear($stamp);
$m = $cE->stampToMonth($stamp);
$d = $cE->stampToDay($stamp);
$h = $cE->stampToHour($stamp);
$i = $cE->stampToMinute($stamp);
$s = $cE->stampToSecond($stamp);
$cE = & Calendar_Engine_Factory::getEngine();
$y = $cE->stampToYear($stamp);
$m = $cE->stampToMonth($stamp);
$d = $cE->stampToDay($stamp);
$h = $cE->stampToHour($stamp);
$i = $cE->stampToMinute($stamp);
$s = $cE->stampToSecond($stamp);
$cal = Calendar_Factory::create($type, $y, $m, $d, $h, $i, $s);
return $cal;
}

View File

@@ -1,27 +1,39 @@
<?php
/* 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
* @version $Id: Hour.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
* Contains the Calendar_Hour class
*
* 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
* <code>
* 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
* while ($Minute = & $Hour->fetch()) {
* echo $Minute->thisMinute().'<br />';
* }
* </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
{
/**
* Constructs Calendar_Hour
* @param int year e.g. 2003
* @param int month e.g. 5
* @param int day e.g. 11
* @param int hour e.g. 13
*
* @param int $y year e.g. 2003
* @param int $m month e.g. 5
* @param int $d day e.g. 11
* @param int $h hour e.g. 13
*
* @access public
*/
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
* @param array (optional) Calendar_Minute objects representing selected dates
*
* @param array $sDates (optional) Calendar_Minute objects representing selected dates
*
* @return boolean
* @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,
$this->hour);
for ($i=0; $i < $mIH; $i++) {
$this->children[$i]=
$this->children[$i] =
new Calendar_Minute($this->year, $this->month, $this->day,
$this->hour, $i);
}
@@ -89,7 +111,9 @@ class Calendar_Hour extends Calendar
/**
* Called from build()
* @param array
*
* @param array $sDates Calendar_Minute objects representing selected dates
*
* @return void
* @access private
*/

View File

@@ -1,27 +1,39 @@
<?php
/* 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
* @version $Id: Minute.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
* Contains the Calendar_Minute class
*
* 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
* <code>
* 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
* while ($Second = & $Minute->fetch()) {
* echo $Second->thisSecond().'<br />';
* }
* </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
{
/**
* Constructs Minute
* @param int year e.g. 2003
* @param int month e.g. 5
* @param int day e.g. 11
* @param int hour e.g. 13
* @param int minute e.g. 31
*
* @param int $y year e.g. 2003
* @param int $m month e.g. 5
* @param int $d day e.g. 11
* @param int $h hour e.g. 13
* @param int $i minute e.g. 31
*
* @access public
*/
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
* @param array (optional) Calendar_Second objects representing selected dates
*
* @param array $sDates (optional) Calendar_Second objects representing selected dates
*
* @return boolean
* @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,
$this->day, $this->hour, $this->minute);
for ($i=0; $i < $sIM; $i++) {
@@ -89,7 +111,9 @@ class Calendar_Minute extends Calendar
/**
* Called from build()
* @param array
*
* @param array $sDates Calendar_Second objects representing selected dates
*
* @return void
* @access private
*/

View File

@@ -1,27 +1,39 @@
<?php
/* 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
* @version $Id: Month.php,v 1.3 2005/10/22 10:10:26 quipo Exp $
* Contains the Calendar_Month class
*
* 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
* <code>
* 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
* while ($Day = & $Month->fetch()) {
* echo $Day->thisDay().'<br />';
* }
* </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
{
/**
* 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]
*
* @access public
*/
function Calendar_Month($y, $m, $firstDay=null)
{
Calendar::Calendar($y, $m);
parent::Calendar($y, $m);
$this->firstDay = $this->defineFirstDayOfWeek($firstDay);
}
/**
* Builds Day objects for this Month. Creates as many Calendar_Day objects
* 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
* @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);
for ($i=1; $i<=$daysInMonth; $i++) {
$this->children[$i] = new Calendar_Day($this->year, $this->month, $i);
@@ -87,7 +109,9 @@ class Calendar_Month extends Calendar
/**
* Called from build()
* @param array
*
* @param array $sDates Calendar_Day objects representing selected dates
*
* @return void
* @access private
*/

View File

@@ -1,27 +1,39 @@
<?php
/* 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
* @version $Id: Weekdays.php,v 1.4 2005/10/22 10:28:49 quipo Exp $
* Contains the Calendar_Month_Weekdays class
*
* 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>
* <code>
* 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
* while ($Day = & $Month->fetch()) {
* if ($Day->isFirst()) {
@@ -62,8 +74,14 @@ require_once CALENDAR_ROOT.'Month.php';
* }
* }
* </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
{
@@ -83,31 +101,35 @@ class Calendar_Month_Weekdays extends Calendar_Month
/**
* Constructs Calendar_Month_Weekdays
* @param int year e.g. 2003
* @param int month e.g. 5
* @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
*
* @param int $y year e.g. 2003
* @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
*/
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
* with empty cells if the first day of the week does not fall on the first
* 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_Base::isFirst()
* @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';
$this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay);
include_once CALENDAR_ROOT.'Table/Helper.php';
$this->tableHelper = new Calendar_Table_Helper($this, $this->firstDay);
Calendar_Month::build($sDates);
$this->buildEmptyDaysBefore();
$this->shiftDays();
@@ -118,6 +140,7 @@ class Calendar_Month_Weekdays extends Calendar_Month
/**
* Prepends empty days before the real days in the month
*
* @return void
* @access private
*/
@@ -138,12 +161,13 @@ class Calendar_Month_Weekdays extends Calendar_Month
/**
* Shifts the array of children forward, if necessary
*
* @return void
* @access private
*/
function shiftDays()
{
if (isset ($this->children[0])) {
if (isset($this->children[0])) {
array_unshift($this->children, null);
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
*
* @return void
* @access private
*/
function buildEmptyDaysAfter()
{
$eAfter = $this->tableHelper->getEmptyDaysAfter();
$sDOM = $this->tableHelper->getNumTableDaysInMonth();
for ($i = 1; $i <= $sDOM-$eAfter; $i++) {
$sDOM = $this->tableHelper->getNumTableDaysInMonth();
for ($i=1; $i <= $sDOM-$eAfter; $i++) {
$Day = new Calendar_Day($this->year, $this->month+1, $i);
$Day->setEmpty();
$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
* built Calendar_Day children
*
* @return void
* @access private
*/
function setWeekMarkers()
{
$dIW = $this->cE->getDaysInWeek(
$dIW = $this->cE->getDaysInWeek(
$this->thisYear(),
$this->thisMonth(),
$this->thisDay()

View File

@@ -1,28 +1,40 @@
<?php
/* 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
* @version $Id: Weeks.php,v 1.3 2005/10/22 10:28:49 quipo Exp $
* Contains the Calendar_Month_Weeks class
*
* 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
* <code>
* 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
* while ($Week = & $Month->fetch()) {
* echo $Week->thisWeek().'<br />';
* }
* </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
{
@@ -74,34 +93,40 @@ class Calendar_Month_Weeks extends Calendar_Month
/**
* Constructs Calendar_Month_Weeks
* @param int year e.g. 2003
* @param int month e.g. 5
* @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
*
* @param int $y year e.g. 2003
* @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
*/
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_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
* @access public
*/
function build($sDates=array())
function build($sDates = array())
{
require_once CALENDAR_ROOT.'Table/Helper.php';
$this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay);
require_once CALENDAR_ROOT.'Week.php';
include_once CALENDAR_ROOT.'Table/Helper.php';
$this->tableHelper = new Calendar_Table_Helper($this, $this->firstDay);
include_once CALENDAR_ROOT.'Week.php';
$numWeeks = $this->tableHelper->getNumWeeks();
for ($i=1, $d=1; $i<=$numWeeks; $i++,
$d+=$this->cE->getDaysInWeek(
$this->thisYear(),
$this->thisMonth(),
$this->thisDay()) ) {
$this->thisDay()
)
) {
$this->children[$i] = new Calendar_Week(
$this->year, $this->month, $d, $this->tableHelper->getFirstDay());
}
@@ -118,7 +143,9 @@ class Calendar_Month_Weeks extends Calendar_Month
/**
* Called from build()
* @param array
*
* @param array $sDates Calendar_Week objects representing selected dates
*
* @return void
* @access private
*/

View File

@@ -1,27 +1,39 @@
<?php
/* 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
* @version $Id: Second.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
* Contains the Calendar_Second class
*
* 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 />
* <b>Note:</b> Seconds do not build other objects
* 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
{
/**
* Constructs Second
* @param int year e.g. 2003
* @param int month e.g. 5
* @param int day e.g. 11
* @param int hour e.g. 13
* @param int minute e.g. 31
* @param int second e.g. 45
*
* @param int $y year e.g. 2003
* @param int $m month e.g. 5
* @param int $d day e.g. 11
* @param int $h hour e.g. 13
* @param int $i minute e.g. 31
* @param int $s second e.g. 45
*/
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
*
* @return NULL
*/
function build()
@@ -70,6 +91,7 @@ class Calendar_Second extends Calendar
/**
* Overwrite fetch
*
* @return NULL
*/
function fetch()
@@ -79,6 +101,7 @@ class Calendar_Second extends Calendar
/**
* Overwrite fetchAll
*
* @return NULL
*/
function fetchAll()
@@ -88,6 +111,7 @@ class Calendar_Second extends Calendar
/**
* Overwrite size
*
* @return NULL
*/
function size()

View File

@@ -1,34 +1,52 @@
<?php
/* 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
* @version $Id: Helper.php,v 1.5 2005/10/22 09:51:53 quipo Exp $
* Contains the Calendar_Decorator_Wrapper class
*
* 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
* 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
{
@@ -90,8 +108,10 @@ class 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
*/
function Calendar_Table_Helper(& $calendar, $firstDay=null)
@@ -112,6 +132,7 @@ class Calendar_Table_Helper
/**
* Constructs $this->daysOfWeek based on $this->firstDay
*
* @return void
* @access private
*/
@@ -140,6 +161,7 @@ class Calendar_Table_Helper
/**
* Constructs $this->daysOfMonth
*
* @return void
* @access private
*/
@@ -174,9 +196,10 @@ class Calendar_Table_Helper
/**
* Returns the first day of the month
* @see Calendar_Engine_Interface::getFirstDayOfWeek()
*
* @return int
* @access protected
* @see Calendar_Engine_Interface::getFirstDayOfWeek()
*/
function getFirstDay()
{
@@ -185,6 +208,7 @@ class Calendar_Table_Helper
/**
* Returns the order array of days in a week
*
* @return int
* @access protected
*/
@@ -195,6 +219,7 @@ class Calendar_Table_Helper
/**
* Returns the number of tabular weeks in a month
*
* @return int
* @access protected
*/
@@ -205,6 +230,7 @@ class Calendar_Table_Helper
/**
* Returns the number of real days + empty days
*
* @return int
* @access protected
*/
@@ -215,6 +241,7 @@ class Calendar_Table_Helper
/**
* Returns the number of empty days before the real days begin
*
* @return int
* @access protected
*/
@@ -225,6 +252,7 @@ class Calendar_Table_Helper
/**
* Returns the index of the last real day in the month
*
* @todo Potential performance optimization with static
* @return int
* @access protected
@@ -232,17 +260,18 @@ class Calendar_Table_Helper
function getEmptyDaysAfter()
{
// Causes bug when displaying more than one month
// static $index;
// if (!isset($index)) {
//static $index;
//if (!isset($index)) {
$index = $this->getEmptyDaysBefore() + $this->cE->getDaysInMonth(
$this->calendar->thisYear(), $this->calendar->thisMonth());
// }
//}
return $index;
}
/**
* Returns the index of the last real day in the month, relative to the
* beginning of the tabular week it is part of
*
* @return int
* @access protected
*/
@@ -254,11 +283,18 @@ class Calendar_Table_Helper
$this->calendar->thisYear(),
$this->calendar->thisMonth(),
$this->calendar->thisDay()
) * ($this->numWeeks-1) );
) * ($this->numWeeks-1));
}
/**
* 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)
{

View File

@@ -1,28 +1,45 @@
<?php
/* 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.2 2004/08/16 13:13:09 hfuecks Exp $
//
/**
* Contains the Calendar_Util_Textual class
*
* 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 247250 2007-11-28 19:42:01Z quipo $
* @link http://pear.php.net/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
* 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
{
/**
* 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
* @access public
* @static
*/
function monthNames($format='long')
function monthNames($format = 'long')
{
$formats = array('one'=>'%b', 'two'=>'%b', 'short'=>'%b', 'long'=>'%B');
if (!array_key_exists($format,$formats)) {
$formats = array(
'one' => '%b',
'two' => '%b',
'short' => '%b',
'long' => '%B',
);
if (!array_key_exists($format, $formats)) {
$format = 'long';
}
$months = array();
@@ -65,11 +96,11 @@ class Calendar_Util_Textual
$stamp = mktime(0, 0, 0, $i, 1, 2003);
$month = strftime($formats[$format], $stamp);
switch($format) {
case 'one':
$month = substr($month, 0, 1);
case 'one':
$month = substr($month, 0, 1);
break;
case 'two':
$month = substr($month, 0, 2);
case 'two':
$month = substr($month, 0, 2);
break;
}
$months[$i] = $month;
@@ -79,15 +110,22 @@ class Calendar_Util_Textual
/**
* 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
* @access public
* @static
*/
function weekdayNames($format='long')
function weekdayNames($format = 'long')
{
$formats = array('one'=>'%a', 'two'=>'%a', 'short'=>'%a', 'long'=>'%A');
if (!array_key_exists($format,$formats)) {
$formats = array(
'one' => '%a',
'two' => '%a',
'short' => '%a',
'long' => '%A',
);
if (!array_key_exists($format, $formats)) {
$format = 'long';
}
$days = array();
@@ -95,11 +133,11 @@ class Calendar_Util_Textual
$stamp = mktime(0, 0, 0, 11, $i+2, 2003);
$day = strftime($formats[$format], $stamp);
switch($format) {
case 'one':
$day = substr($day, 0, 1);
case 'one':
$day = substr($day, 0, 1);
break;
case 'two':
$day = substr($day, 0, 2);
case 'two':
$day = substr($day, 0, 2);
break;
}
$days[$i] = $day;
@@ -109,13 +147,15 @@ class Calendar_Util_Textual
/**
* 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
* @access public
* @static
*/
function prevMonthName($Calendar, $format='long')
function prevMonthName($Calendar, $format = 'long')
{
$months = Calendar_Util_Textual::monthNames($format);
return $months[$Calendar->prevMonth()];
@@ -123,13 +163,15 @@ class Calendar_Util_Textual
/**
* 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
* @access public
* @static
*/
function thisMonthName($Calendar, $format='long')
function thisMonthName($Calendar, $format = 'long')
{
$months = Calendar_Util_Textual::monthNames($format);
return $months[$Calendar->thisMonth()];
@@ -137,13 +179,15 @@ class Calendar_Util_Textual
/**
* 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
* @access public
* @static
*/
function nextMonthName($Calendar, $format='long')
function nextMonthName($Calendar, $format = 'long')
{
$months = Calendar_Util_Textual::monthNames($format);
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
* <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
* @access public
* @static
*/
function prevDayName($Calendar, $format='long')
function prevDayName($Calendar, $format = 'long')
{
$days = Calendar_Util_Textual::weekdayNames($format);
$stamp = $Calendar->prevDay('timestamp');
$cE = $Calendar->getEngine();
require_once 'Date/Calc.php';
include_once 'Date/Calc.php';
$day = Date_Calc::dayOfWeek($cE->stampToDay($stamp),
$cE->stampToMonth($stamp), $cE->stampToYear($stamp));
return $days[$day];
@@ -172,8 +218,10 @@ class Calendar_Util_Textual
/**
* Returns textual representation of the day of week of the decorated calendar object
* <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
* @access public
* @static
@@ -181,15 +229,17 @@ class Calendar_Util_Textual
function thisDayName($Calendar, $format='long')
{
$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());
return $days[$day];
}
/**
* 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
* @access public
* @static
@@ -199,7 +249,7 @@ class Calendar_Util_Textual
$days = Calendar_Util_Textual::weekdayNames($format);
$stamp = $Calendar->nextDay('timestamp');
$cE = $Calendar->getEngine();
require_once 'Date/Calc.php';
include_once 'Date/Calc.php';
$day = Date_Calc::dayOfWeek($cE->stampToDay($stamp),
$cE->stampToMonth($stamp), $cE->stampToYear($stamp));
return $days[$day];
@@ -209,21 +259,36 @@ class Calendar_Util_Textual
* Returns the days of the week using the order defined in the decorated
* calendar object. Only useful for Calendar_Month_Weekdays, Calendar_Month_Weeks
* 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
* @access public
* @static
*/
function orderedWeekdays($Calendar, $format='long')
function orderedWeekdays($Calendar, $format = 'long')
{
$days = Calendar_Util_Textual::weekdayNames($format);
// Not so good - need methods to access this information perhaps...
if (isset($Calendar->tableHelper)) {
$ordereddays = $Calendar->tableHelper->daysOfWeek;
$ordereddays = $Calendar->tableHelper->getDaysOfWeek();
} 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);

View File

@@ -1,35 +1,47 @@
<?php
/* 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
* @version $Id: Uri.php,v 1.1 2004/08/16 09:03:55 hfuecks Exp $
* Contains the Calendar_Util_Uri class
*
* 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 />
* <code>
* $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,'day'); // Displays year=2003&amp;month=10&amp;day=22
* $Uri->seperator = '/';
@@ -37,8 +49,15 @@
* echo $Uri->prev($Day,'month'); // Displays 2003/10
* echo $Uri->prev($Day,'day'); // Displays 2003/10/22
* </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
{
@@ -69,12 +88,14 @@ class Calendar_Util_Uri
/**
* Constructs Calendar_Decorator_Uri
* 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 (optional) URI fragment for day
* @param string (optional) URI fragment for hour
* @param string (optional) URI fragment for minute
* @param string (optional) URI fragment for second
*
* @param string $y URI fragment for year
* @param string $m (optional) URI fragment for month
* @param string $d (optional) URI fragment for day
* @param string $h (optional) URI fragment for hour
* @param string $i (optional) URI fragment for minute
* @param string $s (optional) URI fragment for second
*
* @access public
*/
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
* @param string URI fragment for year
* @param string (optional) URI fragment for month
* @param string (optional) URI fragment for day
* @param string (optional) URI fragment for hour
* @param string (optional) URI fragment for minute
* @param string (optional) URI fragment for second
*
* @param string $y URI fragment for year
* @param string $m (optional) URI fragment for month
* @param string $d (optional) URI fragment for day
* @param string $h (optional) URI fragment for hour
* @param string $i (optional) URI fragment for minute
* @param string $s (optional) URI fragment for second
*
* @return void
* @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($m)) $this->uris['Month'] = $m;
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
* @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
* @access public
*/
@@ -118,22 +144,26 @@ class Calendar_Util_Uri
/**
* 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
* @access public
*/
function this($Calendar, $unit)
{
$method = 'this'.$unit;
$method = 'this'.$unit;
$stamp = $Calendar->{$method}('timestamp');
return $this->buildUriString($Calendar, $method, $stamp);
}
/**
* 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
* @access public
*/
@@ -146,8 +176,11 @@ class Calendar_Util_Uri
/**
* 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
* @access private
*/
@@ -159,7 +192,9 @@ class Calendar_Util_Uri
foreach ($this->uris as $unit => $uri) {
$call = 'stampTo'.$unit;
$uriString .= $separator;
if (!$this->scalar) $uriString .= $uri.'=';
if (!$this->scalar) {
$uriString .= $uri.'=';
}
$uriString .= $cE->{$call}($stamp);
$separator = $this->separator;
}

View File

@@ -1,27 +1,39 @@
<?php
/* 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
* @version $Id: Validator.php,v 1.1 2004/05/24 22:25:42 quipo Exp $
* Contains the Calendar_Validator class
*
* 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
* can be obtained from any data object using the getValidator method
* @see Calendar::getValidator()
* @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
* @see Calendar::getValidator()
* @access public
*/
class Calendar_Validator
{
@@ -66,17 +84,20 @@ class Calendar_Validator
/**
* Constructs Calendar_Validator
* @param object subclass of Calendar
*
* @param object &$calendar subclass of Calendar
*
* @access public
*/
function Calendar_Validator(& $calendar)
function Calendar_Validator(&$calendar)
{
$this->calendar = & $calendar;
$this->cE = & $calendar->getEngine();
$this->cE = & $calendar->getEngine();
}
/**
* Calls all the other isValidXXX() methods in the validator
*
* @return boolean
* @access public
*/
@@ -84,7 +105,7 @@ class Calendar_Validator
{
$checks = array('isValidYear', 'isValidMonth', 'isValidDay',
'isValidHour', 'isValidMinute', 'isValidSecond');
$valid = true;
$valid = true;
foreach ($checks as $check) {
if (!$this->{$check}()) {
$valid = false;
@@ -95,15 +116,16 @@ class Calendar_Validator
/**
* Check whether this is a valid year
*
* @return boolean
* @access public
*/
function isValidYear()
{
$y = $this->calendar->thisYear();
$y = $this->calendar->thisYear();
$min = $this->cE->getMinYears();
if ($min > $y) {
$this->errors[] = new Calendar_Validation_Error(
$this->errors[] = new Calendar_Validation_Error(
'Year', $y, CALENDAR_VALUE_TOOSMALL.$min);
return false;
}
@@ -118,12 +140,13 @@ class Calendar_Validator
/**
* Check whether this is a valid month
*
* @return boolean
* @access public
*/
function isValidMonth()
{
$m = $this->calendar->thisMonth();
$m = $this->calendar->thisMonth();
$min = 1;
if ($min > $m) {
$this->errors[] = new Calendar_Validation_Error(
@@ -141,12 +164,13 @@ class Calendar_Validator
/**
* Check whether this is a valid day
*
* @return boolean
* @access public
*/
function isValidDay()
{
$d = $this->calendar->thisDay();
$d = $this->calendar->thisDay();
$min = 1;
if ($min > $d) {
$this->errors[] = new Calendar_Validation_Error(
@@ -154,7 +178,9 @@ class Calendar_Validator
return false;
}
$max = $this->cE->getDaysInMonth(
$this->calendar->thisYear(), $this->calendar->thisMonth());
$this->calendar->thisYear(),
$this->calendar->thisMonth()
);
if ($d > $max) {
$this->errors[] = new Calendar_Validation_Error(
'Day', $d, CALENDAR_VALUE_TOOLARGE.$max);
@@ -165,12 +191,13 @@ class Calendar_Validator
/**
* Check whether this is a valid hour
*
* @return boolean
* @access public
*/
function isValidHour()
{
$h = $this->calendar->thisHour();
$h = $this->calendar->thisHour();
$min = 0;
if ($min > $h) {
$this->errors[] = new Calendar_Validation_Error(
@@ -188,12 +215,13 @@ class Calendar_Validator
/**
* Check whether this is a valid minute
*
* @return boolean
* @access public
*/
function isValidMinute()
{
$i = $this->calendar->thisMinute();
$i = $this->calendar->thisMinute();
$min = 0;
if ($min > $i) {
$this->errors[] = new Calendar_Validation_Error(
@@ -211,12 +239,13 @@ class Calendar_Validator
/**
* Check whether this is a valid second
*
* @return boolean
* @access public
*/
function isValidSecond()
{
$s = $this->calendar->thisSecond();
$s = $this->calendar->thisSecond();
$min = 0;
if ($min > $s) {
$this->errors[] = new Calendar_Validation_Error(
@@ -234,12 +263,13 @@ class Calendar_Validator
/**
* Iterates over any validation errors
*
* @return mixed either Calendar_Validation_Error or false
* @access public
*/
function fetch()
{
$error = each ($this->errors);
$error = each($this->errors);
if ($error) {
return $error['value'];
} else {
@@ -251,9 +281,15 @@ class Calendar_Validator
/**
* For Validation Error messages
* @see Calendar::fetch()
* @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
* @see Calendar::fetch()
* @access public
*/
class Calendar_Validation_Error
{
@@ -280,12 +316,14 @@ class 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 Validation error message
*
* @param string $unit Date unit (e.g. month,hour,second)
* @param int $value Value of unit which failed test
* @param string $message Validation error message
*
* @access protected
*/
function Calendar_Validation_Error($unit,$value,$message)
function Calendar_Validation_Error($unit, $value, $message)
{
$this->unit = $unit;
$this->value = $value;
@@ -294,6 +332,7 @@ class Calendar_Validation_Error
/**
* Returns the Date unit
*
* @return string
* @access public
*/
@@ -304,6 +343,7 @@ class Calendar_Validation_Error
/**
* Returns the value of the unit
*
* @return int
* @access public
*/
@@ -314,6 +354,7 @@ class Calendar_Validation_Error
/**
* Returns the validation error message
*
* @return string
* @access public
*/
@@ -324,6 +365,7 @@ class Calendar_Validation_Error
/**
* Returns a string containing the unit, value and error message
*
* @return string
* @access public
*/

View File

@@ -1,28 +1,40 @@
<?php
/* 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: Week.php,v 1.7 2005/10/22 10:26:49 quipo Exp $
//
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* @package Calendar
* @version $Id: Week.php,v 1.7 2005/10/22 10:26:49 quipo Exp $
* Contains the Calendar_Week class
*
* 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>
* <code>
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Week.php';
* $Week = & new Calendar_Week(2003, 10, 1); Oct 2003, 1st tabular week
* require_once 'Calendar/Week.php';
* $Week = new Calendar_Week(2003, 10, 1); Oct 2003, 1st tabular week
* echo '<tr>';
* while ($Day = & $Week->fetch()) {
* if ($Day->isEmpty()) {
@@ -53,8 +65,14 @@ require_once CALENDAR_ROOT.'Calendar.php';
* }
* echo '</tr>';
* </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
{
@@ -109,33 +127,49 @@ class Calendar_Week extends Calendar
/**
* Constructs Week
* @param int year e.g. 2003
* @param int month e.g. 5
* @param int a day of the desired week
* @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
*
* @param int $y year e.g. 2003
* @param int $m month e.g. 5
* @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
*/
function Calendar_Week($y, $m, $d, $firstDay=null)
function Calendar_Week($y, $m, $d, $firstDay = null)
{
require_once CALENDAR_ROOT.'Table/Helper.php';
Calendar::Calendar($y, $m, $d);
$this->firstDay = $this->defineFirstDayOfWeek($firstDay);
$this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay);
$this->thisWeek = $this->tableHelper->getWeekStart($y, $m, $d, $this->firstDay);
$this->prevWeek = $this->tableHelper->getWeekStart($y, $m, $d - $this->cE->getDaysInWeek(
$this->thisYear(),
$this->thisMonth(),
$this->thisDay()), $this->firstDay);
$this->nextWeek = $this->tableHelper->getWeekStart($y, $m, $d + $this->cE->getDaysInWeek(
$this->thisYear(),
$this->thisMonth(),
$this->thisDay()), $this->firstDay);
include_once CALENDAR_ROOT.'Table/Helper.php';
parent::Calendar($y, $m, $d);
$this->firstDay = $this->defineFirstDayOfWeek($firstDay);
$this->tableHelper = new Calendar_Table_Helper($this, $this->firstDay);
$this->thisWeek = $this->tableHelper->getWeekStart($y, $m, $d, $this->firstDay);
$this->prevWeek = $this->tableHelper->getWeekStart(
$y,
$m,
$d - $this->cE->getDaysInWeek(
$this->thisYear(),
$this->thisMonth(),
$this->thisDay()
),
$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
* passed to the constructor
* @param int|string Unix or ISO-8601 timestamp
*
* @param int|string $ts Unix or ISO-8601 timestamp
*
* @return void
* @access public
*/
@@ -146,28 +180,38 @@ class Calendar_Week extends Calendar
$this->year, $this->month, $this->day, $this->firstDay
);
$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->thisMonth(),
$this->thisDay()), $this->firstDay
$this->thisDay()
),
$this->firstDay
);
$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->thisMonth(),
$this->thisDay()), $this->firstDay
$this->thisDay()
),
$this->firstDay
);
}
/**
* 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
* @access public
*/
function build($sDates = array())
{
require_once CALENDAR_ROOT.'Day.php';
include_once CALENDAR_ROOT.'Day.php';
$year = $this->cE->stampToYear($this->thisWeek);
$month = $this->cE->stampToMonth($this->thisWeek);
$day = $this->cE->stampToDay($this->thisWeek);
@@ -180,9 +224,10 @@ class Calendar_Week extends Calendar
for ($i=1; $i <= $end; $i++) {
$stamp = $this->cE->dateToStamp($year, $month, $day++);
$this->children[$i] = new Calendar_Day(
$this->cE->stampToYear($stamp),
$this->cE->stampToMonth($stamp),
$this->cE->stampToDay($stamp));
$this->cE->stampToYear($stamp),
$this->cE->stampToMonth($stamp),
$this->cE->stampToDay($stamp)
);
}
//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
* @access private
*/
function setFirst($state=true)
function setFirst($state = true)
{
$this->firstWeek = $state;
}
/**
* @param boolean
* Set as last week of the month
*
* @param boolean $state whether it's lasst or not
*
* @return void
* @access private
*/
function setLast($state=true)
function setLast($state = true)
{
$this->lastWeek = $state;
}
/**
* Called from build()
* @param array
*
* @param array $sDates Calendar_Day objects representing selected dates
*
* @return void
* @access private
*/
@@ -247,37 +300,66 @@ class Calendar_Week extends Calendar
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
*
* @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
*
* @return mixed
* @access public
*/
function prevWeek($format = 'n_in_month')
{
switch (strtolower($format)) {
case 'int':
case 'n_in_month':
return ($this->firstWeek) ? null : $this->thisWeek('n_in_month') -1;
break;
case 'n_in_year':
return $this->cE->getWeekNInYear(
$this->cE->stampToYear($this->prevWeek),
$this->cE->stampToMonth($this->prevWeek),
$this->cE->stampToDay($this->prevWeek));
break;
case 'array':
return $this->toArray($this->prevWeek);
break;
case 'object':
require_once CALENDAR_ROOT.'Factory.php';
return Calendar_Factory::createByTimestamp('Week', $this->prevWeek);
break;
case 'timestamp':
default:
return $this->prevWeek;
break;
case 'int':
case 'n_in_month':
return ($this->firstWeek) ? null : $this->thisWeek('n_in_month') -1;
case 'n_in_year':
return $this->cE->getWeekNInYear(
$this->cE->stampToYear($this->prevWeek),
$this->cE->stampToMonth($this->prevWeek),
$this->cE->stampToDay($this->prevWeek));
case 'array':
return $this->toArray($this->prevWeek);
case 'object':
include_once CALENDAR_ROOT.'Factory.php';
return Calendar_Factory::createByTimestamp('Week', $this->prevWeek);
case 'timestamp':
default:
return $this->prevWeek;
}
}
@@ -285,46 +367,42 @@ class Calendar_Week extends Calendar
* Gets the value of the current week, according to the requested format
*
* @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
*
* @return mixed
* @access public
*/
function thisWeek($format = 'n_in_month')
{
switch (strtolower($format)) {
case 'int':
case 'n_in_month':
if ($this->firstWeek) {
return 1;
}
if ($this->lastWeek) {
return $this->cE->getWeeksInMonth(
$this->thisYear(),
$this->thisMonth(),
$this->firstDay);
}
return $this->cE->getWeekNInMonth(
case 'int':
case 'n_in_month':
if ($this->firstWeek) {
return 1;
}
if ($this->lastWeek) {
return $this->cE->getWeeksInMonth(
$this->thisYear(),
$this->thisMonth(),
$this->thisDay(),
$this->firstDay);
break;
case 'n_in_year':
return $this->cE->getWeekNInYear(
$this->cE->stampToYear($this->thisWeek),
$this->cE->stampToMonth($this->thisWeek),
$this->cE->stampToDay($this->thisWeek));
break;
case 'array':
return $this->toArray($this->thisWeek);
break;
case 'object':
require_once CALENDAR_ROOT.'Factory.php';
return Calendar_Factory::createByTimestamp('Week', $this->thisWeek);
break;
case 'timestamp':
default:
return $this->thisWeek;
break;
}
return $this->cE->getWeekNInMonth(
$this->thisYear(),
$this->thisMonth(),
$this->thisDay(),
$this->firstDay);
case 'n_in_year':
return $this->cE->getWeekNInYear(
$this->cE->stampToYear($this->thisWeek),
$this->cE->stampToMonth($this->thisWeek),
$this->cE->stampToDay($this->thisWeek));
case 'array':
return $this->toArray($this->thisWeek);
case 'object':
include_once CALENDAR_ROOT.'Factory.php';
return Calendar_Factory::createByTimestamp('Week', $this->thisWeek);
case 'timestamp':
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
*
* @param string $format ['timestamp' | 'n_in_month' | 'n_in_year' | 'array']
*
* @return mixed
* @access public
*/
function nextWeek($format = 'n_in_month')
{
switch (strtolower($format)) {
case 'int':
case 'n_in_month':
return ($this->lastWeek) ? null : $this->thisWeek('n_in_month') +1;
break;
case 'n_in_year':
return $this->cE->getWeekNInYear(
$this->cE->stampToYear($this->nextWeek),
$this->cE->stampToMonth($this->nextWeek),
$this->cE->stampToDay($this->nextWeek));
break;
case 'array':
return $this->toArray($this->nextWeek);
break;
case 'object':
require_once CALENDAR_ROOT.'Factory.php';
return Calendar_Factory::createByTimestamp('Week', $this->nextWeek);
break;
case 'timestamp':
default:
return $this->nextWeek;
break;
case 'int':
case 'n_in_month':
return ($this->lastWeek) ? null : $this->thisWeek('n_in_month') +1;
case 'n_in_year':
return $this->cE->getWeekNInYear(
$this->cE->stampToYear($this->nextWeek),
$this->cE->stampToMonth($this->nextWeek),
$this->cE->stampToDay($this->nextWeek));
case 'array':
return $this->toArray($this->nextWeek);
case 'object':
include_once CALENDAR_ROOT.'Factory.php';
return Calendar_Factory::createByTimestamp('Week', $this->nextWeek);
case 'timestamp':
default:
return $this->nextWeek;
}
}
/**
* Returns the instance of Calendar_Table_Helper.
* Called from Calendar_Validator::isValidWeek
*
* @return Calendar_Table_Helper
* @access protected
*/
@@ -375,6 +450,7 @@ class Calendar_Week extends Calendar
/**
* Makes sure theres a value for $this->day
*
* @return void
* @access private
*/

View File

@@ -1,27 +1,39 @@
<?php
/* 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
* @version $Id: Year.php,v 1.4 2005/10/22 10:25:39 quipo Exp $
* Contains the Calendar_Minute class
*
* 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 />';
* }
* </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
{
/**
* Constructs Calendar_Year
* @param int year e.g. 2003
*
* @param int $y year e.g. 2003
*
* @access public
*/
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
* </code>
* 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
* @access public
*/
function build($sDates = array(), $firstDay = null)
{
require_once CALENDAR_ROOT.'Factory.php';
include_once CALENDAR_ROOT.'Factory.php';
$this->firstDay = $this->defineFirstDayOfWeek($firstDay);
$monthsInYear = $this->cE->getMonthsInYear($this->thisYear());
$monthsInYear = $this->cE->getMonthsInYear($this->thisYear());
for ($i=1; $i <= $monthsInYear; $i++) {
$this->children[$i] = Calendar_Factory::create('Month', $this->year, $i);
}
@@ -94,11 +118,14 @@ class Calendar_Year extends Calendar
/**
* Called from build()
* @param array
*
* @param array $sDates array of Calendar_Month objects representing selected dates
*
* @return void
* @access private
*/
function setSelection($sDates) {
function setSelection($sDates)
{
foreach ($sDates as $sDate) {
if ($this->year == $sDate->thisYear()) {
$key = $sDate->thisMonth();