pax_global_header00006660000000000000000000000064121243624250014513gustar00rootroot0000000000000052 comment=e52486e48a6dd74408403ddeb99a4c0d6405df17 php-calendar-0.5.5/000077500000000000000000000000001212436242500140605ustar00rootroot00000000000000php-calendar-0.5.5/Calendar-0.5.5/000077500000000000000000000000001212436242500162345ustar00rootroot00000000000000php-calendar-0.5.5/Calendar-0.5.5/Calendar.php000066400000000000000000000563561212436242500204750ustar00rootroot00000000000000 * @author Lorenzo Alberton * @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 */ /** * Allows Calendar include path to be redefined */ if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR); } /** * Constant which defines the calculation engine to use */ if (!defined('CALENDAR_ENGINE')) { define('CALENDAR_ENGINE', 'UnixTS'); } /** * Define Calendar Month states */ define('CALENDAR_USE_MONTH', 1); define('CALENDAR_USE_MONTH_WEEKDAYS', 2); define('CALENDAR_USE_MONTH_WEEKS', 3); /** * Contains a factory method to return a Singleton instance of a class * implementing the Calendar_Engine_Interface.
* Note: this class must be modified to "register" alternative * Calendar_Engines. The engine used can be controlled with the constant * CALENDAR_ENGINE * * @category Date and Time * @package Calendar * @author Harry Fuecks * @author Lorenzo Alberton * @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 $engine = false; switch (CALENDAR_ENGINE) { case 'PearDate': $class = 'Calendar_Engine_PearDate'; break; case 'UnixTS': default: $class = 'Calendar_Engine_UnixTS'; break; } if (!$engine) { if (!class_exists($class)) { include_once CALENDAR_ROOT.'Engine'.DIRECTORY_SEPARATOR.CALENDAR_ENGINE.'.php'; } $engine = new $class; } return $engine; } } /** * Base class for Calendar API. This class should not be instantiated directly. * * @category Date and Time * @package Calendar * @author Harry Fuecks * @author Lorenzo Alberton * @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 */ class Calendar { /** * Instance of class implementing calendar engine interface * @var object * @access private */ var $cE; /** * Instance of Calendar_Validator (lazy initialized when isValid() or * getValidor() is called * @var Calendar_Validator * @access private */ var $validator; /** * Year for this calendar object e.g. 2003 * @access private * @var int */ var $year; /** * Month for this calendar object e.g. 9 * @access private * @var int */ var $month; /** * Day of month for this calendar object e.g. 23 * @access private * @var int */ var $day; /** * Hour of day for this calendar object e.g. 13 * @access private * @var int */ var $hour; /** * Minute of hour this calendar object e.g. 46 * @access private * @var int */ var $minute; /** * Second of minute this calendar object e.g. 34 * @access private * @var int */ var $second; /** * Marks this calendar object as selected (e.g. 'today') * @access private * @var boolean */ var $selected = false; /** * Collection of child calendar objects created from subclasses * of Calendar. Type depends on the object which created them. * @access private * @var array */ var $children = array(); /** * Constructs the Calendar * * @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) { static $cE = null; if (!isset($cE)) { $cE = & Calendar_Engine_Factory::getEngine(); } $this->cE = & $cE; $this->year = (int)$y; $this->month = (int)$m; $this->day = (int)$d; $this->hour = (int)$h; $this->minute = (int)$i; $this->second = (int)$s; } /** * Defines the calendar by a timestamp (Unix or ISO-8601), replacing values * passed to the constructor * * @param int|string $ts Unix or ISO-8601 timestamp * * @return void * @access public */ function setTimestamp($ts) { $this->year = $this->cE->stampToYear($ts); $this->month = $this->cE->stampToMonth($ts); $this->day = $this->cE->stampToDay($ts); $this->hour = $this->cE->stampToHour($ts); $this->minute = $this->cE->stampToMinute($ts); $this->second = $this->cE->stampToSecond($ts); } /** * 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 */ function getTimestamp() { return $this->cE->dateToStamp( $this->year, $this->month, $this->day, $this->hour, $this->minute, $this->second); } /** * Defines calendar object as selected (e.g. for today) * * @param boolean $state whether Calendar subclass * * @return void * @access public */ function setSelected($state = true) { $this->selected = $state; } /** * True if the calendar subclass object is selected (e.g. today) * * @return boolean * @access public */ function isSelected() { 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(); $this->year = $this->cE->stampToYear($stamp); $this->month = $this->cE->stampToMonth($stamp); $this->day = $this->cE->stampToDay($stamp); $this->hour = $this->cE->stampToHour($stamp); $this->minute = $this->cE->stampToMinute($stamp); $this->second = $this->cE->stampToSecond($stamp); } /** * Returns the date as an associative array (helper method) * * @param mixed $stamp timestamp (leave empty for current timestamp) * * @return array * @access public */ function toArray($stamp=null) { if (is_null($stamp)) { $stamp = $this->getTimeStamp(); } return array( 'year' => $this->cE->stampToYear($stamp), 'month' => $this->cE->stampToMonth($stamp), 'day' => $this->cE->stampToDay($stamp), 'hour' => $this->cE->stampToHour($stamp), 'minute' => $this->cE->stampToMinute($stamp), 'second' => $this->cE->stampToSecond($stamp) ); } /** * Returns the value as an associative array (helper method) * * @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': 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 $sDates array containing Calendar objects to select (optional) * * @return boolean * @access public * @abstract */ function build($sDates = array()) { 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 $sDates array of Calendar objects to select * * @return boolean * @access public * @abstract */ function setSelection($sDates) { include_once 'PEAR.php'; PEAR::raiseError( 'Calendar::setSelection is abstract', null, PEAR_ERROR_TRIGGER, E_USER_NOTICE, 'Calendar::setSelection()'); return false; } /** * Iterator method for fetching child Calendar subclass objects * (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 */ function fetch() { $child = each($this->children); if ($child) { return $child['value']; } else { reset($this->children); return false; } } /** * Fetches all child from the current collection of children * * @return array * @access public */ function fetchAll() { return $this->children; } /** * Get the number Calendar subclass objects stored in the internal collection * * @return int * @access public */ function size() { return count($this->children); } /** * Determine whether this date is valid, with the bounds determined by * the Calendar_Engine. The call is passed on to Calendar_Validator::isValid * * @return boolean * @access public */ function isValid() { $validator = & $this->getValidator(); return $validator->isValid(); } /** * Returns an instance of Calendar_Validator * * @return Calendar_Validator * @access public */ function & getValidator() { if (!isset($this->validator)) { include_once CALENDAR_ROOT.'Validator.php'; $this->validator = new Calendar_Validator($this); } return $this->validator; } /** * 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 */ function & getEngine() { return $this->cE; } /** * 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 * @access protected */ function defineFirstDayOfWeek($firstDay = null) { if (defined('CALENDAR_FIRST_DAY_OF_WEEK')) { if (!is_null($firstDay) && ($firstDay != CALENDAR_FIRST_DAY_OF_WEEK)) { $msg = 'CALENDAR_FIRST_DAY_OF_WEEK constant already defined.' .' The $firstDay parameter will be ignored.'; trigger_error($msg, E_USER_WARNING); } return CALENDAR_FIRST_DAY_OF_WEEK; } if (is_null($firstDay)) { $firstDay = $this->cE->getFirstDayOfWeek( $this->thisYear(), $this->thisMonth(), $this->thisDay() ); } define ('CALENDAR_FIRST_DAY_OF_WEEK', $firstDay); return CALENDAR_FIRST_DAY_OF_WEEK; } /** * Returns the value for the previous year * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 2002 or timestamp * @access public */ function prevYear($format = 'int') { $ts = $this->cE->dateToStamp($this->year-1, 1, 1, 0, 0, 0); return $this->returnValue('Year', $format, $ts, $this->year-1); } /** * Returns the value for this year * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 2003 or timestamp * @access public */ function thisYear($format = 'int') { $ts = $this->cE->dateToStamp($this->year, 1, 1, 0, 0, 0); return $this->returnValue('Year', $format, $ts, $this->year); } /** * Returns the value for next year * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 2004 or timestamp * @access public */ function nextYear($format = 'int') { $ts = $this->cE->dateToStamp($this->year+1, 1, 1, 0, 0, 0); return $this->returnValue('Year', $format, $ts, $this->year+1); } /** * Returns the value for the previous month * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 4 or Unix timestamp * @access public */ function prevMonth($format = 'int') { $ts = $this->cE->dateToStamp($this->year, $this->month-1, 1, 0, 0, 0); return $this->returnValue('Month', $format, $ts, $this->cE->stampToMonth($ts)); } /** * Returns the value for this month * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 5 or timestamp * @access public */ function thisMonth($format = 'int') { $ts = $this->cE->dateToStamp($this->year, $this->month, 1, 0, 0, 0); return $this->returnValue('Month', $format, $ts, $this->month); } /** * Returns the value for next month * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 6 or timestamp * @access public */ function nextMonth($format = 'int') { $ts = $this->cE->dateToStamp($this->year, $this->month+1, 1, 0, 0, 0); return $this->returnValue('Month', $format, $ts, $this->cE->stampToMonth($ts)); } /** * Returns the value for the previous day * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 10 or timestamp * @access public */ function prevDay($format = 'int') { $ts = $this->cE->dateToStamp( $this->year, $this->month, $this->day-1, 0, 0, 0); return $this->returnValue('Day', $format, $ts, $this->cE->stampToDay($ts)); } /** * Returns the value for this day * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 11 or timestamp * @access public */ function thisDay($format = 'int') { $ts = $this->cE->dateToStamp( $this->year, $this->month, $this->day, 0, 0, 0); return $this->returnValue('Day', $format, $ts, $this->day); } /** * Returns the value for the next day * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 12 or timestamp * @access public */ function nextDay($format = 'int') { $ts = $this->cE->dateToStamp( $this->year, $this->month, $this->day+1, 0, 0, 0); return $this->returnValue('Day', $format, $ts, $this->cE->stampToDay($ts)); } /** * Returns the value for the previous hour * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 13 or timestamp * @access public */ function prevHour($format = 'int') { $ts = $this->cE->dateToStamp( $this->year, $this->month, $this->day, $this->hour-1, 0, 0); return $this->returnValue('Hour', $format, $ts, $this->cE->stampToHour($ts)); } /** * Returns the value for this hour * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 14 or timestamp * @access public */ function thisHour($format = 'int') { $ts = $this->cE->dateToStamp( $this->year, $this->month, $this->day, $this->hour, 0, 0); return $this->returnValue('Hour', $format, $ts, $this->hour); } /** * Returns the value for the next hour * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 14 or timestamp * @access public */ function nextHour($format = 'int') { $ts = $this->cE->dateToStamp( $this->year, $this->month, $this->day, $this->hour+1, 0, 0); return $this->returnValue('Hour', $format, $ts, $this->cE->stampToHour($ts)); } /** * Returns the value for the previous minute * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 23 or timestamp * @access public */ function prevMinute($format = 'int') { $ts = $this->cE->dateToStamp( $this->year, $this->month, $this->day, $this->hour, $this->minute-1, 0); return $this->returnValue('Minute', $format, $ts, $this->cE->stampToMinute($ts)); } /** * Returns the value for this minute * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 24 or timestamp * @access public */ function thisMinute($format = 'int') { $ts = $this->cE->dateToStamp( $this->year, $this->month, $this->day, $this->hour, $this->minute, 0); return $this->returnValue('Minute', $format, $ts, $this->minute); } /** * Returns the value for the next minute * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 25 or timestamp * @access public */ function nextMinute($format = 'int') { $ts = $this->cE->dateToStamp( $this->year, $this->month, $this->day, $this->hour, $this->minute+1, 0); return $this->returnValue('Minute', $format, $ts, $this->cE->stampToMinute($ts)); } /** * Returns the value for the previous second * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 43 or timestamp * @access public */ function prevSecond($format = 'int') { $ts = $this->cE->dateToStamp( $this->year, $this->month, $this->day, $this->hour, $this->minute, $this->second-1); return $this->returnValue('Second', $format, $ts, $this->cE->stampToSecond($ts)); } /** * Returns the value for this second * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 44 or timestamp * @access public */ function thisSecond($format = 'int') { $ts = $this->cE->dateToStamp( $this->year, $this->month, $this->day, $this->hour, $this->minute, $this->second); return $this->returnValue('Second', $format, $ts, $this->second); } /** * Returns the value for the next second * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 45 or timestamp * @access public */ function nextSecond($format = 'int') { $ts = $this->cE->dateToStamp( $this->year, $this->month, $this->day, $this->hour, $this->minute, $this->second+1); return $this->returnValue('Second', $format, $ts, $this->cE->stampToSecond($ts)); } } ?>php-calendar-0.5.5/Calendar-0.5.5/Day.php000066400000000000000000000145421212436242500174700ustar00rootroot00000000000000 * @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 */ /** * Allows Calendar include path to be redefined * @ignore */ if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR); } /** * Load Calendar base class */ require_once CALENDAR_ROOT.'Calendar.php'; /** * Represents a Day and builds Hours. * * require_once 'Calendar/Day.php'; * $Day = new Calendar_Day(2003, 10, 21); // Oct 21st 2003 * while ($Hour = & $Day->fetch()) { * echo $Hour->thisHour().'
'; * } *
* * @category Date and Time * @package Calendar * @author Harry Fuecks * @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 { /** * Marks the Day at the beginning of a week * @access private * @var boolean */ var $first = false; /** * Marks the Day at the end of a week * @access private * @var boolean */ var $last = false; /** * Used for tabular calendars * @access private * @var boolean */ var $empty = false; /** * Constructs Calendar_Day * * @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) { parent::Calendar($y, $m, $d); } /** * Builds the Hours of the Day * * @param array $sDates (optional) Caledar_Hour objects representing selected dates * * @return boolean * @access public */ function build($sDates = array()) { 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] = new Calendar_Hour($this->year, $this->month, $this->day, $i); } if (count($sDates) > 0) { $this->setSelection($sDates); } return true; } /** * Called from build() * * @param array $sDates dates to be selected * * @return void * @access private */ function setSelection($sDates) { foreach ($sDates as $sDate) { if ($this->year == $sDate->thisYear() && $this->month == $sDate->thisMonth() && $this->day == $sDate->thisDay()) { $key = (int)$sDate->thisHour(); if (isset($this->children[$key])) { $sDate->setSelected(); $this->children[$key] = $sDate; } } } } /** * Defines Day object as first in a week * Only used by Calendar_Month_Weekdays::build() * * @param boolean $state set this day as first in week * * @return void * @access private */ function setFirst($state = true) { $this->first = $state; } /** * Defines Day object as last in a week * Used only following Calendar_Month_Weekdays::build() * * @param boolean $state set this day as last in week * * @return void * @access private */ function setLast($state = true) { $this->last = $state; } /** * 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() { 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 */ function isLast() { return $this->last; } /** * Defines Day object as empty * Only used by Calendar_Month_Weekdays::build() * * @param boolean $state set this day as empty * * @return void * @access private */ function setEmpty ($state = true) { $this->empty = $state; } /** * Check if this day is empty * * @return boolean * @access public */ function isEmpty() { return $this->empty; } } ?>php-calendar-0.5.5/Calendar-0.5.5/Decorator.php000066400000000000000000000433361212436242500207000ustar00rootroot00000000000000 * @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". * Used for "selections" * * class DayDecorator extends Calendar_Decorator * { * function thisDay($format = 'int') * { .* $day = parent::thisDay('timestamp'); .* return date('D', $day); * } * } * $Day = new Calendar_Day(2003, 10, 25); * $DayDecorator = new DayDecorator($Day); * echo $DayDecorator->thisDay(); // Outputs "Sat" * * * @category Date and Time * @package Calendar * @author Harry Fuecks * @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 */ class Calendar_Decorator { /** * Subclass of Calendar being decorated * @var object * @access private */ var $calendar; /** * Constructs the Calendar_Decorator * * @param object &$calendar subclass to Calendar to decorate */ function Calendar_Decorator(&$calendar) { $this->calendar = & $calendar; } /** * Defines the calendar by a Unix timestamp, replacing values * passed to the constructor * * @param int $ts Unix timestamp * * @return void * @access public */ function setTimestamp($ts) { $this->calendar->setTimestamp($ts); } /** * Returns a timestamp from the current date / time values. Format of * timestamp depends on Calendar_Engine implementation being used * * @return int $ts timestamp * @access public */ function getTimestamp() { return $this->calendar->getTimeStamp(); } /** * Defines calendar object as selected (e.g. for today) * * @param boolean $state whether Calendar subclass must be selected * * @return void * @access public */ function setSelected($state = true) { $this->calendar->setSelected($state = true); } /** * True if the calendar subclass object is selected (e.g. today) * * @return boolean * @access public */ function isSelected() { return $this->calendar->isSelected(); } /** * Adjusts the date (helper method) * * @return void * @access public */ function adjust() { $this->calendar->adjust(); } /** * Returns the date as an associative array (helper method) * * @param mixed $stamp timestamp (leave empty for current timestamp) * * @return array * @access public */ function toArray($stamp = null) { return $this->calendar->toArray($stamp); } /** * Returns the value as an associative array (helper method) * * @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 */ function returnValue($returnType, $format, $stamp, $default) { return $this->calendar->returnValue($returnType, $format, $stamp, $default); } /** * Defines Day object as first in a week * Only used by Calendar_Month_Weekdays::build() * * @param boolean $state whether it's first or not * * @return void * @access private */ function setFirst($state = true) { if (method_exists($this->calendar, 'setFirst')) { $this->calendar->setFirst($state); } } /** * Defines Day object as last in a week * Used only following Calendar_Month_Weekdays::build() * * @param boolean $state whether it's last or not * * @return void * @access private */ function setLast($state = true) { if (method_exists($this->calendar, 'setLast')) { $this->calendar->setLast($state); } } /** * 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')) { return $this->calendar->isFirst(); } } /** * 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')) { return $this->calendar->isLast(); } } /** * Defines Day object as empty * Only used by Calendar_Month_Weekdays::build() * * @param boolean $state whether it's empty or not * * @return void * @access private */ function setEmpty ($state = true) { 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')) { return $this->calendar->isEmpty(); } } /** * Build the children * * @param array $sDates array containing Calendar objects to select (optional) * * @return boolean * @access public * @abstract */ function build($sDates = array()) { $this->calendar->build($sDates); } /** * Iterator method for fetching child Calendar subclass objects * (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 */ function fetch() { return $this->calendar->fetch(); } /** * Fetches all child from the current collection of children * * @return array * @access public */ function fetchAll() { return $this->calendar->fetchAll(); } /** * Get the number Calendar subclass objects stored in the internal collection * * @return int * @access public */ function size() { return $this->calendar->size(); } /** * Determine whether this date is valid, with the bounds determined by * the Calendar_Engine. The call is passed on to Calendar_Validator::isValid * * @return boolean * @access public */ function isValid() { return $this->calendar->isValid(); } /** * Returns an instance of Calendar_Validator * * @return Calendar_Validator * @access public */ function & getValidator() { $validator = $this->calendar->getValidator(); return $validator; } /** * 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() { $engine = $this->calendar->getEngine(); return $engine; } /** * Returns the value for the previous year * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 2002 or timestamp * @access public */ function prevYear($format = 'int') { return $this->calendar->prevYear($format); } /** * Returns the value for this year * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 2003 or timestamp * @access public */ function thisYear($format = 'int') { return $this->calendar->thisYear($format); } /** * Returns the value for next year * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 2004 or timestamp * @access public */ function nextYear($format = 'int') { return $this->calendar->nextYear($format); } /** * Returns the value for the previous month * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 4 or Unix timestamp * @access public */ function prevMonth($format = 'int') { return $this->calendar->prevMonth($format); } /** * Returns the value for this month * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 5 or timestamp * @access public */ function thisMonth($format = 'int') { return $this->calendar->thisMonth($format); } /** * Returns the value for next month * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 6 or timestamp * @access public */ function nextMonth($format = 'int') { return $this->calendar->nextMonth($format); } /** * Returns the value for the previous week * * @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')) { return $this->calendar->prevWeek($format); } else { include_once 'PEAR.php'; PEAR::raiseError( 'Cannot call prevWeek on Calendar object of type: '. get_class($this->calendar), 133, PEAR_ERROR_TRIGGER, E_USER_NOTICE, 'Calendar_Decorator::prevWeek()'); return false; } } /** * Returns the value for this week * * @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')) { return $this->calendar->thisWeek($format); } else { include_once 'PEAR.php'; PEAR::raiseError( 'Cannot call thisWeek on Calendar object of type: '. get_class($this->calendar), 133, PEAR_ERROR_TRIGGER, E_USER_NOTICE, 'Calendar_Decorator::thisWeek()'); return false; } } /** * Returns the value for next week * * @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')) { return $this->calendar->nextWeek($format); } else { include_once 'PEAR.php'; PEAR::raiseError( 'Cannot call thisWeek on Calendar object of type: '. get_class($this->calendar), 133, PEAR_ERROR_TRIGGER, E_USER_NOTICE, 'Calendar_Decorator::nextWeek()'); return false; } } /** * Returns the value for the previous day * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 10 or timestamp * @access public */ function prevDay($format = 'int') { return $this->calendar->prevDay($format); } /** * Returns the value for this day * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 11 or timestamp * @access public */ function thisDay($format = 'int') { return $this->calendar->thisDay($format); } /** * Returns the value for the next day * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 12 or timestamp * @access public */ function nextDay($format = 'int') { return $this->calendar->nextDay($format); } /** * Returns the value for the previous hour * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 13 or timestamp * @access public */ function prevHour($format = 'int') { return $this->calendar->prevHour($format); } /** * Returns the value for this hour * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 14 or timestamp * @access public */ function thisHour($format = 'int') { return $this->calendar->thisHour($format); } /** * Returns the value for the next hour * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 14 or timestamp * @access public */ function nextHour($format = 'int') { return $this->calendar->nextHour($format); } /** * Returns the value for the previous minute * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 23 or timestamp * @access public */ function prevMinute($format = 'int') { return $this->calendar->prevMinute($format); } /** * Returns the value for this minute * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 24 or timestamp * @access public */ function thisMinute($format = 'int') { return $this->calendar->thisMinute($format); } /** * Returns the value for the next minute * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 25 or timestamp * @access public */ function nextMinute($format = 'int') { return $this->calendar->nextMinute($format); } /** * Returns the value for the previous second * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 43 or timestamp * @access public */ function prevSecond($format = 'int') { return $this->calendar->prevSecond($format); } /** * Returns the value for this second * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 44 or timestamp * @access public */ function thisSecond($format = 'int') { return $this->calendar->thisSecond($format); } /** * Returns the value for the next second * * @param string $format return value format ['int'|'timestamp'|'object'|'array'] * * @return int e.g. 45 or timestamp * @access public */ function nextSecond($format = 'int') { return $this->calendar->nextSecond($format); } } ?>php-calendar-0.5.5/Calendar-0.5.5/Decorator/000077500000000000000000000000001212436242500201565ustar00rootroot00000000000000php-calendar-0.5.5/Calendar-0.5.5/Decorator/Textual.php000066400000000000000000000156361212436242500223300ustar00rootroot00000000000000 * @author Lorenzo Alberton * @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 */ /** * Allows Calendar include path to be redefined * @ignore */ if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR); } /** * Load Calendar decorator base class */ require_once CALENDAR_ROOT.'Decorator.php'; /** * Load the Uri utility */ require_once CALENDAR_ROOT.'Util'.DIRECTORY_SEPARATOR.'Textual.php'; /** * Decorator to help with fetching textual representations of months and * days of the week. * Note: for performance you should prefer Calendar_Util_Textual unless you * have a specific need to use a decorator * * @category Date and Time * @package Calendar * @author Harry Fuecks * @author Lorenzo Alberton * @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 &$Calendar subclass of Calendar * * @access public */ function Calendar_Decorator_Textual(&$Calendar) { parent::Calendar_Decorator($Calendar); } /** * Returns an array of 12 month names (first index = 1) * * @param string $format (optional) format of returned months (one|two|short|long) * * @return array * @access public * @static */ function monthNames($format = 'long') { return Calendar_Util_Textual::monthNames($format); } /** * Returns an array of 7 week day names (first index = 0) * * @param string $format (optional) format of returned days (one|two|short|long) * * @return array * @access public * @static */ function weekdayNames($format = 'long') { return Calendar_Util_Textual::weekdayNames($format); } /** * Returns textual representation of the previous month of the decorated calendar object * * @param string $format (optional) format of returned months (one|two|short|long) * * @return string * @access public */ function prevMonthName($format = 'long') { return Calendar_Util_Textual::prevMonthName($this->calendar, $format); } /** * Returns textual representation of the month of the decorated calendar object * * @param string $format (optional) format of returned months (one|two|short|long) * * @return string * @access public */ function thisMonthName($format = 'long') { return Calendar_Util_Textual::thisMonthName($this->calendar, $format); } /** * Returns textual representation of the next month of the decorated calendar object * * @param string $format (optional) format of returned months (one|two|short|long) * * @return string * @access public */ function nextMonthName($format = 'long') { return Calendar_Util_Textual::nextMonthName($this->calendar, $format); } /** * Returns textual representation of the previous day of week of the decorated calendar object * * @param string $format (optional) format of returned months (one|two|short|long) * * @return string * @access public */ function prevDayName($format = 'long') { return Calendar_Util_Textual::prevDayName($this->calendar, $format); } /** * Returns textual representation of the day of week of the decorated calendar object * * @param string $format (optional) format of returned months (one|two|short|long) * * @return string * @access public */ function thisDayName($format = 'long') { return Calendar_Util_Textual::thisDayName($this->calendar, $format); } /** * Returns textual representation of the next day of week of the decorated calendar object * * @param string $format (optional) format of returned months (one|two|short|long) * * @return string * @access public */ function nextDayName($format = 'long') { 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 $format (optional) format of returned months (one|two|short|long) * * @return array ordered array of week day names * @access public */ function orderedWeekdays($format = 'long') { return Calendar_Util_Textual::orderedWeekdays($this->calendar, $format); } } ?>php-calendar-0.5.5/Calendar-0.5.5/Decorator/Uri.php000066400000000000000000000133131212436242500214270ustar00rootroot00000000000000 * @author Lorenzo Alberton * @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 */ /** * Allows Calendar include path to be redefined * @ignore */ if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR); } /** * Load Calendar decorator base class */ require_once CALENDAR_ROOT.'Decorator.php'; /** * Load the Uri utility */ require_once CALENDAR_ROOT.'Util'.DIRECTORY_SEPARATOR.'Uri.php'; /** * Decorator to help with building HTML links for navigating the calendar
* Note: for performance you should prefer Calendar_Util_Uri unless you * have a specific need to use a decorator * * $Day = new Calendar_Day(2003, 10, 23); * $Uri = new Calendar_Decorator_Uri($Day); * $Uri->setFragments('year', 'month', 'day'); * echo $Uri->getPrev(); // Displays year=2003&month=10&day=22 * * * @category Date and Time * @package Calendar * @author Harry Fuecks * @author Lorenzo Alberton * @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 $Uri; /** * Constructs Calendar_Decorator_Uri * * @param object &$Calendar subclass of Calendar * * @access public */ function Calendar_Decorator_Uri(&$Calendar) { parent::Calendar_Decorator($Calendar); } /** * Sets the URI fragment names * * @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); } /** * Sets the separator string between fragments * * @param string $separator url fragment separator e.g. / * * @return void * @access public */ function setSeparator($separator) { $this->Uri->separator = $separator; } /** * Puts Uri decorator into "scalar mode" - URI variable names are not returned * * @param boolean $state (optional) * * @return void * @access public */ function setScalar($state = true) { $this->Uri->scalar = $state; } /** * Gets the URI string for the previous calendar unit * * @param string $method calendar unit to fetch uri for (year, month, week or day etc) * * @return string * @access public */ function prev($method) { return $this->Uri->prev($this, $method); } /** * Gets the URI string for the current calendar unit * * @param string $method calendar unit to fetch uri for (year,month,week or day etc) * * @return string * @access public */ function this($method) { return $this->Uri->this($this, $method); } /** * Gets the URI string for the next calendar unit * * @param string $method calendar unit to fetch uri for (year,month,week or day etc) * * @return string * @access public */ function next($method) { return $this->Uri->next($this, $method); } } ?>php-calendar-0.5.5/Calendar-0.5.5/Decorator/Weekday.php000066400000000000000000000145171212436242500222700ustar00rootroot00000000000000 * @author Lorenzo Alberton * @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 */ /** * Allows Calendar include path to be redefined * @ignore */ if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR); } /** * Load Calendar decorator base class */ require_once CALENDAR_ROOT.'Decorator.php'; /** * Load a Calendar_Day */ require_once CALENDAR_ROOT.'Day.php'; /** * Decorator for fetching the day of the week * * $Day = new Calendar_Day(2003, 10, 23); * $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 * * * @category Date and Time * @package Calendar * @author Harry Fuecks * @author Lorenzo Alberton * @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 { /** * First day of week * @var int (default = 1 for Monday) * @access private */ var $firstDay = 1; /** * Constructs Calendar_Decorator_Weekday * * @param object &$Calendar subclass of Calendar * * @access public */ function Calendar_Decorator_Weekday(&$Calendar) { parent::Calendar_Decorator($Calendar); } /** * Sets the first day of the week (0 = Sunday, 1 = Monday (default) etc) * * @param int $firstDay first day of week * * @return void * @access public */ function setFirstDay($firstDay) { $this->firstDay = (int)$firstDay; } /** * Returns the previous weekday * * @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); $Day->setTimeStamp($ts); $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 $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 ); $day = $this->adjustWeekScale($day); return $this->returnValue('Day', $format, $ts, $day); } /** * Returns the next weekday * * @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); $Day->setTimeStamp($ts); $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 $dayOfWeek day of week calendar from Calendar_Engine * * @return int day of week adjusted to first day * @access private */ function adjustWeekScale($dayOfWeek) { $dayOfWeek = $dayOfWeek - $this->firstDay; if ($dayOfWeek >= 0) { return $dayOfWeek; } else { return $this->calendar->cE->getDaysInWeek( $this->calendar->year, $this->calendar->month, $this->calendar->day ) + $dayOfWeek; } } } ?>php-calendar-0.5.5/Calendar-0.5.5/Decorator/Wrapper.php000066400000000000000000000077201212436242500223150ustar00rootroot00000000000000 * @author Lorenzo Alberton * @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 */ /** * Allows Calendar include path to be redefined * @ignore */ if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR); } /** * Load Calendar decorator base class */ require_once CALENDAR_ROOT.'Decorator.php'; /** * Decorator to help with wrapping built children in another decorator * * @category Date and Time * @package Calendar * @author Harry Fuecks * @author Lorenzo Alberton * @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 &$Calendar subclass of Calendar * * @access public */ function Calendar_Decorator_Wrapper(&$Calendar) { parent::Calendar_Decorator($Calendar); } /** * Wraps objects returned from fetch in the named Decorator class * * @param string $decorator name of Decorator class to wrap with * * @return object instance of named decorator * @access public */ function & fetch($decorator) { $Calendar = parent::fetch(); if ($Calendar) { $ret = new $decorator($Calendar); } else { $ret = false; } return $ret; } /** * Wraps the returned calendar objects from fetchAll in the named decorator * * @param string $decorator name of Decorator class to wrap with * * @return array * @access public */ function fetchAll($decorator) { $children = parent::fetchAll(); foreach ($children as $key => $Calendar) { $children[$key] = new $decorator($Calendar); } return $children; } } ?>php-calendar-0.5.5/Calendar-0.5.5/Engine/000077500000000000000000000000001212436242500174415ustar00rootroot00000000000000php-calendar-0.5.5/Calendar-0.5.5/Engine/Interface.php000066400000000000000000000236461212436242500220650ustar00rootroot00000000000000 * @author Lorenzo Alberton * @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 * * @category Date and Time * @package Calendar * @author Harry Fuecks * @author Lorenzo Alberton * @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 { /** * Provides a mechansim to make sure parsing of timestamps * 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 $stamp timestamp (depending on implementation) * * @return mixed * @access protected */ function stampCollection($stamp) { } /** * Returns a numeric year given a timestamp * * @param int $stamp timestamp (depending on implementation) * * @return int year (e.g. 2003) * @access protected */ function stampToYear($stamp) { } /** * Returns a numeric month given a timestamp * * @param int $stamp timestamp (depending on implementation) * * @return int month (e.g. 9) * @access protected */ function stampToMonth($stamp) { } /** * Returns a numeric day given a timestamp * * @param int $stamp timestamp (depending on implementation) * * @return int day (e.g. 15) * @access protected */ function stampToDay($stamp) { } /** * Returns a numeric hour given a timestamp * * @param int $stamp timestamp (depending on implementation) * * @return int hour (e.g. 13) * @access protected */ function stampToHour($stamp) { } /** * Returns a numeric minute given a timestamp * * @param int $stamp timestamp (depending on implementation) * * @return int minute (e.g. 34) * @access protected */ function stampToMinute($stamp) { } /** * Returns a numeric second given a timestamp * * @param int $stamp timestamp (depending on implementation) * * @return int second (e.g. 51) * @access protected */ function stampToSecond($stamp) { } /** * 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) { } /** * The upper limit on years that the Calendar Engine can work with * * @return int (e.g. 2037) * @access protected */ function getMaxYears() { } /** * The lower limit on years that the Calendar Engine can work with * * @return int (e.g 1902) * @access protected */ function getMinYears() { } /** * Returns the number of months in a year * * @param int $y (optional) year to get months for * * @return int (e.g. 12) * @access protected */ function getMonthsInYear($y=null) { } /** * Returns the number of days in a month, given year and month * * @param int $y year (e.g. 2003) * @param int $m month (e.g. 9) * * @return int days in month * @access protected */ function getDaysInMonth($y, $m) { } /** * Returns numeric representation of the day of the week in a month, * given year and month * * @param int $y year (e.g. 2003) * @param int $m month (e.g. 9) * * @return int * @access protected */ function getFirstDayInMonth ($y, $m) { } /** * Returns the number of days in a week * * @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) { } /** * Returns the number of the week in the year (ISO-8601), given a date * * @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) { } /** * Returns the number of the week in the month, given a date * * @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 */ function getWeekNInMonth($y, $m, $d, $firstDay=1) { } /** * Returns the number of weeks in the month * * @param int $y year (2003) * @param int $m month (9) * * @return int weeks number * @access protected */ function getWeeksInMonth($y, $m) { } /** * Returns the number of the day of the week (0=sunday, 1=monday...) * * @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) { } /** * Returns the numeric values of the days of the week. * * @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) { } /** * Returns the default first day of the week as an integer. Must be a * member of the array returned from getWeekDays * * @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) { } /** * 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 */ function getHoursInDay($y=null,$m=null,$d=null) { } /** * 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 * @access protected */ function getMinutesInHour($y=null,$m=null,$d=null,$h=null) { } /** * 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 * @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) { } } ?>php-calendar-0.5.5/Calendar-0.5.5/Engine/PearDate.php000066400000000000000000000337551212436242500216540ustar00rootroot00000000000000 * @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 */ 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) * * @category Date and Time * @package Calendar * @author Lorenzo Alberton * @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 */ { /** * 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 $stamp Any timestamp format recognized by Pear::Date * * @return object Pear::Date object * @access protected */ function stampCollection($stamp) { static $stamps = array(); if (!isset($stamps[$stamp])) { $stamps[$stamp] = new Date($stamp); } return $stamps[$stamp]; } /** * Returns a numeric year given a iso-8601 datetime * * @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS) * * @return int year (e.g. 2003) * @access protected */ function stampToYear($stamp) { $date = Calendar_Engine_PearDate::stampCollection($stamp); return (int)$date->year; } /** * Returns a numeric month given a iso-8601 datetime * * @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS) * * @return int month (e.g. 9) * @access protected */ function stampToMonth($stamp) { $date = Calendar_Engine_PearDate::stampCollection($stamp); return (int)$date->month; } /** * Returns a numeric day given a iso-8601 datetime * * @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS) * * @return int day (e.g. 15) * @access protected */ function stampToDay($stamp) { $date = Calendar_Engine_PearDate::stampCollection($stamp); return (int)$date->day; } /** * Returns a numeric hour given a iso-8601 datetime * * @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS) * * @return int hour (e.g. 13) * @access protected */ function stampToHour($stamp) { $date = Calendar_Engine_PearDate::stampCollection($stamp); return (int)$date->hour; } /** * Returns a numeric minute given a iso-8601 datetime * * @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS) * * @return int minute (e.g. 34) * @access protected */ function stampToMinute($stamp) { $date = Calendar_Engine_PearDate::stampCollection($stamp); return (int)$date->minute; } /** * Returns a numeric second given a iso-8601 datetime * * @param string $stamp iso-8601 datetime (YYYY-MM-DD HH:MM:SS) * * @return int second (e.g. 51) * @access protected */ function stampToSecond($stamp) { $date = Calendar_Engine_PearDate::stampCollection($stamp); return (int)$date->second; } /** * Returns a iso-8601 datetime * * @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 */ function dateToStamp($y, $m, $d, $h=0, $i=0, $s=0) { $r = array(); Calendar_Engine_PearDate::adjustDate($y, $m, $d, $h, $i, $s); $key = $y.$m.$d.$h.$i.$s; if (!isset($r[$key])) { $r[$key] = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $y, $m, $d, $h, $i, $s); } return $r[$key]; } /** * Set the correct date values (useful for math operations on dates) * * @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) { if ($s < 0) { $m -= floor($s / 60); $s = -$s % 60; } if ($s > 60) { $m += floor($s / 60); $s %= 60; } if ($i < 0) { $h -= floor($i / 60); $i = -$i % 60; } if ($i > 60) { $h += floor($i / 60); $i %= 60; } if ($h < 0) { $d -= floor($h / 24); $h = -$h % 24; } if ($h > 24) { $d += floor($h / 24); $h %= 24; } for(; $m < 1; $y--, $m+=12); for(; $m > 12; $y++, $m-=12); while ($d < 1) { if ($m > 1) { $m--; } else { $m = 12; $y--; } $d += Date_Calc::daysInMonth($m, $y); } for ($max_days = Date_Calc::daysInMonth($m, $y); $d > $max_days; ) { $d -= $max_days; if ($m < 12) { $m++; } else { $m = 1; $y++; } } } /** * The upper limit on years that the Calendar Engine can work with * * @return int 9999 * @access protected */ function getMaxYears() { return 9999; } /** * The lower limit on years that the Calendar Engine can work with * * @return int 0 * @access protected */ function getMinYears() { return 0; } /** * Returns the number of months in a year * * @param int $y year * * @return int (12) * @access protected */ function getMonthsInYear($y=null) { return 12; } /** * Returns the number of days in a month, given year and month * * @param int $y year (2003) * @param int $m month (9) * * @return int days in month * @access protected */ function getDaysInMonth($y, $m) { return (int)Date_Calc::daysInMonth($m, $y); } /** * Returns numeric representation of the day of the week in a month, * given year and month * * @param int $y year (2003) * @param int $m month (9) * * @return int from 0 to 7 * @access protected */ function getFirstDayInMonth($y, $m) { return (int)Date_Calc::dayOfWeek(1, $m, $y); } /** * Returns the number of days in a week * * @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) { return 7; } /** * Returns the number of the week in the year (ISO-8601), given a date * * @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! 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 $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; $end_of_week = (int)Date_Calc::nextDayOfWeek($weekEnd, 1, $m, $y, '%e', true); $w = 1; while ($d > $end_of_week) { ++$w; $end_of_week += $this->getDaysInWeek(); } return $w; } /** * Returns the number of weeks in the month * * @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) { $FDOM = Date_Calc::firstOfMonthWeekday($m, $y); if ($FDOM == 0) { $FDOM = $this->getDaysInWeek(); } if ($FDOM > $firstDay) { $daysInTheFirstWeek = $this->getDaysInWeek() - $FDOM + $firstDay; $weeks = 1; } else { $daysInTheFirstWeek = $firstDay - $FDOM; $weeks = 0; } $daysInTheFirstWeek %= $this->getDaysInWeek(); return (int)(ceil(($this->getDaysInMonth($y, $m) - $daysInTheFirstWeek) / $this->getDaysInWeek()) + $weeks); } /** * Returns the number of the day of the week (0=sunday, 1=monday...) * * @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) { return Date_Calc::dayOfWeek($d, $m, $y); } /** * Returns a list of integer days of the week beginning 0 * * @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) { return array(0, 1, 2, 3, 4, 5, 6); } /** * Returns the default first day of the week * * @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) { 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) { 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) { 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) { 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() ); } } ?>php-calendar-0.5.5/Calendar-0.5.5/Engine/UnixTS.php000066400000000000000000000316561212436242500213570ustar00rootroot00000000000000 * @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). * * @category Date and Time * @package Calendar * @author Harry Fuecks * @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 */ { /** * Makes sure a given timestamp is only ever parsed once *
     * array (
     *  [0] => year (e.g 2003),
     *  [1] => month (e.g 9),
     *  [2] => day (e.g 6),
     *  [3] => hour (e.g 14),
     *  [4] => minute (e.g 34),
     *  [5] => second (e.g 45),
     *  [6] => num days in month (e.g. 31),
     *  [7] => week in year (e.g. 50),
     *  [8] => day in week (e.g. 0 for Sunday)
     * )
     * 
* Uses a static variable to prevent date() being used twice * for a date which is already known * * @param int $stamp Unix timestamp * * @return array * @access protected */ function stampCollection($stamp) { static $stamps = array(); if ( !isset($stamps[$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]; } /** * Returns a numeric year given a timestamp * * @param int $stamp Unix timestamp * * @return int year (e.g. 2003) * @access protected */ function stampToYear($stamp) { $date = Calendar_Engine_UnixTS::stampCollection($stamp); return (int)$date[0]; } /** * Returns a numeric month given a timestamp * * @param int $stamp Unix timestamp * * @return int month (e.g. 9) * @access protected */ function stampToMonth($stamp) { $date = Calendar_Engine_UnixTS::stampCollection($stamp); return (int)$date[1]; } /** * Returns a numeric day given a timestamp * * @param int $stamp Unix timestamp * * @return int day (e.g. 15) * @access protected */ function stampToDay($stamp) { $date = Calendar_Engine_UnixTS::stampCollection($stamp); return (int)$date[2]; } /** * Returns a numeric hour given a timestamp * * @param int $stamp Unix timestamp * * @return int hour (e.g. 13) * @access protected */ function stampToHour($stamp) { $date = Calendar_Engine_UnixTS::stampCollection($stamp); return (int)$date[3]; } /** * Returns a numeric minute given a timestamp * * @param int $stamp Unix timestamp * * @return int minute (e.g. 34) * @access protected */ function stampToMinute($stamp) { $date = Calendar_Engine_UnixTS::stampCollection($stamp); return (int)$date[4]; } /** * Returns a numeric second given a timestamp * * @param int $stamp Unix timestamp * * @return int second (e.g. 51) * @access protected */ function stampToSecond($stamp) { $date = Calendar_Engine_UnixTS::stampCollection($stamp); return (int)$date[5]; } /** * Returns a timestamp * * @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])) { $dates[$y][$m][$d][$h][$i][$s] = @mktime($h, $i, $s, $m, $d, $y); } return $dates[$y][$m][$d][$h][$i][$s]; } /** * The upper limit on years that the Calendar Engine can work with * * @return int (2037) * @access protected */ function getMaxYears() { return 2037; } /** * 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 */ function getMinYears() { return $min = strpos(PHP_OS, 'WIN') === false ? 1902 : 1970; } /** * Returns the number of months in a year * * @param int $y year * * @return int (12) * @access protected */ function getMonthsInYear($y=null) { return 12; } /** * Returns the number of days in a month, given year and month * * @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); return $date[6]; } /** * Returns numeric representation of the day of the week in a month, * given year and month * * @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); return $date[8]; } /** * Returns the number of days in a week * * @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) { return 7; } /** * Returns the number of the week in the year (ISO-8601), given a date * * @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); return $date[7]; } /** * Returns the number of the week in the month, given a date * * @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 = (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 } $w = 1; while ($d > $end_of_week) { ++$w; $end_of_week += $this->getDaysInWeek(); } return $w; } /** * Returns the number of weeks in the month * * @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) { $FDOM = $this->getFirstDayInMonth($y, $m); if ($FDOM == 0) { $FDOM = $this->getDaysInWeek(); } if ($FDOM > $firstDay) { $daysInTheFirstWeek = $this->getDaysInWeek() - $FDOM + $firstDay; $weeks = 1; } else { $daysInTheFirstWeek = $firstDay - $FDOM; $weeks = 0; } $daysInTheFirstWeek %= $this->getDaysInWeek(); return (int)(ceil(($this->getDaysInMonth($y, $m) - $daysInTheFirstWeek) / $this->getDaysInWeek()) + $weeks); } /** * Returns the number of the day of the week (0=sunday, 1=monday...) * * @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); $date = Calendar_Engine_UnixTS::stampCollection($stamp); return $date[8]; } /** * Returns a list of integer days of the week beginning 0 * * @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) { return array(0, 1, 2, 3, 4, 5, 6); } /** * Returns the default first day of the week * * @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) { 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) { 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) { 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) { 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] ); } } ?>php-calendar-0.5.5/Calendar-0.5.5/Factory.php000066400000000000000000000153041212436242500203570ustar00rootroot00000000000000 * @author Lorenzo Alberton * @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 */ /** * Allows Calendar include path to be redefined * @ignore */ if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR); } /** * Load Calendar base class */ require_once CALENDAR_ROOT.'Calendar.php'; /** * Contains a factory method to return a Singleton instance of a class * implementing the Calendar_Engine_Interface.
* For Month objects, to control type of month returned, use CALENDAR_MONTH_STATE * constact e.g.; * * require_once 'Calendar/Factory.php'; * define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKDAYS); // Use Calendar_Month_Weekdays * // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKS); // Use Calendar_Month_Weeks * // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH); // Use Calendar_Month * * It defaults to building Calendar_Month objects.
* 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) * * @category Date and Time * @package Calendar * @author Harry Fuecks * @author Lorenzo Alberton * @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 $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) { $firstDay = defined('CALENDAR_FIRST_DAY_OF_WEEK') ? CALENDAR_FIRST_DAY_OF_WEEK : 1; switch ($type) { 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: 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 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) { $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; } } ?>php-calendar-0.5.5/Calendar-0.5.5/Hour.php000066400000000000000000000112031212436242500176570ustar00rootroot00000000000000 * @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 */ /** * Allows Calendar include path to be redefined * @ignore */ if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR); } /** * Load Calendar base class */ require_once CALENDAR_ROOT.'Calendar.php'; /** * Represents an Hour and builds Minutes * * require_once 'Calendar'.DIRECTORY_SEPARATOR.'Hour.php'; * $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().'
'; * } *
* * @category Date and Time * @package Calendar * @author Harry Fuecks * @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 $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) { parent::Calendar($y, $m, $d, $h); } /** * Builds the Minutes in the Hour * * @param array $sDates (optional) Calendar_Minute objects representing selected dates * * @return boolean * @access public */ function build($sDates = array()) { 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] = new Calendar_Minute($this->year, $this->month, $this->day, $this->hour, $i); } if (count($sDates) > 0) { $this->setSelection($sDates); } return true; } /** * Called from build() * * @param array $sDates Calendar_Minute objects representing selected dates * * @return void * @access private */ function setSelection($sDates) { foreach ($sDates as $sDate) { if ($this->year == $sDate->thisYear() && $this->month == $sDate->thisMonth() && $this->day == $sDate->thisDay() && $this->hour == $sDate->thisHour()) { $key = (int)$sDate->thisMinute(); if (isset($this->children[$key])) { $sDate->setSelected(); $this->children[$key] = $sDate; } } } } } ?>php-calendar-0.5.5/Calendar-0.5.5/Minute.php000066400000000000000000000113721212436242500202120ustar00rootroot00000000000000 * @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 */ /** * Allows Calendar include path to be redefined * @ignore */ if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR); } /** * Load Calendar base class */ require_once CALENDAR_ROOT.'Calendar.php'; /** * Represents a Minute and builds Seconds * * require_once 'Calendar'.DIRECTORY_SEPARATOR.'Minute.php'; * $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().'
'; * } *
* * @category Date and Time * @package Calendar * @author Harry Fuecks * @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 $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) { parent::Calendar($y, $m, $d, $h, $i); } /** * Builds the Calendar_Second objects * * @param array $sDates (optional) Calendar_Second objects representing selected dates * * @return boolean * @access public */ function build($sDates = array()) { 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++) { $this->children[$i] = new Calendar_Second($this->year, $this->month, $this->day, $this->hour, $this->minute, $i); } if (count($sDates) > 0) { $this->setSelection($sDates); } return true; } /** * Called from build() * * @param array $sDates Calendar_Second objects representing selected dates * * @return void * @access private */ function setSelection($sDates) { foreach ($sDates as $sDate) { if ($this->year == $sDate->thisYear() && $this->month == $sDate->thisMonth() && $this->day == $sDate->thisDay() && $this->hour == $sDate->thisHour() && $this->minute == $sDate->thisMinute()) { $key = (int)$sDate->thisSecond(); if (isset($this->children[$key])) { $sDate->setSelected(); $this->children[$key] = $sDate; } } } } } ?>php-calendar-0.5.5/Calendar-0.5.5/Month.php000066400000000000000000000115101212436242500200300ustar00rootroot00000000000000 * @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 */ /** * Allows Calendar include path to be redefined * @ignore */ if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR); } /** * Load Calendar base class */ require_once CALENDAR_ROOT.'Calendar.php'; /** * Represents a Month and builds Days * * require_once 'Calendar/Month.php'; * $Month = new Calendar_Month(2003, 10); // Oct 2003 * $Month->build(); // Build Calendar_Day objects * while ($Day = & $Month->fetch()) { * echo $Day->thisDay().'
'; * } *
* * @category Date and Time * @package Calendar * @author Harry Fuecks * @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 $firstDay first day of the week [optional] * * @access public */ function Calendar_Month($y, $m, $firstDay=null) { 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 $sDates (optional) Calendar_Day objects representing selected dates * * @return boolean * @access public */ function build($sDates = array()) { 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); } if (count($sDates) > 0) { $this->setSelection($sDates); } return true; } /** * Called from build() * * @param array $sDates Calendar_Day objects representing selected dates * * @return void * @access private */ function setSelection($sDates) { foreach ($sDates as $sDate) { if ($this->year == $sDate->thisYear() && $this->month == $sDate->thisMonth() ) { $key = $sDate->thisDay(); if (isset($this->children[$key])) { $sDate->setSelected(); $class = strtolower(get_class($sDate)); if ($class == 'calendar_day' || $class == 'calendar_decorator') { $sDate->setFirst($this->children[$key]->isFirst()); $sDate->setLast($this->children[$key]->isLast()); } $this->children[$key] = $sDate; } } } } } ?>php-calendar-0.5.5/Calendar-0.5.5/Month/000077500000000000000000000000001212436242500173215ustar00rootroot00000000000000php-calendar-0.5.5/Calendar-0.5.5/Month/Weekdays.php000066400000000000000000000154401212436242500216120ustar00rootroot00000000000000 * @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 */ /** * Allows Calendar include path to be redefined * @ignore */ if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR); } /** * Load Calendar base class */ require_once CALENDAR_ROOT.'Calendar.php'; /** * Load base month */ require_once CALENDAR_ROOT.'Month.php'; /** * Represents a Month and builds Days in tabular form
* * require_once 'Calendar/Month/Weekdays.php'; * $Month = new Calendar_Month_Weekdays(2003, 10); // Oct 2003 * $Month->build(); // Build Calendar_Day objects * while ($Day = & $Month->fetch()) { * if ($Day->isFirst()) { * echo ''; * } * if ($Day->isEmpty()) { * echo ' '; * } else { * echo ''.$Day->thisDay().''; * } * if ($Day->isLast()) { * echo ''; * } * } * * * @category Date and Time * @package Calendar * @author Harry Fuecks * @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 { /** * Instance of Calendar_Table_Helper * @var Calendar_Table_Helper * @access private */ var $tableHelper; /** * First day of the week * @access private * @var string */ var $firstDay; /** * Constructs Calendar_Month_Weekdays * * @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) { 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() */ function build($sDates = array()) { include_once CALENDAR_ROOT.'Table/Helper.php'; $this->tableHelper = new Calendar_Table_Helper($this, $this->firstDay); Calendar_Month::build($sDates); $this->buildEmptyDaysBefore(); $this->shiftDays(); $this->buildEmptyDaysAfter(); $this->setWeekMarkers(); return true; } /** * Prepends empty days before the real days in the month * * @return void * @access private */ function buildEmptyDaysBefore() { $eBefore = $this->tableHelper->getEmptyDaysBefore(); for ($i=0; $i < $eBefore; $i++) { $stamp = $this->cE->dateToStamp($this->year, $this->month, -$i); $Day = new Calendar_Day( $this->cE->stampToYear($stamp), $this->cE->stampToMonth($stamp), $this->cE->stampToDay($stamp)); $Day->setEmpty(); $Day->adjust(); array_unshift($this->children, $Day); } } /** * Shifts the array of children forward, if necessary * * @return void * @access private */ function shiftDays() { if (isset($this->children[0])) { array_unshift($this->children, null); unset($this->children[0]); } } /** * 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++) { $Day = new Calendar_Day($this->year, $this->month+1, $i); $Day->setEmpty(); $Day->adjust(); array_push($this->children, $Day); } } /** * 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( $this->thisYear(), $this->thisMonth(), $this->thisDay() ); $sDOM = $this->tableHelper->getNumTableDaysInMonth(); for ($i=1; $i <= $sDOM; $i+= $dIW) { $this->children[$i]->setFirst(); $this->children[$i+($dIW-1)]->setLast(); } } } ?>php-calendar-0.5.5/Calendar-0.5.5/Month/Weeks.php000066400000000000000000000131001212436242500211030ustar00rootroot00000000000000 * @author Lorenzo Alberton * @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 */ /** * Allows Calendar include path to be redefined * @ignore */ if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR); } /** * Load Calendar base class */ require_once CALENDAR_ROOT.'Calendar.php'; /** * Load base month */ require_once CALENDAR_ROOT.'Month.php'; /** * Represents a Month and builds Weeks * * require_once 'Calendar'.DIRECTORY_SEPARATOR.'Month'.DIRECTORY_SEPARATOR.'Weeks.php'; * $Month = new Calendar_Month_Weeks(2003, 10); // Oct 2003 * $Month->build(); // Build Calendar_Day objects * while ($Week = & $Month->fetch()) { * echo $Week->thisWeek().'
'; * } *
* * @category Date and Time * @package Calendar * @author Harry Fuecks * @author Lorenzo Alberton * @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 { /** * Instance of Calendar_Table_Helper * @var Calendar_Table_Helper * @access private */ var $tableHelper; /** * First day of the week * @access private * @var string */ var $firstDay; /** * Constructs Calendar_Month_Weeks * * @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) { 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 $sDates (optional) Calendar_Week objects representing selected dates * * @return boolean * @access public */ function build($sDates = array()) { 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->children[$i] = new Calendar_Week( $this->year, $this->month, $d, $this->tableHelper->getFirstDay()); } //used to set empty days $this->children[1]->setFirst(true); $this->children[$numWeeks]->setLast(true); // Handle selected weeks here if (count($sDates) > 0) { $this->setSelection($sDates); } return true; } /** * Called from build() * * @param array $sDates Calendar_Week objects representing selected dates * * @return void * @access private */ function setSelection($sDates) { foreach ($sDates as $sDate) { if ($this->year == $sDate->thisYear() && $this->month == $sDate->thisMonth()) { $key = $sDate->thisWeek('n_in_month'); if (isset($this->children[$key])) { $this->children[$key]->setSelected(); } } } } } ?>php-calendar-0.5.5/Calendar-0.5.5/Second.php000066400000000000000000000070271212436242500201660ustar00rootroot00000000000000 * @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 */ /** * Allows Calendar include path to be redefined * @ignore */ if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR); } /** * Load Calendar base class */ require_once CALENDAR_ROOT.'Calendar.php'; /** * Represents a Second
* Note: Seconds do not build other objects * so related methods are overridden to return NULL * * @category Date and Time * @package Calendar * @author Harry Fuecks * @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 $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) { parent::Calendar($y, $m, $d, $h, $i, $s); } /** * Overwrite build * * @return NULL */ function build() { return null; } /** * Overwrite fetch * * @return NULL */ function fetch() { return null; } /** * Overwrite fetchAll * * @return NULL */ function fetchAll() { return null; } /** * Overwrite size * * @return NULL */ function size() { return null; } } ?>php-calendar-0.5.5/Calendar-0.5.5/Table/000077500000000000000000000000001212436242500172635ustar00rootroot00000000000000php-calendar-0.5.5/Calendar-0.5.5/Table/Helper.php000066400000000000000000000221671212436242500212230ustar00rootroot00000000000000 * @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 * * @category Date and Time * @package Calendar * @author Harry Fuecks * @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 { /** * Instance of the Calendar object being helped. * @var object * @access private */ var $calendar; /** * Instance of the Calendar_Engine * @var object * @access private */ var $cE; /** * First day of the week * @access private * @var string */ var $firstDay; /** * The seven days of the week named * @access private * @var array */ var $weekDays; /** * Days of the week ordered with $firstDay at the beginning * @access private * @var array */ var $daysOfWeek = array(); /** * Days of the month built from days of the week * @access private * @var array */ var $daysOfMonth = array(); /** * Number of weeks in month * @var int * @access private */ var $numWeeks = null; /** * Number of emtpy days before real days begin in month * @var int * @access private */ var $emptyBefore = 0; /** * Constructs Calendar_Table_Helper * * @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) { $this->calendar = & $calendar; $this->cE = & $calendar->getEngine(); if (is_null($firstDay)) { $firstDay = $this->cE->getFirstDayOfWeek( $this->calendar->thisYear(), $this->calendar->thisMonth(), $this->calendar->thisDay() ); } $this->firstDay = $firstDay; $this->setFirstDay(); $this->setDaysOfMonth(); } /** * Constructs $this->daysOfWeek based on $this->firstDay * * @return void * @access private */ function setFirstDay() { $weekDays = $this->cE->getWeekDays( $this->calendar->thisYear(), $this->calendar->thisMonth(), $this->calendar->thisDay() ); $endDays = array(); $tmpDays = array(); $begin = false; foreach ($weekDays as $day) { if ($begin) { $endDays[] = $day; } else if ($day === $this->firstDay) { $begin = true; $endDays[] = $day; } else { $tmpDays[] = $day; } } $this->daysOfWeek = array_merge($endDays, $tmpDays); } /** * Constructs $this->daysOfMonth * * @return void * @access private */ function setDaysOfMonth() { $this->daysOfMonth = $this->daysOfWeek; $daysInMonth = $this->cE->getDaysInMonth( $this->calendar->thisYear(), $this->calendar->thisMonth()); $firstDayInMonth = $this->cE->getFirstDayInMonth( $this->calendar->thisYear(), $this->calendar->thisMonth()); $this->emptyBefore=0; foreach ($this->daysOfMonth as $dayOfWeek) { if ($firstDayInMonth == $dayOfWeek) { break; } $this->emptyBefore++; } $this->numWeeks = ceil( ($daysInMonth + $this->emptyBefore) / $this->cE->getDaysInWeek( $this->calendar->thisYear(), $this->calendar->thisMonth(), $this->calendar->thisDay() ) ); for ($i=1; $i < $this->numWeeks; $i++) { $this->daysOfMonth = array_merge($this->daysOfMonth, $this->daysOfWeek); } } /** * Returns the first day of the month * * @return int * @access protected * @see Calendar_Engine_Interface::getFirstDayOfWeek() */ function getFirstDay() { return $this->firstDay; } /** * Returns the order array of days in a week * * @return int * @access protected */ function getDaysOfWeek() { return $this->daysOfWeek; } /** * Returns the number of tabular weeks in a month * * @return int * @access protected */ function getNumWeeks() { return $this->numWeeks; } /** * Returns the number of real days + empty days * * @return int * @access protected */ function getNumTableDaysInMonth() { return count($this->daysOfMonth); } /** * Returns the number of empty days before the real days begin * * @return int * @access protected */ function getEmptyDaysBefore() { return $this->emptyBefore; } /** * Returns the index of the last real day in the month * * @todo Potential performance optimization with static * @return int * @access protected */ function getEmptyDaysAfter() { // Causes bug when displaying more than one month //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 */ function getEmptyDaysAfterOffset() { $eAfter = $this->getEmptyDaysAfter(); return $eAfter - ( $this->cE->getDaysInWeek( $this->calendar->thisYear(), $this->calendar->thisMonth(), $this->calendar->thisDay() ) * ($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) { $dow = $this->cE->getDayOfWeek($y, $m, $d); if ($dow > $firstDay) { $d -= ($dow - $firstDay); } if ($dow < $firstDay) { $d -= ( $this->cE->getDaysInWeek( $this->calendar->thisYear(), $this->calendar->thisMonth(), $this->calendar->thisDay() ) - $firstDay + $dow); } return $this->cE->dateToStamp($y, $m, $d); } } ?>php-calendar-0.5.5/Calendar-0.5.5/Util/000077500000000000000000000000001212436242500171515ustar00rootroot00000000000000php-calendar-0.5.5/Calendar-0.5.5/Util/Textual.php000066400000000000000000000245221212436242500213150ustar00rootroot00000000000000 * @author Lorenzo Alberton * @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 247250 2007-11-28 19:42:01Z quipo $ */ /** * Allows Calendar include path to be redefined * @ignore */ if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR); } /** * Load Calendar decorator base class */ require_once CALENDAR_ROOT.'Decorator.php'; /** * Static utlities to help with fetching textual representations of months and * days of the week. * * @category Date and Time * @package Calendar * @author Harry Fuecks * @author Lorenzo Alberton * @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 $format (optional) format of returned months (one|two|short|long) * * @return array * @access public * @static */ function monthNames($format = 'long') { $formats = array( 'one' => '%b', 'two' => '%b', 'short' => '%b', 'long' => '%B', ); if (!array_key_exists($format, $formats)) { $format = 'long'; } $months = array(); for ($i=1; $i<=12; $i++) { $stamp = mktime(0, 0, 0, $i, 1, 2003); $month = strftime($formats[$format], $stamp); switch($format) { case 'one': $month = substr($month, 0, 1); break; case 'two': $month = substr($month, 0, 2); break; } $months[$i] = $month; } return $months; } /** * Returns an array of 7 week day names (first index = 0) * * @param string $format (optional) format of returned days (one,two,short or long) * * @return array * @access public * @static */ function weekdayNames($format = 'long') { $formats = array( 'one' => '%a', 'two' => '%a', 'short' => '%a', 'long' => '%A', ); if (!array_key_exists($format, $formats)) { $format = 'long'; } $days = array(); for ($i=0; $i<=6; $i++) { $stamp = mktime(0, 0, 0, 11, $i+2, 2003); $day = strftime($formats[$format], $stamp); switch($format) { case 'one': $day = substr($day, 0, 1); break; case 'two': $day = substr($day, 0, 2); break; } $days[$i] = $day; } return $days; } /** * Returns textual representation of the previous month of the decorated calendar object * * @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') { $months = Calendar_Util_Textual::monthNames($format); return $months[$Calendar->prevMonth()]; } /** * Returns textual representation of the month of the decorated calendar object * * @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') { $months = Calendar_Util_Textual::monthNames($format); return $months[$Calendar->thisMonth()]; } /** * Returns textual representation of the next month of the decorated calendar object * * @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') { $months = Calendar_Util_Textual::monthNames($format); return $months[$Calendar->nextMonth()]; } /** * Returns textual representation of the previous day of week of the decorated calendar object * Note: Requires PEAR::Date * * @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') { $days = Calendar_Util_Textual::weekdayNames($format); $stamp = $Calendar->prevDay('timestamp'); $cE = $Calendar->getEngine(); include_once 'Date/Calc.php'; $day = Date_Calc::dayOfWeek($cE->stampToDay($stamp), $cE->stampToMonth($stamp), $cE->stampToYear($stamp)); return $days[$day]; } /** * Returns textual representation of the day of week of the decorated calendar object * Note: Requires PEAR::Date * * @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 thisDayName($Calendar, $format='long') { $days = Calendar_Util_Textual::weekdayNames($format); 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 $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 nextDayName($Calendar, $format='long') { $days = Calendar_Util_Textual::weekdayNames($format); $stamp = $Calendar->nextDay('timestamp'); $cE = $Calendar->getEngine(); include_once 'Date/Calc.php'; $day = Date_Calc::dayOfWeek($cE->stampToDay($stamp), $cE->stampToMonth($stamp), $cE->stampToYear($stamp)); return $days[$day]; } /** * 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 $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') { $days = Calendar_Util_Textual::weekdayNames($format); if (isset($Calendar->tableHelper)) { $ordereddays = $Calendar->tableHelper->getDaysOfWeek(); } else { //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); $i = 0; $returndays = array(); foreach ($ordereddays as $key => $value) { $returndays[$i] = $days[$key]; $i++; } return $returndays; } } ?>php-calendar-0.5.5/Calendar-0.5.5/Util/Uri.php000066400000000000000000000164061212436242500204300ustar00rootroot00000000000000 * @author Lorenzo Alberton * @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
* * $Day = new Calendar_Day(2003, 10, 23); * $Uri = new Calendar_Util_Uri('year', 'month', 'day'); * echo $Uri->prev($Day,'month'); // Displays year=2003&month=10 * echo $Uri->prev($Day,'day'); // Displays year=2003&month=10&day=22 * $Uri->seperator = '/'; * $Uri->scalar = true; * echo $Uri->prev($Day,'month'); // Displays 2003/10 * echo $Uri->prev($Day,'day'); // Displays 2003/10/22 * * * @category Date and Time * @package Calendar * @author Harry Fuecks * @author Lorenzo Alberton * @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 { /** * Uri fragments for year, month, day etc. * @var array * @access private */ var $uris = array(); /** * String to separate fragments with. * Set to just & for HTML. * For a scalar URL you might use / as the seperator * @var string (default XHTML &) * @access public */ var $separator = '&'; /** * To output a "scalar" string - variable names omitted. * Used for urls like index.php/2004/8/12 * @var boolean (default false) * @access public */ var $scalar = false; /** * Constructs Calendar_Decorator_Uri * The term "fragment" means name of a calendar GET variables in the URL * * @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) { $this->setFragments($y, $m, $d, $h, $i, $s); } /** * Sets the URI fragment names * * @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) { if (!is_null($y)) $this->uris['Year'] = $y; if (!is_null($m)) $this->uris['Month'] = $m; if (!is_null($d)) $this->uris['Day'] = $d; if (!is_null($h)) $this->uris['Hour'] = $h; if (!is_null($i)) $this->uris['Minute'] = $i; if (!is_null($s)) $this->uris['Second'] = $s; } /** * Gets the URI string for the previous calendar unit * * @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 prev($Calendar, $unit) { $method = 'prev'.$unit; $stamp = $Calendar->{$method}('timestamp'); return $this->buildUriString($Calendar, $method, $stamp); } /** * Gets the URI string for the current calendar unit * * @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; $stamp = $Calendar->{$method}('timestamp'); return $this->buildUriString($Calendar, $method, $stamp); } /** * Gets the URI string for the next calendar unit * * @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 next($Calendar, $unit) { $method = 'next'.$unit; $stamp = $Calendar->{$method}('timestamp'); return $this->buildUriString($Calendar, $method, $stamp); } /** * Build the URI string * * @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 */ function buildUriString($Calendar, $method, $stamp) { $uriString = ''; $cE = & $Calendar->getEngine(); $separator = ''; foreach ($this->uris as $unit => $uri) { $call = 'stampTo'.$unit; $uriString .= $separator; if (!$this->scalar) { $uriString .= $uri.'='; } $uriString .= $cE->{$call}($stamp); $separator = $this->separator; } return $uriString; } } ?>php-calendar-0.5.5/Calendar-0.5.5/Validator.php000066400000000000000000000246001212436242500206740ustar00rootroot00000000000000 * @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 */ /** * Validation Error Messages */ if (!defined('CALENDAR_VALUE_TOOSMALL')) { define('CALENDAR_VALUE_TOOSMALL', 'Too small: min = '); } if (!defined('CALENDAR_VALUE_TOOLARGE')) { define('CALENDAR_VALUE_TOOLARGE', 'Too large: max = '); } /** * Used to validate any given Calendar date object. Instances of this class * can be obtained from any data object using the getValidator method * * @category Date and Time * @package Calendar * @author Harry Fuecks * @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 { /** * Instance of the Calendar date object to validate * @var object * @access private */ var $calendar; /** * Instance of the Calendar_Engine * @var object * @access private */ var $cE; /** * Array of errors for validation failures * @var array * @access private */ var $errors = array(); /** * Constructs Calendar_Validator * * @param object &$calendar subclass of Calendar * * @access public */ function Calendar_Validator(&$calendar) { $this->calendar = & $calendar; $this->cE = & $calendar->getEngine(); } /** * Calls all the other isValidXXX() methods in the validator * * @return boolean * @access public */ function isValid() { $checks = array('isValidYear', 'isValidMonth', 'isValidDay', 'isValidHour', 'isValidMinute', 'isValidSecond'); $valid = true; foreach ($checks as $check) { if (!$this->{$check}()) { $valid = false; } } return $valid; } /** * Check whether this is a valid year * * @return boolean * @access public */ function isValidYear() { $y = $this->calendar->thisYear(); $min = $this->cE->getMinYears(); if ($min > $y) { $this->errors[] = new Calendar_Validation_Error( 'Year', $y, CALENDAR_VALUE_TOOSMALL.$min); return false; } $max = $this->cE->getMaxYears(); if ($y > $max) { $this->errors[] = new Calendar_Validation_Error( 'Year', $y, CALENDAR_VALUE_TOOLARGE.$max); return false; } return true; } /** * Check whether this is a valid month * * @return boolean * @access public */ function isValidMonth() { $m = $this->calendar->thisMonth(); $min = 1; if ($min > $m) { $this->errors[] = new Calendar_Validation_Error( 'Month', $m, CALENDAR_VALUE_TOOSMALL.$min); return false; } $max = $this->cE->getMonthsInYear($this->calendar->thisYear()); if ($m > $max) { $this->errors[] = new Calendar_Validation_Error( 'Month', $m, CALENDAR_VALUE_TOOLARGE.$max); return false; } return true; } /** * Check whether this is a valid day * * @return boolean * @access public */ function isValidDay() { $d = $this->calendar->thisDay(); $min = 1; if ($min > $d) { $this->errors[] = new Calendar_Validation_Error( 'Day', $d, CALENDAR_VALUE_TOOSMALL.$min); return false; } $max = $this->cE->getDaysInMonth( $this->calendar->thisYear(), $this->calendar->thisMonth() ); if ($d > $max) { $this->errors[] = new Calendar_Validation_Error( 'Day', $d, CALENDAR_VALUE_TOOLARGE.$max); return false; } return true; } /** * Check whether this is a valid hour * * @return boolean * @access public */ function isValidHour() { $h = $this->calendar->thisHour(); $min = 0; if ($min > $h) { $this->errors[] = new Calendar_Validation_Error( 'Hour', $h, CALENDAR_VALUE_TOOSMALL.$min); return false; } $max = ($this->cE->getHoursInDay($this->calendar->thisDay())-1); if ($h > $max) { $this->errors[] = new Calendar_Validation_Error( 'Hour', $h, CALENDAR_VALUE_TOOLARGE.$max); return false; } return true; } /** * Check whether this is a valid minute * * @return boolean * @access public */ function isValidMinute() { $i = $this->calendar->thisMinute(); $min = 0; if ($min > $i) { $this->errors[] = new Calendar_Validation_Error( 'Minute', $i, CALENDAR_VALUE_TOOSMALL.$min); return false; } $max = ($this->cE->getMinutesInHour($this->calendar->thisHour())-1); if ($i > $max) { $this->errors[] = new Calendar_Validation_Error( 'Minute', $i, CALENDAR_VALUE_TOOLARGE.$max); return false; } return true; } /** * Check whether this is a valid second * * @return boolean * @access public */ function isValidSecond() { $s = $this->calendar->thisSecond(); $min = 0; if ($min > $s) { $this->errors[] = new Calendar_Validation_Error( 'Second', $s, CALENDAR_VALUE_TOOSMALL.$min); return false; } $max = ($this->cE->getSecondsInMinute($this->calendar->thisMinute())-1); if ($s > $max) { $this->errors[] = new Calendar_Validation_Error( 'Second', $s, CALENDAR_VALUE_TOOLARGE.$max); return false; } return true; } /** * Iterates over any validation errors * * @return mixed either Calendar_Validation_Error or false * @access public */ function fetch() { $error = each($this->errors); if ($error) { return $error['value']; } else { reset($this->errors); return false; } } } /** * For Validation Error messages * * @category Date and Time * @package Calendar * @author Harry Fuecks * @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 { /** * Date unit (e.g. month,hour,second) which failed test * @var string * @access private */ var $unit; /** * Value of unit which failed test * @var int * @access private */ var $value; /** * Validation error message * @var string * @access private */ var $message; /** * Constructs Calendar_Validation_Error * * @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) { $this->unit = $unit; $this->value = $value; $this->message = $message; } /** * Returns the Date unit * * @return string * @access public */ function getUnit() { return $this->unit; } /** * Returns the value of the unit * * @return int * @access public */ function getValue() { return $this->value; } /** * Returns the validation error message * * @return string * @access public */ function getMessage() { return $this->message; } /** * Returns a string containing the unit, value and error message * * @return string * @access public */ function toString () { return $this->unit.' = '.$this->value.' ['.$this->message.']'; } } ?>php-calendar-0.5.5/Calendar-0.5.5/Week.php000066400000000000000000000350601212436242500176440ustar00rootroot00000000000000 * @author Lorenzo Alberton * @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 */ /** * Allows Calendar include path to be redefined * @ignore */ if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR); } /** * Load Calendar base class */ require_once CALENDAR_ROOT.'Calendar.php'; /** * Represents a Week and builds Days in tabular format
* * require_once 'Calendar/Week.php'; * $Week = new Calendar_Week(2003, 10, 1); Oct 2003, 1st tabular week * echo ''; * while ($Day = & $Week->fetch()) { * if ($Day->isEmpty()) { * echo ' '; * } else { * echo ''.$Day->thisDay().''; * } * } * echo ''; * * * @category Date and Time * @package Calendar * @author Harry Fuecks * @author Lorenzo Alberton * @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 { /** * Instance of Calendar_Table_Helper * @var Calendar_Table_Helper * @access private */ var $tableHelper; /** * Stores the timestamp of the first day of this week * @access private * @var object */ var $thisWeek; /** * Stores the timestamp of first day of previous week * @access private * @var object */ var $prevWeek; /** * Stores the timestamp of first day of next week * @access private * @var object */ var $nextWeek; /** * Used by build() to set empty days * @access private * @var boolean */ var $firstWeek = false; /** * Used by build() to set empty days * @access private * @var boolean */ var $lastWeek = false; /** * First day of the week (0=sunday, 1=monday...) * @access private * @var boolean */ var $firstDay = 1; /** * Constructs Week * * @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) { 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 $ts Unix or ISO-8601 timestamp * * @return void * @access public */ function setTimestamp($ts) { parent::setTimestamp($ts); $this->thisWeek = $this->tableHelper->getWeekStart( $this->year, $this->month, $this->day, $this->firstDay ); $this->prevWeek = $this->tableHelper->getWeekStart( $this->year, $this->month, $this->day - $this->cE->getDaysInWeek( $this->thisYear(), $this->thisMonth(), $this->thisDay() ), $this->firstDay ); $this->nextWeek = $this->tableHelper->getWeekStart( $this->year, $this->month, $this->day + $this->cE->getDaysInWeek( $this->thisYear(), $this->thisMonth(), $this->thisDay() ), $this->firstDay ); } /** * Builds Calendar_Day objects for this Week * * @param array $sDates (optional) Calendar_Day objects representing selected dates * * @return boolean * @access public */ function build($sDates = array()) { include_once CALENDAR_ROOT.'Day.php'; $year = $this->cE->stampToYear($this->thisWeek); $month = $this->cE->stampToMonth($this->thisWeek); $day = $this->cE->stampToDay($this->thisWeek); $end = $this->cE->getDaysInWeek( $this->thisYear(), $this->thisMonth(), $this->thisDay() ); 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) ); } //set empty days (@see Calendar_Month_Weeks::build()) if ($this->firstWeek) { $eBefore = $this->tableHelper->getEmptyDaysBefore(); for ($i=1; $i <= $eBefore; $i++) { $this->children[$i]->setEmpty(); } } if ($this->lastWeek) { $eAfter = $this->tableHelper->getEmptyDaysAfterOffset(); for ($i = $eAfter+1; $i <= $end; $i++) { $this->children[$i]->setEmpty(); } } if (count($sDates) > 0) { $this->setSelection($sDates); } return true; } /** * Set as first week of the month * * @param boolean $state whether it's first or not * * @return void * @access private */ function setFirst($state = true) { $this->firstWeek = $state; } /** * Set as last week of the month * * @param boolean $state whether it's lasst or not * * @return void * @access private */ function setLast($state = true) { $this->lastWeek = $state; } /** * Called from build() * * @param array $sDates Calendar_Day objects representing selected dates * * @return void * @access private */ function setSelection($sDates) { foreach ($sDates as $sDate) { foreach ($this->children as $key => $child) { if ($child->thisDay() == $sDate->thisDay() && $child->thisMonth() == $sDate->thisMonth() && $child->thisYear() == $sDate->thisYear() ) { $this->children[$key] = $sDate; $this->children[$key]->setSelected(); } } } 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; 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; } } /** * 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( $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; } } /** * 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; 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 */ function & getHelper() { return $this->tableHelper; } /** * Makes sure theres a value for $this->day * * @return void * @access private */ function findFirstDay() { if (!count($this->children) > 0) { $this->build(); foreach ($this->children as $Day) { if (!$Day->isEmpty()) { $this->day = $Day->thisDay(); break; } } } } } ?>php-calendar-0.5.5/Calendar-0.5.5/Year.php000066400000000000000000000120221212436242500176420ustar00rootroot00000000000000 * @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 */ /** * Allows Calendar include path to be redefined * @ignore */ if (!defined('CALENDAR_ROOT')) { define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR); } /** * Load Calendar base class */ require_once CALENDAR_ROOT.'Calendar.php'; /** * Represents a Year and builds Months
* * require_once 'Calendar'.DIRECTORY_SEPARATOR.'Year.php'; * $Year = & new Calendar_Year(2003, 10, 21); // 21st Oct 2003 * $Year->build(); // Build Calendar_Month objects * while ($Month = & $Year->fetch()) { * echo $Month->thisMonth().'
'; * } *
* * @category Date and Time * @package Calendar * @author Harry Fuecks * @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 $y year e.g. 2003 * * @access public */ function Calendar_Year($y) { parent::Calendar($y); } /** * Builds the Months of the Year.
* Note: by defining the constant CALENDAR_MONTH_STATE you can * control what class of Calendar_Month is built e.g.; * * require_once 'Calendar/Calendar_Year.php'; * define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKDAYS); // Use Calendar_Month_Weekdays * // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKS); // Use Calendar_Month_Weeks * // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH); // Use Calendar_Month * * It defaults to building Calendar_Month objects. * * @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) { include_once CALENDAR_ROOT.'Factory.php'; $this->firstDay = $this->defineFirstDayOfWeek($firstDay); $monthsInYear = $this->cE->getMonthsInYear($this->thisYear()); for ($i=1; $i <= $monthsInYear; $i++) { $this->children[$i] = Calendar_Factory::create('Month', $this->year, $i); } if (count($sDates) > 0) { $this->setSelection($sDates); } return true; } /** * Called from build() * * @param array $sDates array of Calendar_Month objects representing selected dates * * @return void * @access private */ function setSelection($sDates) { foreach ($sDates as $sDate) { if ($this->year == $sDate->thisYear()) { $key = $sDate->thisMonth(); if (isset($this->children[$key])) { $sDate->setSelected(); $this->children[$key] = $sDate; } } } } } ?>php-calendar-0.5.5/Calendar-0.5.5/docs/000077500000000000000000000000001212436242500171645ustar00rootroot00000000000000php-calendar-0.5.5/Calendar-0.5.5/docs/Readme000066400000000000000000000001511212436242500203010ustar00rootroot00000000000000Readme See the PEAR manual at http://pear.php.net/manual/en/package.datetime.calendar.php for details.php-calendar-0.5.5/Calendar-0.5.5/docs/examples/000077500000000000000000000000001212436242500210025ustar00rootroot00000000000000php-calendar-0.5.5/Calendar-0.5.5/docs/examples/1.php000066400000000000000000000063311212436242500216560ustar00rootroot00000000000000' ); echo ( 'The time is now: '.date('Y M d H:i:s',$c->getTimestamp()).'
' ); $i = 1; echo ( '

First Iteration

' ); echo ( '

The first iteration is more "expensive", the calendar data structures having to be built.

' ); $start = getmicrotime(); $c->build(); while ( $e = $c->fetch() ) { $class = strtolower(get_class($e)); $link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay(). "&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond(); $method = 'this'.str_replace('calendar_','',$class); echo ( "".$e->{$method}()." : " ); if ( ($i % 10) == 0 ) { echo ( '
' ); } $i++; } echo ( '

Took: '.(getmicrotime()-$start).' seconds

' ); $i = 1; echo ( '

Second Iteration

' ); echo ( '

This second iteration is faster, the data structures being re-used

' ); $start = getmicrotime(); while ( $e = $c->fetch() ) { $class = strtolower(get_class($e)); $link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay(). "&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond(); $method = 'this'.str_replace('calendar_','',$class); echo ( "".$e->{$method}()." : " ); if ( ($i % 10) == 0 ) { echo ( '
' ); } $i++; } echo ( '

Took: '.(getmicrotime()-$start).' seconds

' ); ?>php-calendar-0.5.5/Calendar-0.5.5/docs/examples/1.phps000066400000000000000000000063311212436242500220410ustar00rootroot00000000000000' ); echo ( 'The time is now: '.date('Y M d H:i:s',$c->getTimestamp()).'
' ); $i = 1; echo ( '

First Iteration

' ); echo ( '

The first iteration is more "expensive", the calendar data structures having to be built.

' ); $start = getmicrotime(); $c->build(); while ( $e = $c->fetch() ) { $class = strtolower(get_class($e)); $link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay(). "&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond(); $method = 'this'.str_replace('calendar_','',$class); echo ( "".$e->{$method}()." : " ); if ( ($i % 10) == 0 ) { echo ( '
' ); } $i++; } echo ( '

Took: '.(getmicrotime()-$start).' seconds

' ); $i = 1; echo ( '

Second Iteration

' ); echo ( '

This second iteration is faster, the data structures being re-used

' ); $start = getmicrotime(); while ( $e = $c->fetch() ) { $class = strtolower(get_class($e)); $link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay(). "&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond(); $method = 'this'.str_replace('calendar_','',$class); echo ( "".$e->{$method}()." : " ); if ( ($i % 10) == 0 ) { echo ( '
' ); } $i++; } echo ( '

Took: '.(getmicrotime()-$start).' seconds

' ); ?>php-calendar-0.5.5/Calendar-0.5.5/docs/examples/10.php000066400000000000000000000055111212436242500217350ustar00rootroot00000000000000build(); ?> A Simple Decorator

A Simple Decorator

fetch() ) { if ( $Day->isFirst() ) { echo ( "\n\n" ); } if ( $Day->isEmpty() ) { echo ( "" ); } else { echo ( "" ); } if ( $Day->isLast() ) { echo ( "\n\n" ); } } ?>
thisMonth() ); ?>
 ".$Day->thisDay()."
Prev   Next
php-calendar-0.5.5/Calendar-0.5.5/docs/examples/10.phps000066400000000000000000000055111212436242500221200ustar00rootroot00000000000000build(); ?> A Simple Decorator

A Simple Decorator

fetch() ) { if ( $Day->isFirst() ) { echo ( "\n\n" ); } if ( $Day->isEmpty() ) { echo ( "" ); } else { echo ( "" ); } if ( $Day->isLast() ) { echo ( "\n\n" ); } } ?>
thisMonth() ); ?>
 ".$Day->thisDay()."
Prev   Next
php-calendar-0.5.5/Calendar-0.5.5/docs/examples/11.php000066400000000000000000000061421212436242500217370ustar00rootroot00000000000000entry = $entry; } function getEntry() { return $this->entry; } } // Create a day to view the hours for $Day = & new Calendar_Day(2003,10,24); // A sample query to get the data for today (NOT ACTUALLY USED HERE) $sql = " SELECT * FROM diary WHERE eventtime >= '".$Day->thisDay(TRUE)."' AND eventtime < '".$Day->nextDay(TRUE)."';"; // An array simulating data from a database $result = array ( array('eventtime'=>mktime(9,0,0,10,24,2003),'entry'=>'Meeting with sales team'), array('eventtime'=>mktime(11,0,0,10,24,2003),'entry'=>'Conference call with Widget Inc.'), array('eventtime'=>mktime(15,0,0,10,24,2003),'entry'=>'Presentation to board of directors') ); // An array to place selected hours in $selection = array(); // Loop through the "database result" foreach ( $result as $row ) { $Hour = new Calendar_Hour(2000,1,1,1); // Create Hour with dummy values $Hour->setTimeStamp($row['eventtime']); // Set the real time with setTimeStamp // Create the decorator, passing it the Hour $DiaryEvent = new DiaryEvent($Hour); // Attach the payload $DiaryEvent->setEntry($row['entry']); // Add the decorator to the selection $selection[] = $DiaryEvent; } // Build the hours in that day, passing the selection $Day->build($selection); ?> Passing a Selection Payload with a Decorator

Passing a Selection "Payload" using a Decorator

fetch() ) { $hour = $Hour->thisHour(); $minute = $Hour->thisMinute(); // Office hours only... if ( $hour >= 8 && $hour <= 18 ) { echo ( "\n" ); echo ( "\n" ); // If the hour is selected, call the decorator method... if ( $Hour->isSelected() ) { echo ( "\n" ); } else { echo ( "\n" ); } echo ( "\n" ); } } ?>
Your Schedule for thisDay(TRUE)) ); ?>
Time Entry
$hour:$minute".$Hour->getEntry()." 

The query to fetch this data, with help from PEAR::Calendar, might be;


php-calendar-0.5.5/Calendar-0.5.5/docs/examples/11.phps000066400000000000000000000061421212436242500221220ustar00rootroot00000000000000entry = $entry; } function getEntry() { return $this->entry; } } // Create a day to view the hours for $Day = & new Calendar_Day(2003,10,24); // A sample query to get the data for today (NOT ACTUALLY USED HERE) $sql = " SELECT * FROM diary WHERE eventtime >= '".$Day->thisDay(TRUE)."' AND eventtime < '".$Day->nextDay(TRUE)."';"; // An array simulating data from a database $result = array ( array('eventtime'=>mktime(9,0,0,10,24,2003),'entry'=>'Meeting with sales team'), array('eventtime'=>mktime(11,0,0,10,24,2003),'entry'=>'Conference call with Widget Inc.'), array('eventtime'=>mktime(15,0,0,10,24,2003),'entry'=>'Presentation to board of directors') ); // An array to place selected hours in $selection = array(); // Loop through the "database result" foreach ( $result as $row ) { $Hour = new Calendar_Hour(2000,1,1,1); // Create Hour with dummy values $Hour->setTimeStamp($row['eventtime']); // Set the real time with setTimeStamp // Create the decorator, passing it the Hour $DiaryEvent = new DiaryEvent($Hour); // Attach the payload $DiaryEvent->setEntry($row['entry']); // Add the decorator to the selection $selection[] = $DiaryEvent; } // Build the hours in that day, passing the selection $Day->build($selection); ?> Passing a Selection Payload with a Decorator

Passing a Selection "Payload" using a Decorator

fetch() ) { $hour = $Hour->thisHour(); $minute = $Hour->thisMinute(); // Office hours only... if ( $hour >= 8 && $hour <= 18 ) { echo ( "\n" ); echo ( "\n" ); // If the hour is selected, call the decorator method... if ( $Hour->isSelected() ) { echo ( "\n" ); } else { echo ( "\n" ); } echo ( "\n" ); } } ?>
Your Schedule for thisDay(TRUE)) ); ?>
Time Entry
$hour:$minute".$Hour->getEntry()." 

The query to fetch this data, with help from PEAR::Calendar, might be;


php-calendar-0.5.5/Calendar-0.5.5/docs/examples/12.php000066400000000000000000000047041212436242500217420ustar00rootroot00000000000000build(); ?> <?php echo ( $Year->thisYear() ); ?> fetch() ) { switch ( $i ) { case 0: echo ( "\n" ); break; case 3: case 6: case 9: echo ( "\n\n" ); break; case 12: echo ( "\n" ); break; } echo ( "\n" ); $i++; } ?>
thisYear() ); ?>
\n\n" ); echo ( "" ); echo ( "\n\n" ); $Month->build(); while ( $Day = $Month->fetch() ) { if ( $Day->isFirst() ) { echo ( "\n" ); } if ( $Day->isEmpty() ) { echo ( "\n" ); } else { echo ( "\n" ); } if ( $Day->isLast() ) { echo ( "\n" ); } } echo ( "
".date('F',$Month->thisMonth(TRUE))."
MTWTFSS
 ".$Day->thisDay()."
\n

Took:

php-calendar-0.5.5/Calendar-0.5.5/docs/examples/12.phps000066400000000000000000000047041212436242500221250ustar00rootroot00000000000000build(); ?> <?php echo ( $Year->thisYear() ); ?> fetch() ) { switch ( $i ) { case 0: echo ( "\n" ); break; case 3: case 6: case 9: echo ( "\n\n" ); break; case 12: echo ( "\n" ); break; } echo ( "\n" ); $i++; } ?>
thisYear() ); ?>
\n\n" ); echo ( "" ); echo ( "\n\n" ); $Month->build(); while ( $Day = $Month->fetch() ) { if ( $Day->isFirst() ) { echo ( "\n" ); } if ( $Day->isEmpty() ) { echo ( "\n" ); } else { echo ( "\n" ); } if ( $Day->isLast() ) { echo ( "\n" ); } } echo ( "
".date('F',$Month->thisMonth(TRUE))."
MTWTFSS
 ".$Day->thisDay()."
\n

Took:

php-calendar-0.5.5/Calendar-0.5.5/docs/examples/13.php000066400000000000000000000066711212436242500217500ustar00rootroot00000000000000getTimestamp()); echo ( '

Using PEAR::Date engine

' ); echo ( 'Viewing: '.@$_GET['view'].'
' ); echo ( 'The time is now: '.$date->format('%Y %a %e %T').'
' ); $i = 1; echo ( '

First Iteration

' ); echo ( '

The first iteration is more "expensive", the calendar data structures having to be built.

' ); $start = getmicrotime(); $c->build(); while ( $e = $c->fetch() ) { $class = strtolower(get_class($e)); $link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay(). "&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond(); $method = 'this'.str_replace('calendar_','',$class); echo ( "".$e->{$method}()." : " ); if ( ($i % 10) == 0 ) { echo ( '
' ); } $i++; } echo ( '

Took: '.(getmicrotime()-$start).' seconds

' ); $i = 1; echo ( '

Second Iteration

' ); echo ( '

This second iteration is faster, the data structures being re-used

' ); $start = getmicrotime(); while ( $e = $c->fetch() ) { $class = strtolower(get_class($e)); $link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay(). "&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond(); $method = 'this'.str_replace('calendar_','',$class); echo ( "".$e->{$method}()." : " ); if ( ($i % 10) == 0 ) { echo ( '
' ); } $i++; } echo ( '

Took: '.(getmicrotime()-$start).' seconds

' ); ?>php-calendar-0.5.5/Calendar-0.5.5/docs/examples/13.phps000066400000000000000000000066711212436242500221330ustar00rootroot00000000000000getTimestamp()); echo ( '

Using PEAR::Date engine

' ); echo ( 'Viewing: '.@$_GET['view'].'
' ); echo ( 'The time is now: '.$date->format('%Y %a %e %T').'
' ); $i = 1; echo ( '

First Iteration

' ); echo ( '

The first iteration is more "expensive", the calendar data structures having to be built.

' ); $start = getmicrotime(); $c->build(); while ( $e = $c->fetch() ) { $class = strtolower(get_class($e)); $link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay(). "&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond(); $method = 'this'.str_replace('calendar_','',$class); echo ( "".$e->{$method}()." : " ); if ( ($i % 10) == 0 ) { echo ( '
' ); } $i++; } echo ( '

Took: '.(getmicrotime()-$start).' seconds

' ); $i = 1; echo ( '

Second Iteration

' ); echo ( '

This second iteration is faster, the data structures being re-used

' ); $start = getmicrotime(); while ( $e = $c->fetch() ) { $class = strtolower(get_class($e)); $link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay(). "&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond(); $method = 'this'.str_replace('calendar_','',$class); echo ( "".$e->{$method}()." : " ); if ( ($i % 10) == 0 ) { echo ( '
' ); } $i++; } echo ( '

Took: '.(getmicrotime()-$start).' seconds

' ); ?>php-calendar-0.5.5/Calendar-0.5.5/docs/examples/14.php000066400000000000000000000065711212436242500217500ustar00rootroot00000000000000build($selectedDays); // Construct strings for next/previous links $PMonth = $month->prevMonth('object'); // Get previous month as object $prev = $_SERVER['PHP_SELF'].'?y='.$PMonth->thisYear().'&m='.$PMonth->thisMonth().'&d='.$PMonth->thisDay(); $NMonth = $month->nextMonth('object'); $next = $_SERVER['PHP_SELF'].'?y='.$NMonth->thisYear().'&m='.$NMonth->thisMonth().'&d='.$NMonth->thisDay(); $thisDate = new Date($month->thisMonth('timestamp')); ?> Calendar using PEAR::Date Engine

Calendar using PEAR::Date Engine

fetch()) { // Build a link string for each day $link = $_SERVER['PHP_SELF']. '?y='.$day->thisYear(). '&m='.$day->thisMonth(). '&d='.$day->thisDay(); // isFirst() to find start of week if ($day->isFirst()) echo "\n"; if ($day->isSelected()) { echo ''."\n"; } else if ($day->isEmpty()) { echo ''."\n"; } else { echo ''."\n"; } // isLast() to find end of week if ($day->isLast()) { echo "\n"; } } ?>
format('%B %Y'); ?>
M T W T F S S
'.$day->thisDay().' '.$day->thisDay().'
<<   >>
Took: '.(getmicrotime()-$start).' seconds

'; ?> php-calendar-0.5.5/Calendar-0.5.5/docs/examples/14.phps000066400000000000000000000065711212436242500221330ustar00rootroot00000000000000build($selectedDays); // Construct strings for next/previous links $PMonth = $month->prevMonth('object'); // Get previous month as object $prev = $_SERVER['PHP_SELF'].'?y='.$PMonth->thisYear().'&m='.$PMonth->thisMonth().'&d='.$PMonth->thisDay(); $NMonth = $month->nextMonth('object'); $next = $_SERVER['PHP_SELF'].'?y='.$NMonth->thisYear().'&m='.$NMonth->thisMonth().'&d='.$NMonth->thisDay(); $thisDate = new Date($month->thisMonth('timestamp')); ?> Calendar using PEAR::Date Engine

Calendar using PEAR::Date Engine

fetch()) { // Build a link string for each day $link = $_SERVER['PHP_SELF']. '?y='.$day->thisYear(). '&m='.$day->thisMonth(). '&d='.$day->thisDay(); // isFirst() to find start of week if ($day->isFirst()) echo "\n"; if ($day->isSelected()) { echo ''."\n"; } else if ($day->isEmpty()) { echo ''."\n"; } else { echo ''."\n"; } // isLast() to find end of week if ($day->isLast()) { echo "\n"; } } ?>
format('%B %Y'); ?>
M T W T F S S
'.$day->thisDay().' '.$day->thisDay().'
<<   >>
Took: '.(getmicrotime()-$start).' seconds

'; ?> php-calendar-0.5.5/Calendar-0.5.5/docs/examples/15.php000066400000000000000000000031401212436242500217360ustar00rootroot00000000000000getValidator(); if (!$Validator->isValidWeek()) { die ('Please enter a valid week!'); } */ ?> Paging Weeks

Paging Weeks

Week: thisWeek().' '.date('F Y',$Week->thisMonth(true)); ?>

build(); while ($Day = $Week->fetch()) { echo '

'.date('jS F',$Day->thisDay(true))."

\n"; } $days = $Week->fetchAll(); $prevWeek = $Week->prevWeek('array'); $prevWeekLink = $_SERVER['PHP_SELF']. '?y='.$prevWeek['year']. '&m='.$prevWeek['month']. '&d='.$prevWeek['day']; $nextWeek = $Week->nextWeek('array'); $nextWeekLink = $_SERVER['PHP_SELF']. '?y='.$nextWeek['year']. '&m='.$nextWeek['month']. '&d='.$nextWeek['day']; ?>

<< | >>

php-calendar-0.5.5/Calendar-0.5.5/docs/examples/15.phps000066400000000000000000000031401212436242500221210ustar00rootroot00000000000000getValidator(); if (!$Validator->isValidWeek()) { die ('Please enter a valid week!'); } */ ?> Paging Weeks

Paging Weeks

Week: thisWeek().' '.date('F Y',$Week->thisMonth(true)); ?>

build(); while ($Day = $Week->fetch()) { echo '

'.date('jS F',$Day->thisDay(true))."

\n"; } $days = $Week->fetchAll(); $prevWeek = $Week->prevWeek('array'); $prevWeekLink = $_SERVER['PHP_SELF']. '?y='.$prevWeek['year']. '&m='.$prevWeek['month']. '&d='.$prevWeek['day']; $nextWeek = $Week->nextWeek('array'); $nextWeekLink = $_SERVER['PHP_SELF']. '?y='.$nextWeek['year']. '&m='.$nextWeek['month']. '&d='.$nextWeek['day']; ?>

<< | >>

php-calendar-0.5.5/Calendar-0.5.5/docs/examples/16.php000066400000000000000000000021061212436242500217400ustar00rootroot00000000000000The current month is ' .$Calendar->thisMonth().' of year '.$Calendar->thisYear().'

'); $Uri = & new Calendar_Decorator_Uri($Calendar); $Uri->setFragments('jahr','monat'); // $Uri->setSeperator('/'); // Default is & // $Uri->setScalar(); // Omit variable names echo ( "
Previous Uri:\t".$Uri->prev('month')."\n" );
echo ( "This Uri:\t".$Uri->this('month')."\n" );
echo ( "Next Uri:\t".$Uri->next('month')."\n
" ); ?>

Prev : Next

php-calendar-0.5.5/Calendar-0.5.5/docs/examples/16.phps000066400000000000000000000021061212436242500221230ustar00rootroot00000000000000The current month is ' .$Calendar->thisMonth().' of year '.$Calendar->thisYear().'

'); $Uri = & new Calendar_Decorator_Uri($Calendar); $Uri->setFragments('jahr','monat'); // $Uri->setSeperator('/'); // Default is & // $Uri->setScalar(); // Omit variable names echo ( "
Previous Uri:\t".$Uri->prev('month')."\n" );
echo ( "This Uri:\t".$Uri->this('month')."\n" );
echo ( "Next Uri:\t".$Uri->next('month')."\n
" ); ?>

Prev : Next

php-calendar-0.5.5/Calendar-0.5.5/docs/examples/17.php000066400000000000000000000043611212436242500217460ustar00rootroot00000000000000Calling: Calendar_Decorator_Textual::monthNames('long');
";
print_r(Calendar_Decorator_Textual::monthNames('long'));
echo '
'; echo "
Calling: Calendar_Decorator_Textual::weekdayNames('two');
";
print_r(Calendar_Decorator_Textual::weekdayNames('two'));
echo '
'; echo "
Creating: new Calendar_Day(date('Y'), date('n'), date('d'));
"; $Calendar = new Calendar_Day(date('Y'), date('n'), date('d')); // Decorate $Textual = & new Calendar_Decorator_Textual($Calendar); echo '
Previous month is: '.$Textual->prevMonthName('two').'
'; echo 'This month is: '.$Textual->thisMonthName('short').'
'; echo 'Next month is: '.$Textual->nextMonthName().'

'; echo 'Previous day is: '.$Textual->prevDayName().'
'; echo 'This day is: '.$Textual->thisDayName('short').'
'; echo 'Next day is: '.$Textual->nextDayName('one').'

'; echo "Creating: new Calendar_Month_Weekdays(date('Y'), date('n'), 6); - Saturday is first day of week
"; $Calendar = new Calendar_Month_Weekdays(date('Y'), date('n'), 6); // Decorate $Textual = & new Calendar_Decorator_Textual($Calendar); ?>

Rendering calendar....

orderedWeekdays('short'); foreach ($dayheaders as $dayheader) { echo ''; } ?> build(); while ($Day = $Calendar->fetch()) { if ($Day->isFirst()) { echo "\n"; } if ($Day->isEmpty()) { echo ''; } else { echo ''; } if ($Day->isLast()) { echo "\n"; } } ?>
thisMonthName().' '.$Textual->thisYear(); ?>
'.$dayheader.'
 '.$Day->thisDay().'
php-calendar-0.5.5/Calendar-0.5.5/docs/examples/17.phps000066400000000000000000000043611212436242500221310ustar00rootroot00000000000000Calling: Calendar_Decorator_Textual::monthNames('long');
";
print_r(Calendar_Decorator_Textual::monthNames('long'));
echo '
'; echo "
Calling: Calendar_Decorator_Textual::weekdayNames('two');
";
print_r(Calendar_Decorator_Textual::weekdayNames('two'));
echo '
'; echo "
Creating: new Calendar_Day(date('Y'), date('n'), date('d'));
"; $Calendar = new Calendar_Day(date('Y'), date('n'), date('d')); // Decorate $Textual = & new Calendar_Decorator_Textual($Calendar); echo '
Previous month is: '.$Textual->prevMonthName('two').'
'; echo 'This month is: '.$Textual->thisMonthName('short').'
'; echo 'Next month is: '.$Textual->nextMonthName().'

'; echo 'Previous day is: '.$Textual->prevDayName().'
'; echo 'This day is: '.$Textual->thisDayName('short').'
'; echo 'Next day is: '.$Textual->nextDayName('one').'

'; echo "Creating: new Calendar_Month_Weekdays(date('Y'), date('n'), 6); - Saturday is first day of week
"; $Calendar = new Calendar_Month_Weekdays(date('Y'), date('n'), 6); // Decorate $Textual = & new Calendar_Decorator_Textual($Calendar); ?>

Rendering calendar....

orderedWeekdays('short'); foreach ($dayheaders as $dayheader) { echo ''; } ?> build(); while ($Day = $Calendar->fetch()) { if ($Day->isFirst()) { echo "\n"; } if ($Day->isEmpty()) { echo ''; } else { echo ''; } if ($Day->isLast()) { echo "\n"; } } ?>
thisMonthName().' '.$Textual->thisYear(); ?>
'.$dayheader.'
 '.$Day->thisDay().'
php-calendar-0.5.5/Calendar-0.5.5/docs/examples/18.php000066400000000000000000000016661212436242500217540ustar00rootroot00000000000000'.parent::thisDay().''; } } $Month = new Calendar_Month(date('Y'), date('n')); $Wrapper = & new Calendar_Decorator_Wrapper($Month); $Wrapper->build(); echo '

The Wrapper decorator

'; echo 'Day numbers are rendered in bold

'; while ($DecoratedDay = $Wrapper->fetch('MyBoldDecorator')) { echo $DecoratedDay->thisDay().'
'; } ?>php-calendar-0.5.5/Calendar-0.5.5/docs/examples/18.phps000066400000000000000000000016661212436242500221370ustar00rootroot00000000000000'.parent::thisDay().''; } } $Month = new Calendar_Month(date('Y'), date('n')); $Wrapper = & new Calendar_Decorator_Wrapper($Month); $Wrapper->build(); echo '

The Wrapper decorator

'; echo 'Day numbers are rendered in bold

'; while ($DecoratedDay = $Wrapper->fetch('MyBoldDecorator')) { echo $DecoratedDay->thisDay().'
'; } ?>php-calendar-0.5.5/Calendar-0.5.5/docs/examples/19.php000066400000000000000000000013201212436242500217400ustar00rootroot00000000000000setFirstDay(0); // Make Sunday first Day echo 'Yesterday: '.$WeekDay->prevWeekDay().'
'; echo 'Today: '.$WeekDay->thisWeekDay().'
'; echo 'Tomorrow: '.$WeekDay->nextWeekDay().'
'; $WeekDay->build(); echo 'Hours today:
'; while ( $Hour = $WeekDay->fetch() ) { echo $Hour->thisHour().'
'; } ?>php-calendar-0.5.5/Calendar-0.5.5/docs/examples/19.phps000066400000000000000000000013201212436242500221230ustar00rootroot00000000000000setFirstDay(0); // Make Sunday first Day echo 'Yesterday: '.$WeekDay->prevWeekDay().'
'; echo 'Today: '.$WeekDay->thisWeekDay().'
'; echo 'Tomorrow: '.$WeekDay->nextWeekDay().'
'; $WeekDay->build(); echo 'Hours today:
'; while ( $Hour = $WeekDay->fetch() ) { echo $Hour->thisHour().'
'; } ?>php-calendar-0.5.5/Calendar-0.5.5/docs/examples/2.php000066400000000000000000000070771212436242500216670ustar00rootroot00000000000000build(); // Construct strings for next/previous links $PMonth = $Month->prevMonth('object'); // Get previous month as object $prev = $_SERVER['PHP_SELF'].'?y='.$PMonth->thisYear().'&m='.$PMonth->thisMonth().'&d='.$PMonth->thisDay(); $NMonth = $Month->nextMonth('object'); $next = $_SERVER['PHP_SELF'].'?y='.$NMonth->thisYear().'&m='.$NMonth->thisMonth().'&d='.$NMonth->thisDay(); ?> Calendar

Build with Calendar_Month_Weeks::build() then Calendar_Week::build()

fetch()) { echo "\n"; // Build the days in the week, passing the selected days $Week->build($selectedDays); while ($Day = $Week->fetch()) { // Build a link string for each day $link = $_SERVER['PHP_SELF']. '?y='.$Day->thisYear(). '&m='.$Day->thisMonth(). '&d='.$Day->thisDay(); // Check to see if day is selected if ($Day->isSelected()) { echo ''."\n"; // Check to see if day is empty } else if ($Day->isEmpty()) { echo ''."\n"; } else { echo ''."\n"; } } echo ''."\n"; } ?>
getTimeStamp()); ?>
M T W T F S S
'.$Day->thisDay().''.$Day->thisDay().''.$Day->thisDay().'
<<   >>
Took: '.(getmicrotime()-$start).' seconds

'; ?> php-calendar-0.5.5/Calendar-0.5.5/docs/examples/2.phps000066400000000000000000000070771212436242500220520ustar00rootroot00000000000000build(); // Construct strings for next/previous links $PMonth = $Month->prevMonth('object'); // Get previous month as object $prev = $_SERVER['PHP_SELF'].'?y='.$PMonth->thisYear().'&m='.$PMonth->thisMonth().'&d='.$PMonth->thisDay(); $NMonth = $Month->nextMonth('object'); $next = $_SERVER['PHP_SELF'].'?y='.$NMonth->thisYear().'&m='.$NMonth->thisMonth().'&d='.$NMonth->thisDay(); ?> Calendar

Build with Calendar_Month_Weeks::build() then Calendar_Week::build()

fetch()) { echo "\n"; // Build the days in the week, passing the selected days $Week->build($selectedDays); while ($Day = $Week->fetch()) { // Build a link string for each day $link = $_SERVER['PHP_SELF']. '?y='.$Day->thisYear(). '&m='.$Day->thisMonth(). '&d='.$Day->thisDay(); // Check to see if day is selected if ($Day->isSelected()) { echo ''."\n"; // Check to see if day is empty } else if ($Day->isEmpty()) { echo ''."\n"; } else { echo ''."\n"; } } echo ''."\n"; } ?>
getTimeStamp()); ?>
M T W T F S S
'.$Day->thisDay().''.$Day->thisDay().''.$Day->thisDay().'
<<   >>
Took: '.(getmicrotime()-$start).' seconds

'; ?> php-calendar-0.5.5/Calendar-0.5.5/docs/examples/20.php000066400000000000000000000143171212436242500217420ustar00rootroot00000000000000entries[] = $entry; } function getEntry() { $entry = each($this->entries); if ($entry) { return $entry['value']; } else { reset($this->entries); return false; } } } class MonthPayload_Decorator extends Calendar_Decorator { //Calendar engine var $cE; var $tableHelper; var $year; var $month; var $firstDay = false; function build($events=array()) { require_once CALENDAR_ROOT . 'Day.php'; require_once CALENDAR_ROOT . 'Table/Helper.php'; $this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay); $this->cE = & $this->getEngine(); $this->year = $this->thisYear(); $this->month = $this->thisMonth(); $daysInMonth = $this->cE->getDaysInMonth($this->year, $this->month); for ($i=1; $i<=$daysInMonth; $i++) { $Day = new Calendar_Day(2000,1,1); // Create Day with dummy values $Day->setTimeStamp($this->cE->dateToStamp($this->year, $this->month, $i)); $this->children[$i] = new DiaryEvent($Day); } if (count($events) > 0) { $this->setSelection($events); } Calendar_Month_Weekdays::buildEmptyDaysBefore(); Calendar_Month_Weekdays::shiftDays(); Calendar_Month_Weekdays::buildEmptyDaysAfter(); Calendar_Month_Weekdays::setWeekMarkers(); return true; } function setSelection($events) { $daysInMonth = $this->cE->getDaysInMonth($this->year, $this->month); for ($i=1; $i<=$daysInMonth; $i++) { $stamp1 = $this->cE->dateToStamp($this->year, $this->month, $i); $stamp2 = $this->cE->dateToStamp($this->year, $this->month, $i+1); foreach ($events as $event) { if (($stamp1 >= $event['start'] && $stamp1 < $event['end']) || ($stamp2 >= $event['start'] && $stamp2 < $event['end']) || ($stamp1 <= $event['start'] && $stamp2 > $event['end']) ) { $this->children[$i]->addEntry($event); $this->children[$i]->setSelected(); } } } } function fetch() { $child = each($this->children); if ($child) { return $child['value']; } else { reset($this->children); return false; } } } // Calendar instance used to get the dates in the preferred format: // you can switch Calendar Engine and the example still works $cal = new Calendar; $events = array(); //add some events $events[] = array( 'start' => $cal->cE->dateToStamp(2004, 6, 1, 10), 'end' => $cal->cE->dateToStamp(2004, 6, 1, 12), 'desc' => 'Important meeting' ); $events[] = array( 'start' => $cal->cE->dateToStamp(2004, 6, 1, 21), 'end' => $cal->cE->dateToStamp(2004, 6, 1, 23, 59), 'desc' => 'Dinner with the boss' ); $events[] = array( 'start' => $cal->cE->dateToStamp(2004, 6, 5), 'end' => $cal->cE->dateToStamp(2004, 6, 10, 23, 59), 'desc' => 'Holidays!' ); $Month = & new Calendar_Month_Weekdays(2004, 6); $MonthDecorator = new MonthPayload_Decorator($Month); $MonthDecorator->build($events); ?> Calendar

Sample Calendar Payload Decorator (using engine)

fetch()) { if ($Day->isFirst()) { echo "\n"; } echo ''; if ($Day->isLast()) { echo "\n"; } } ?>
thisMonth().' / '.$MonthDecorator->thisYear(); ?>
Monday Tuesday Wednesday Thursday Friday Saturday Sunday
'; echo '
'.$Day->thisDay().'
'; if ($Day->isEmpty()) { echo ' '; } else { echo '
    '; while ($entry = $Day->getEntry()) { echo '
  • '.$entry['desc'].'
  • '; //you can print the time range as well } echo '
'; } echo '
php-calendar-0.5.5/Calendar-0.5.5/docs/examples/20.phps000066400000000000000000000143171212436242500221250ustar00rootroot00000000000000entries[] = $entry; } function getEntry() { $entry = each($this->entries); if ($entry) { return $entry['value']; } else { reset($this->entries); return false; } } } class MonthPayload_Decorator extends Calendar_Decorator { //Calendar engine var $cE; var $tableHelper; var $year; var $month; var $firstDay = false; function build($events=array()) { require_once CALENDAR_ROOT . 'Day.php'; require_once CALENDAR_ROOT . 'Table/Helper.php'; $this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay); $this->cE = & $this->getEngine(); $this->year = $this->thisYear(); $this->month = $this->thisMonth(); $daysInMonth = $this->cE->getDaysInMonth($this->year, $this->month); for ($i=1; $i<=$daysInMonth; $i++) { $Day = new Calendar_Day(2000,1,1); // Create Day with dummy values $Day->setTimeStamp($this->cE->dateToStamp($this->year, $this->month, $i)); $this->children[$i] = new DiaryEvent($Day); } if (count($events) > 0) { $this->setSelection($events); } Calendar_Month_Weekdays::buildEmptyDaysBefore(); Calendar_Month_Weekdays::shiftDays(); Calendar_Month_Weekdays::buildEmptyDaysAfter(); Calendar_Month_Weekdays::setWeekMarkers(); return true; } function setSelection($events) { $daysInMonth = $this->cE->getDaysInMonth($this->year, $this->month); for ($i=1; $i<=$daysInMonth; $i++) { $stamp1 = $this->cE->dateToStamp($this->year, $this->month, $i); $stamp2 = $this->cE->dateToStamp($this->year, $this->month, $i+1); foreach ($events as $event) { if (($stamp1 >= $event['start'] && $stamp1 < $event['end']) || ($stamp2 >= $event['start'] && $stamp2 < $event['end']) || ($stamp1 <= $event['start'] && $stamp2 > $event['end']) ) { $this->children[$i]->addEntry($event); $this->children[$i]->setSelected(); } } } } function fetch() { $child = each($this->children); if ($child) { return $child['value']; } else { reset($this->children); return false; } } } // Calendar instance used to get the dates in the preferred format: // you can switch Calendar Engine and the example still works $cal = new Calendar; $events = array(); //add some events $events[] = array( 'start' => $cal->cE->dateToStamp(2004, 6, 1, 10), 'end' => $cal->cE->dateToStamp(2004, 6, 1, 12), 'desc' => 'Important meeting' ); $events[] = array( 'start' => $cal->cE->dateToStamp(2004, 6, 1, 21), 'end' => $cal->cE->dateToStamp(2004, 6, 1, 23, 59), 'desc' => 'Dinner with the boss' ); $events[] = array( 'start' => $cal->cE->dateToStamp(2004, 6, 5), 'end' => $cal->cE->dateToStamp(2004, 6, 10, 23, 59), 'desc' => 'Holidays!' ); $Month = & new Calendar_Month_Weekdays(2004, 6); $MonthDecorator = new MonthPayload_Decorator($Month); $MonthDecorator->build($events); ?> Calendar

Sample Calendar Payload Decorator (using engine)

fetch()) { if ($Day->isFirst()) { echo "\n"; } echo ''; if ($Day->isLast()) { echo "\n"; } } ?>
thisMonth().' / '.$MonthDecorator->thisYear(); ?>
Monday Tuesday Wednesday Thursday Friday Saturday Sunday
'; echo '
'.$Day->thisDay().'
'; if ($Day->isEmpty()) { echo ' '; } else { echo '
    '; while ($entry = $Day->getEntry()) { echo '
  • '.$entry['desc'].'
  • '; //you can print the time range as well } echo '
'; } echo '
php-calendar-0.5.5/Calendar-0.5.5/docs/examples/21.php000066400000000000000000000062711212436242500217430ustar00rootroot00000000000000build(); ?> <?php echo $Year->thisYear(); ?> fetch()) { switch ($i) { case 0: echo "\n"; break; case 3: case 6: case 9: echo "\n\n"; break; case 12: echo "\n"; break; } echo "\n"; $i++; } ?>
thisYear(); ?>
\n\n"; echo ''; echo ''."\n"; echo "\n\n"; $Month->build(); while ($Week = $Month->fetch()) { echo "\n"; echo '\n"; $Week->build(); while ($Day = $Week->fetch()) { if ($Day->isEmpty()) { echo "\n"; } else { echo "\n"; } } } echo "
'.date('F', $Month->thisMonth(TRUE)).'
WeekMTWTFSS
'.$Week->thisWeek($_GET['week_type'])." ".$Day->thisDay()."
\n

Took:

php-calendar-0.5.5/Calendar-0.5.5/docs/examples/21.phps000066400000000000000000000062711212436242500221260ustar00rootroot00000000000000build(); ?> <?php echo $Year->thisYear(); ?> fetch()) { switch ($i) { case 0: echo "\n"; break; case 3: case 6: case 9: echo "\n\n"; break; case 12: echo "\n"; break; } echo "\n"; $i++; } ?>
thisYear(); ?>
\n\n"; echo ''; echo ''."\n"; echo "\n\n"; $Month->build(); while ($Week = $Month->fetch()) { echo "\n"; echo '\n"; $Week->build(); while ($Day = $Week->fetch()) { if ($Day->isEmpty()) { echo "\n"; } else { echo "\n"; } } } echo "
'.date('F', $Month->thisMonth(TRUE)).'
WeekMTWTFSS
'.$Week->thisWeek($_GET['week_type'])." ".$Day->thisDay()."
\n

Took:

php-calendar-0.5.5/Calendar-0.5.5/docs/examples/22.php000066400000000000000000000030321212436242500217340ustar00rootroot00000000000000The current month is ' .$Calendar->thisMonth().' of year '.$Calendar->thisYear().'

'); $Uri = & new Calendar_Util_Uri('jahr','monat'); $Uri->setFragments('jahr','monat'); echo "\"Vector\" URIs
";
echo ( "Previous Uri:\t".htmlentities($Uri->prev($Calendar, 'month'))."\n" );
echo ( "This Uri:\t".htmlentities($Uri->this($Calendar,  'month'))."\n" );
echo ( "Next Uri:\t".htmlentities($Uri->next($Calendar, 'month'))."\n" );
echo "
"; // Switch to scalar URIs $Uri->separator = '/'; // Default is & $Uri->scalar = true; // Omit variable names echo "\"Scalar\" URIs
";
echo ( "Previous Uri:\t".$Uri->prev($Calendar, 'month')."\n" );
echo ( "This Uri:\t".$Uri->this($Calendar,  'month')."\n" );
echo ( "Next Uri:\t".$Uri->next($Calendar, 'month')."\n" );
echo "
"; // Restore the vector URIs $Uri->separator = '&'; $Uri->scalar = false; ?>

Prev : Next

php-calendar-0.5.5/Calendar-0.5.5/docs/examples/22.phps000066400000000000000000000030321212436242500221170ustar00rootroot00000000000000The current month is ' .$Calendar->thisMonth().' of year '.$Calendar->thisYear().'

'); $Uri = & new Calendar_Util_Uri('jahr','monat'); $Uri->setFragments('jahr','monat'); echo "\"Vector\" URIs
";
echo ( "Previous Uri:\t".htmlentities($Uri->prev($Calendar, 'month'))."\n" );
echo ( "This Uri:\t".htmlentities($Uri->this($Calendar,  'month'))."\n" );
echo ( "Next Uri:\t".htmlentities($Uri->next($Calendar, 'month'))."\n" );
echo "
"; // Switch to scalar URIs $Uri->separator = '/'; // Default is & $Uri->scalar = true; // Omit variable names echo "\"Scalar\" URIs
";
echo ( "Previous Uri:\t".$Uri->prev($Calendar, 'month')."\n" );
echo ( "This Uri:\t".$Uri->this($Calendar,  'month')."\n" );
echo ( "Next Uri:\t".$Uri->next($Calendar, 'month')."\n" );
echo "
"; // Restore the vector URIs $Uri->separator = '&'; $Uri->scalar = false; ?>

Prev : Next

php-calendar-0.5.5/Calendar-0.5.5/docs/examples/23.php000066400000000000000000000043731212436242500217460ustar00rootroot00000000000000Calling: Calendar_Util_Textual::monthNames('long');
";
print_r(Calendar_Util_Textual::monthNames('long'));
echo '
'; echo "
Calling: Calendar_Util_Textual::weekdayNames('two');
";
print_r(Calendar_Util_Textual::weekdayNames('two'));
echo '
'; echo "
Creating: new Calendar_Day(date('Y'), date('n'), date('d'));
"; $Calendar = new Calendar_Day(date('Y'), date('n'), date('d')); echo '
Previous month is: '.Calendar_Util_Textual::prevMonthName($Calendar,'two').'
'; echo 'This month is: '.Calendar_Util_Textual::thisMonthName($Calendar,'short').'
'; echo 'Next month is: '.Calendar_Util_Textual::nextMonthName($Calendar).'

'; echo 'Previous day is: '.Calendar_Util_Textual::prevDayName($Calendar).'
'; echo 'This day is: '.Calendar_Util_Textual::thisDayName($Calendar,'short').'
'; echo 'Next day is: '.Calendar_Util_Textual::nextDayName($Calendar,'one').'

'; echo "Creating: new Calendar_Month_Weekdays(date('Y'), date('n'), 6); - Saturday is first day of week
"; $Calendar = new Calendar_Month_Weekdays(date('Y'), date('n'), 6); ?>

Rendering calendar....

'.$dayheader.''; } ?> build(); while ($Day = $Calendar->fetch()) { if ($Day->isFirst()) { echo "\n"; } if ($Day->isEmpty()) { echo ''; } else { echo ''; } if ($Day->isLast()) { echo "\n"; } } ?>
thisYear(); ?>
 '.$Day->thisDay().'
php-calendar-0.5.5/Calendar-0.5.5/docs/examples/23.phps000066400000000000000000000043731212436242500221310ustar00rootroot00000000000000Calling: Calendar_Util_Textual::monthNames('long');
";
print_r(Calendar_Util_Textual::monthNames('long'));
echo '
'; echo "
Calling: Calendar_Util_Textual::weekdayNames('two');
";
print_r(Calendar_Util_Textual::weekdayNames('two'));
echo '
'; echo "
Creating: new Calendar_Day(date('Y'), date('n'), date('d'));
"; $Calendar = new Calendar_Day(date('Y'), date('n'), date('d')); echo '
Previous month is: '.Calendar_Util_Textual::prevMonthName($Calendar,'two').'
'; echo 'This month is: '.Calendar_Util_Textual::thisMonthName($Calendar,'short').'
'; echo 'Next month is: '.Calendar_Util_Textual::nextMonthName($Calendar).'

'; echo 'Previous day is: '.Calendar_Util_Textual::prevDayName($Calendar).'
'; echo 'This day is: '.Calendar_Util_Textual::thisDayName($Calendar,'short').'
'; echo 'Next day is: '.Calendar_Util_Textual::nextDayName($Calendar,'one').'

'; echo "Creating: new Calendar_Month_Weekdays(date('Y'), date('n'), 6); - Saturday is first day of week
"; $Calendar = new Calendar_Month_Weekdays(date('Y'), date('n'), 6); ?>

Rendering calendar....

'.$dayheader.''; } ?> build(); while ($Day = $Calendar->fetch()) { if ($Day->isFirst()) { echo "\n"; } if ($Day->isEmpty()) { echo ''; } else { echo ''; } if ($Day->isLast()) { echo "\n"; } } ?>
thisYear(); ?>
 '.$Day->thisDay().'
php-calendar-0.5.5/Calendar-0.5.5/docs/examples/3.php000066400000000000000000000061571212436242500216660ustar00rootroot00000000000000prevMonth('object'); // Get previous month as object $prev = $_SERVER['PHP_SELF'].'?y='.$PMonth->thisYear().'&m='.$PMonth->thisMonth().'&d='.$PMonth->thisDay(); $NMonth = $Month->nextMonth('object'); $next = $_SERVER['PHP_SELF'].'?y='.$NMonth->thisYear().'&m='.$NMonth->thisMonth().'&d='.$NMonth->thisDay(); ?> Calendar build($selectedDays); ?>

Built with Calendar_Month_Weekday::build()

fetch() ) { // Build a link string for each day $link = $_SERVER['PHP_SELF']. '?y='.$Day->thisYear(). '&m='.$Day->thisMonth(). '&d='.$Day->thisDay(); // isFirst() to find start of week if ( $Day->isFirst() ) echo ( "\n" ); if ( $Day->isSelected() ) { echo ( "\n" ); } else if ( $Day->isEmpty() ) { echo ( "\n" ); } else { echo ( "\n" ); } // isLast() to find end of week if ( $Day->isLast() ) echo ( "\n" ); } ?>
getTimeStamp())); ?>
M T W T F S S
".$Day->thisDay()." ".$Day->thisDay()."
<<   >>
Took: '.(getmicrotime()-$start).' seconds

' ); ?> php-calendar-0.5.5/Calendar-0.5.5/docs/examples/3.phps000066400000000000000000000061571212436242500220510ustar00rootroot00000000000000prevMonth('object'); // Get previous month as object $prev = $_SERVER['PHP_SELF'].'?y='.$PMonth->thisYear().'&m='.$PMonth->thisMonth().'&d='.$PMonth->thisDay(); $NMonth = $Month->nextMonth('object'); $next = $_SERVER['PHP_SELF'].'?y='.$NMonth->thisYear().'&m='.$NMonth->thisMonth().'&d='.$NMonth->thisDay(); ?> Calendar build($selectedDays); ?>

Built with Calendar_Month_Weekday::build()

fetch() ) { // Build a link string for each day $link = $_SERVER['PHP_SELF']. '?y='.$Day->thisYear(). '&m='.$Day->thisMonth(). '&d='.$Day->thisDay(); // isFirst() to find start of week if ( $Day->isFirst() ) echo ( "\n" ); if ( $Day->isSelected() ) { echo ( "\n" ); } else if ( $Day->isEmpty() ) { echo ( "\n" ); } else { echo ( "\n" ); } // isLast() to find end of week if ( $Day->isLast() ) echo ( "\n" ); } ?>
getTimeStamp())); ?>
M T W T F S S
".$Day->thisDay()." ".$Day->thisDay()."
<<   >>
Took: '.(getmicrotime()-$start).' seconds

' ); ?> php-calendar-0.5.5/Calendar-0.5.5/docs/examples/4.php000066400000000000000000000035721212436242500216650ustar00rootroot00000000000000Result: '.$Unit->thisYear().'-'.$Unit->thisMonth().'-'.$Unit->thisDay(). ' '.$Unit->thisHour().':'.$Unit->thisMinute().':'.$Unit->thisSecond(); if ($Unit->isValid()) { echo ' is valid!

'; } else { $V= & $Unit->getValidator(); echo ' is invalid:

'; while ($error = $V->fetch()) { echo $error->toString() .'
'; } } ?>

Enter a date / time to validate:

Year:
Month:
Day:
Hour:
Minute:
Second:

Note: Error messages can be controlled with the constants CALENDAR_VALUE_TOOSMALL and CALENDAR_VALUE_TOOLARGE - see Calendar_Validator.php

Took: '.(getmicrotime()-$start).' seconds

'; ?>php-calendar-0.5.5/Calendar-0.5.5/docs/examples/4.phps000066400000000000000000000035721212436242500220500ustar00rootroot00000000000000Result: '.$Unit->thisYear().'-'.$Unit->thisMonth().'-'.$Unit->thisDay(). ' '.$Unit->thisHour().':'.$Unit->thisMinute().':'.$Unit->thisSecond(); if ($Unit->isValid()) { echo ' is valid!

'; } else { $V= & $Unit->getValidator(); echo ' is invalid:

'; while ($error = $V->fetch()) { echo $error->toString() .'
'; } } ?>

Enter a date / time to validate:

Year:
Month:
Day:
Hour:
Minute:
Second:

Note: Error messages can be controlled with the constants CALENDAR_VALUE_TOOSMALL and CALENDAR_VALUE_TOOLARGE - see Calendar_Validator.php

Took: '.(getmicrotime()-$start).' seconds

'; ?>php-calendar-0.5.5/Calendar-0.5.5/docs/examples/5.php000066400000000000000000000105601212436242500216610ustar00rootroot00000000000000 Select and Update

Select and Update

isValid() ) { $V= & $Second->getValidator(); echo ('

Validation failed:

' ); while ( $error = $V->fetch() ) { echo ( $error->toString() .'
' ); } } else { echo ('

Validation success.

' ); echo ( '

New timestamp is: '.$Second->getTimeStamp().' which could be used to update a database, for example'); } } else { $Year = new Calendar_Year($_POST['y']); $Month = new Calendar_Month($_POST['y'],$_POST['m']); $Day = new Calendar_Day($_POST['y'],$_POST['m'],$_POST['d']); $Hour = new Calendar_Hour($_POST['y'],$_POST['m'],$_POST['d'],$_POST['h']); $Minute = new Calendar_Minute($_POST['y'],$_POST['m'],$_POST['d'],$_POST['h'],$_POST['i']); $Second = new Calendar_Second($_POST['y'],$_POST['m'],$_POST['d'],$_POST['h'],$_POST['i'],$_POST['s']); ?>

Set the alarm clock

Year:   Month:  Day:  Hour:  Minute:  Second: 
Took: '.(getmicrotime()-$start).' seconds

' ); ?> php-calendar-0.5.5/Calendar-0.5.5/docs/examples/5.phps000066400000000000000000000105601212436242500220440ustar00rootroot00000000000000 Select and Update

Select and Update

isValid() ) { $V= & $Second->getValidator(); echo ('

Validation failed:

' ); while ( $error = $V->fetch() ) { echo ( $error->toString() .'
' ); } } else { echo ('

Validation success.

' ); echo ( '

New timestamp is: '.$Second->getTimeStamp().' which could be used to update a database, for example'); } } else { $Year = new Calendar_Year($_POST['y']); $Month = new Calendar_Month($_POST['y'],$_POST['m']); $Day = new Calendar_Day($_POST['y'],$_POST['m'],$_POST['d']); $Hour = new Calendar_Hour($_POST['y'],$_POST['m'],$_POST['d'],$_POST['h']); $Minute = new Calendar_Minute($_POST['y'],$_POST['m'],$_POST['d'],$_POST['h'],$_POST['i']); $Second = new Calendar_Second($_POST['y'],$_POST['m'],$_POST['d'],$_POST['h'],$_POST['i'],$_POST['s']); ?>

Set the alarm clock

Year:   Month:  Day:  Hour:  Minute:  Second: 
Took: '.(getmicrotime()-$start).' seconds

' ); ?> php-calendar-0.5.5/Calendar-0.5.5/docs/examples/6.php000066400000000000000000000137471212436242500216740ustar00rootroot00000000000000' ); ?> Personal Planner Rendered with WML

Viewing getTimeStamp()) ); ?>

Back to Month View "/>

build(); while ( $Hour = & $Day->fetch() ) { echo ( "\n" ); echo ( "\n" ); echo ( "\n" ); } ?>
".date('g a',$Hour->getTimeStamp())."Free time!

getTimeStamp()) ); ?>

build($selection); while ( $Day = $Month->fetch() ) { if ( $Day->isFirst() ) { echo ( "\n" ); } if ( $Day->isEmpty() ) { echo ( "\n" ); } else if ( $Day->isSelected() ) { echo ( "\n" ); } else { echo ( "\n" ); } if ( $Day->isLast() ) { echo ( "\n" ); } } ?>
MTWTFSS
".$Day->thisDay()."\nthisYear()."&m=".$Day->thisMonth()."&d=".$Day->thisDay(). "&mime=wml\" />\n".$Day->thisDay()."\nthisYear()."&m=".$Day->thisMonth()."&d=".$Day->thisDay(). "&mime=wml\" />
<< "/> >> "/>

Back to HTML

Took: '.(getmicrotime()-$start).' seconds

' ); ?>
HTML (+WML) Personal Planner

Personal Planner Rendered with HTML

To view in WML, click here or place a ?mime=wml at the end of any URL. Note that Opera supports WML natively and Mozilla / Firefox has the WMLBrowser plugin: wmlbrowser.mozdev.org

Viewing getTimeStamp()) ); ?>

Back to Month View

build(); while ( $Hour = & $Day->fetch() ) { echo ( "\n" ); echo ( "\n" ); echo ( "\n" ); } ?>
".date('g a',$Hour->getTimeStamp())."Free time!

getTimeStamp()) ); ?>

build($selection); while ( $Day = $Month->fetch() ) { if ( $Day->isFirst() ) { echo ( "\n" ); } if ( $Day->isEmpty() ) { echo ( "\n" ); } else if ( $Day->isSelected() ) { echo ( "\n" ); } else { echo ( "\n" ); } if ( $Day->isLast() ) { echo ( "\n" ); } } ?>
MTWTFSS
thisYear()."&m=".$Day->thisMonth()."&d=".$Day->thisDay(). "&wml\">".$Day->thisDay()."thisYear()."&m=".$Day->thisMonth()."&d=".$Day->thisDay(). "\">".$Day->thisDay()."
<< >>
Took: '.(getmicrotime()-$start).' seconds

' ); ?> php-calendar-0.5.5/Calendar-0.5.5/docs/examples/6.phps000066400000000000000000000137471212436242500220570ustar00rootroot00000000000000' ); ?> Personal Planner Rendered with WML

Viewing getTimeStamp()) ); ?>

Back to Month View "/>

build(); while ( $Hour = & $Day->fetch() ) { echo ( "\n" ); echo ( "\n" ); echo ( "\n" ); } ?>
".date('g a',$Hour->getTimeStamp())."Free time!

getTimeStamp()) ); ?>

build($selection); while ( $Day = $Month->fetch() ) { if ( $Day->isFirst() ) { echo ( "\n" ); } if ( $Day->isEmpty() ) { echo ( "\n" ); } else if ( $Day->isSelected() ) { echo ( "\n" ); } else { echo ( "\n" ); } if ( $Day->isLast() ) { echo ( "\n" ); } } ?>
MTWTFSS
".$Day->thisDay()."\nthisYear()."&m=".$Day->thisMonth()."&d=".$Day->thisDay(). "&mime=wml\" />\n".$Day->thisDay()."\nthisYear()."&m=".$Day->thisMonth()."&d=".$Day->thisDay(). "&mime=wml\" />
<< "/> >> "/>

Back to HTML

Took: '.(getmicrotime()-$start).' seconds

' ); ?>
HTML (+WML) Personal Planner

Personal Planner Rendered with HTML

To view in WML, click here or place a ?mime=wml at the end of any URL. Note that Opera supports WML natively and Mozilla / Firefox has the WMLBrowser plugin: wmlbrowser.mozdev.org

Viewing getTimeStamp()) ); ?>

Back to Month View

build(); while ( $Hour = & $Day->fetch() ) { echo ( "\n" ); echo ( "\n" ); echo ( "\n" ); } ?>
".date('g a',$Hour->getTimeStamp())."Free time!

getTimeStamp()) ); ?>

build($selection); while ( $Day = $Month->fetch() ) { if ( $Day->isFirst() ) { echo ( "\n" ); } if ( $Day->isEmpty() ) { echo ( "\n" ); } else if ( $Day->isSelected() ) { echo ( "\n" ); } else { echo ( "\n" ); } if ( $Day->isLast() ) { echo ( "\n" ); } } ?>
MTWTFSS
thisYear()."&m=".$Day->thisMonth()."&d=".$Day->thisDay(). "&wml\">".$Day->thisDay()."thisYear()."&m=".$Day->thisMonth()."&d=".$Day->thisDay(). "\">".$Day->thisDay()."
<< >>
Took: '.(getmicrotime()-$start).' seconds

' ); ?> php-calendar-0.5.5/Calendar-0.5.5/docs/examples/7.php000066400000000000000000000060761212436242500216720ustar00rootroot00000000000000__dispatch_map['getMonth'] = array('in' => array('year' => 'int', 'month'=>'int'), 'out' => array('month' => '{urn:PEAR_SOAP_Calendar}Month'), ); $this->__typedef['Month'] = array ( 'monthname' => 'string', 'days' => '{urn:PEAR_SOAP_Calendar}MonthDays' ); $this->__typedef['MonthDays'] = array (array ('{urn:PEAR_SOAP_Calendar}Day')); $this->__typedef['Day'] = array ( 'isFirst' => 'int', 'isLast' => 'int', 'isEmpty' => 'int', 'day' => 'int' ); } function __dispatch($methodname) { if (isset($this->__dispatch_map[$methodname])) return $this->__dispatch_map[$methodname]; return NULL; } function getMonth($year, $month) { require_once(CALENDAR_ROOT.'Month'.DIRECTORY_SEPARATOR.'Weekdays.php'); $Month = & new Calendar_Month_Weekdays($year,$month); if (!$Month->isValid()) { $V = & $Month->getValidator(); $errorMsg = ''; while ($error = $V->fetch()) { $errorMsg .= $error->toString()."\n"; } return new SOAP_Fault($errorMsg, 'Client'); } else { $monthname = date('F Y', $Month->getTimeStamp()); $days = array(); $Month->build(); while ($Day = & $Month->fetch()) { $day = array( 'isFirst' => (int)$Day->isFirst(), 'isLast' => (int)$Day->isLast(), 'isEmpty' => (int)$Day->isEmpty(), 'day' => (int)$Day->thisDay(), ); $days[] = $day; } return array('monthname' => $monthname, 'days' => $days); } } } $server = new SOAP_Server(); $server->_auto_translation = true; $calendar = new Calendar_Server(); $server->addObjectMap($calendar, 'urn:PEAR_SOAP_Calendar'); if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') { $server->service($GLOBALS['HTTP_RAW_POST_DATA']); } else { require_once 'SOAP'.DIRECTORY_SEPARATOR.'Disco.php'; $disco = new SOAP_DISCO_Server($server, "PEAR_SOAP_Calendar"); if (isset($_SERVER['QUERY_STRING']) && strcasecmp($_SERVER['QUERY_STRING'], 'wsdl')==0) { header("Content-type: text/xml"); echo $disco->getWSDL(); } else { echo 'This is a PEAR::SOAP Calendar Server. For client try here
'; echo 'For WSDL try here'; } exit; } ?>php-calendar-0.5.5/Calendar-0.5.5/docs/examples/7.phps000066400000000000000000000060761212436242500220550ustar00rootroot00000000000000__dispatch_map['getMonth'] = array('in' => array('year' => 'int', 'month'=>'int'), 'out' => array('month' => '{urn:PEAR_SOAP_Calendar}Month'), ); $this->__typedef['Month'] = array ( 'monthname' => 'string', 'days' => '{urn:PEAR_SOAP_Calendar}MonthDays' ); $this->__typedef['MonthDays'] = array (array ('{urn:PEAR_SOAP_Calendar}Day')); $this->__typedef['Day'] = array ( 'isFirst' => 'int', 'isLast' => 'int', 'isEmpty' => 'int', 'day' => 'int' ); } function __dispatch($methodname) { if (isset($this->__dispatch_map[$methodname])) return $this->__dispatch_map[$methodname]; return NULL; } function getMonth($year, $month) { require_once(CALENDAR_ROOT.'Month'.DIRECTORY_SEPARATOR.'Weekdays.php'); $Month = & new Calendar_Month_Weekdays($year,$month); if (!$Month->isValid()) { $V = & $Month->getValidator(); $errorMsg = ''; while ($error = $V->fetch()) { $errorMsg .= $error->toString()."\n"; } return new SOAP_Fault($errorMsg, 'Client'); } else { $monthname = date('F Y', $Month->getTimeStamp()); $days = array(); $Month->build(); while ($Day = & $Month->fetch()) { $day = array( 'isFirst' => (int)$Day->isFirst(), 'isLast' => (int)$Day->isLast(), 'isEmpty' => (int)$Day->isEmpty(), 'day' => (int)$Day->thisDay(), ); $days[] = $day; } return array('monthname' => $monthname, 'days' => $days); } } } $server = new SOAP_Server(); $server->_auto_translation = true; $calendar = new Calendar_Server(); $server->addObjectMap($calendar, 'urn:PEAR_SOAP_Calendar'); if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') { $server->service($GLOBALS['HTTP_RAW_POST_DATA']); } else { require_once 'SOAP'.DIRECTORY_SEPARATOR.'Disco.php'; $disco = new SOAP_DISCO_Server($server, "PEAR_SOAP_Calendar"); if (isset($_SERVER['QUERY_STRING']) && strcasecmp($_SERVER['QUERY_STRING'], 'wsdl')==0) { header("Content-type: text/xml"); echo $disco->getWSDL(); } else { echo 'This is a PEAR::SOAP Calendar Server. For client try here
'; echo 'For WSDL try here'; } exit; } ?>php-calendar-0.5.5/Calendar-0.5.5/docs/examples/8.php000066400000000000000000000036741212436242500216740ustar00rootroot00000000000000") ) { die('PHP 5 has problems with PEAR::SOAP Client (8.0RC3) - remove @ before include below to see why'); } if (!@include('SOAP'.DIRECTORY_SEPARATOR.'Client.php')) { die('You must have PEAR::SOAP installed'); } // Just to save manaul modification... $basePath = explode('/', $_SERVER['SCRIPT_NAME']); array_pop($basePath); $basePath = implode('/', $basePath); $url = 'http://'.$_SERVER['SERVER_NAME'].$basePath.'/7.php?wsdl'; if (!isset($_GET['y'])) $_GET['y'] = date('Y'); if (!isset($_GET['m'])) $_GET['m'] = date('n'); $wsdl = new SOAP_WSDL ($url); echo ( '
'.$wsdl->generateProxyCode().'
' ); $calendarClient = $wsdl->getProxy(); $month = $calendarClient->getMonth((int)$_GET['y'],(int)$_GET['m']); if ( PEAR::isError($month) ) { die ( $month->toString() ); } ?> Calendar over the Wire

Calendar Over the Wire (featuring PEAR::SOAP)

days as $day ) { if ( $day->isFirst === 1 ) echo ( "\n" ); if ( $day->isEmpty === 1 ) { echo ( "" ); } else { echo ( "" ); } if ( $day->isLast === 1 ) echo ( "\n" ); } ?>
monthname );?>
MTWTFSS
".$day->day."

Enter Year and Month to View:

Year:   Month:   php-calendar-0.5.5/Calendar-0.5.5/docs/examples/8.phps000066400000000000000000000036741212436242500220570ustar00rootroot00000000000000") ) { die('PHP 5 has problems with PEAR::SOAP Client (8.0RC3) - remove @ before include below to see why'); } if (!@include('SOAP'.DIRECTORY_SEPARATOR.'Client.php')) { die('You must have PEAR::SOAP installed'); } // Just to save manaul modification... $basePath = explode('/', $_SERVER['SCRIPT_NAME']); array_pop($basePath); $basePath = implode('/', $basePath); $url = 'http://'.$_SERVER['SERVER_NAME'].$basePath.'/7.php?wsdl'; if (!isset($_GET['y'])) $_GET['y'] = date('Y'); if (!isset($_GET['m'])) $_GET['m'] = date('n'); $wsdl = new SOAP_WSDL ($url); echo ( '
'.$wsdl->generateProxyCode().'
' ); $calendarClient = $wsdl->getProxy(); $month = $calendarClient->getMonth((int)$_GET['y'],(int)$_GET['m']); if ( PEAR::isError($month) ) { die ( $month->toString() ); } ?> Calendar over the Wire

Calendar Over the Wire (featuring PEAR::SOAP)

days as $day ) { if ( $day->isFirst === 1 ) echo ( "\n" ); if ( $day->isEmpty === 1 ) { echo ( "" ); } else { echo ( "" ); } if ( $day->isLast === 1 ) echo ( "\n" ); } ?>
monthname );?>
MTWTFSS
".$day->day."

Enter Year and Month to View:

Year:   Month:  
php-calendar-0.5.5/Calendar-0.5.5/docs/examples/9.php000066400000000000000000000005751212436242500216720ustar00rootroot00000000000000getTimeStamp())); ?>php-calendar-0.5.5/Calendar-0.5.5/docs/examples/9.phps000066400000000000000000000005751212436242500220550ustar00rootroot00000000000000getTimeStamp())); ?>php-calendar-0.5.5/Calendar-0.5.5/docs/examples/index.html000066400000000000000000000104671212436242500230070ustar00rootroot00000000000000 PEAR::Calendar Examples

PEAR::Calendar Examples

$Id: index.html 166574 2004-08-17 09:10:53Z hfuecks $

  • 1.php [src] - shows basic usage, passing all the way down from Calendar_Year to Calendar_Second - more of a quick test it's working
  • 2.php [src] - shows how to build a tabular month using Calendar_Month_Weeks, Calendar_Week, Calendar_Day as well as selecting some dates.
  • 3.php [src] - shows how to build a tabular month using Calendar_Month_Weekdays and Calendar_Day, as well as selecting some dates (this method is faster).
  • 4.php [src] - shows how to use PEAR::Calendar for validation.
  • 5.php [src] - shows PEAR::Calendar in use to help generate a form.
  • 6.php [src] - a month and day "planner" calendar, which can be rendered both as HTML and WML.
  • 7.php [src] - a simple SOAP Calendar Server, using PEAR::SOAP and PEAR::Calendar
  • 8.php [src] - a WSDL SOAP client for the SOAP Calendar Server
  • 9.php [src] - quick example of i18n with setlocale (not working on SF)
  • 10.php [src] - an example of extending Calendar_Decorator to modify output
  • 11.php [src] - attaching a "payload" (e.g. results of a DB query) to a calendar using Calendar_Decorator to allow the payload to be available inside the main loop.
  • 12.php [src] - a complete year with months.
  • 13.php [src] - same as 1.php but using Calendar_Engine_PearDate, (see PEAR::Date).
  • 14.php [src] - same as 3.php but using Calendar_Engine_PearDate
  • 15.php [src] - paging through weeks
  • 16.php [src] - example of Calendar_Decorator_Uri. Note you should prefer Calendar_Util_Uri (see below) in most cases, for performance
  • 17.php [src] - example of Calendar_Decorator_Textual. Note you should prefer Calendar_Util_Textual (see below) in most cases, for performance
  • 18.php [src] - example of Calendar_Decorator_Wrapper.
  • 19.php [src] - example of Calendar_Decorator_Weekday.
  • 20.php [src] - shows how to attach a "payload" spanning multiple days, with more than one entry per day
  • 21.php [src] - same as 12.php but using Calendar_Month_Weeks instead of Calendar_Month_Weekdays to allow the week in the year or week in the month to be displayed.
  • 22.php [src] - demonstrates use of Calendar_Util_Uri.
  • 23.php [src] - demonstrates use of Calendar_Util_Textual.
  • 24.php [src] - Calendar_Decorator_Weekday combined with Calendar_Decorator_Wrapper to decorate days in the month.
php-calendar-0.5.5/Calendar-0.5.5/tests/000077500000000000000000000000001212436242500173765ustar00rootroot00000000000000php-calendar-0.5.5/Calendar-0.5.5/tests/README000066400000000000000000000004641212436242500202620ustar00rootroot00000000000000These tests require Simple Test: http://www.lastcraft.com/simple_test.php Ideally they would use PEAR::PHPUnit but the current version has bugs and lacks alot of the functionality (e.g. Mock Objects) which Simple Test provides. Modifying the simple_include.php script for your simple test install dirphp-calendar-0.5.5/Calendar-0.5.5/tests/all_tests.php000066400000000000000000000020641212436242500221030ustar00rootroot00000000000000GroupTest('All PEAR::Calendar Tests'); $this->AddTestCase(new CalendarTests()); $this->AddTestCase(new CalendarTabularTests()); $this->AddTestCase(new ValidatorTests()); $this->AddTestCase(new CalendarEngineTests()); $this->AddTestCase(new TableHelperTests()); $this->AddTestCase(new DecoratorTests()); $this->AddTestCase(new UtilTests()); } } $test = &new AllTests(); $test->run(new HtmlReporter()); ?>php-calendar-0.5.5/Calendar-0.5.5/tests/calendar_engine_tests.php000066400000000000000000000010721212436242500244270ustar00rootroot00000000000000GroupTest('Calendar Engine Tests'); $this->addTestFile('peardate_engine_test.php'); $this->addTestFile('unixts_engine_test.php'); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new CalendarEngineTests(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/calendar_include.php000066400000000000000000000023271212436242500233670ustar00rootroot00000000000000php-calendar-0.5.5/Calendar-0.5.5/tests/calendar_tabular_tests.php000066400000000000000000000012751212436242500246210ustar00rootroot00000000000000GroupTest('Calendar Tabular Tests'); $this->addTestFile('month_weekdays_test.php'); $this->addTestFile('month_weeks_test.php'); $this->addTestFile('week_test.php'); //$this->addTestFile('week_firstday_0_test.php'); //switch with the above } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new CalendarTabularTests(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/calendar_test.php000066400000000000000000000074101212436242500227210ustar00rootroot00000000000000UnitTestCase($name); } function setUp() { $this->cal = new Calendar(2003,10,25,13,32,43); } function tearDown() { unset($this->cal); } function testPrevYear () { $this->assertEqual(2002,$this->cal->prevYear()); } function testPrevYear_Array () { $this->assertEqual( array( 'year' => 2002, 'month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0, 'second' => 0), $this->cal->prevYear('array')); } function testThisYear () { $this->assertEqual(2003,$this->cal->thisYear()); } function testNextYear () { $this->assertEqual(2004,$this->cal->nextYear()); } function testPrevMonth () { $this->assertEqual(9,$this->cal->prevMonth()); } function testPrevMonth_Array () { $this->assertEqual( array( 'year' => 2003, 'month' => 9, 'day' => 1, 'hour' => 0, 'minute' => 0, 'second' => 0), $this->cal->prevMonth('array')); } function testThisMonth () { $this->assertEqual(10,$this->cal->thisMonth()); } function testNextMonth () { $this->assertEqual(11,$this->cal->nextMonth()); } function testPrevDay () { $this->assertEqual(24,$this->cal->prevDay()); } function testPrevDay_Array () { $this->assertEqual( array( 'year' => 2003, 'month' => 10, 'day' => 24, 'hour' => 0, 'minute' => 0, 'second' => 0), $this->cal->prevDay('array')); } function testThisDay () { $this->assertEqual(25,$this->cal->thisDay()); } function testNextDay () { $this->assertEqual(26,$this->cal->nextDay()); } function testPrevHour () { $this->assertEqual(12,$this->cal->prevHour()); } function testThisHour () { $this->assertEqual(13,$this->cal->thisHour()); } function testNextHour () { $this->assertEqual(14,$this->cal->nextHour()); } function testPrevMinute () { $this->assertEqual(31,$this->cal->prevMinute()); } function testThisMinute () { $this->assertEqual(32,$this->cal->thisMinute()); } function testNextMinute () { $this->assertEqual(33,$this->cal->nextMinute()); } function testPrevSecond () { $this->assertEqual(42,$this->cal->prevSecond()); } function testThisSecond () { $this->assertEqual(43,$this->cal->thisSecond()); } function testNextSecond () { $this->assertEqual(44,$this->cal->nextSecond()); } function testSetTimeStamp() { $stamp = mktime(13,32,43,10,25,2003); $this->cal->setTimeStamp($stamp); $this->assertEqual($stamp,$this->cal->getTimeStamp()); } function testGetTimeStamp() { $stamp = mktime(13,32,43,10,25,2003); $this->assertEqual($stamp,$this->cal->getTimeStamp()); } function testIsToday() { $stamp = mktime(); $this->cal->setTimestamp($stamp); $this->assertTrue($this->cal->isToday()); $stamp += 1000000000; $this->cal->setTimestamp($stamp); $this->assertFalse($this->cal->isToday()); } } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/calendar_tests.php000066400000000000000000000013641212436242500231060ustar00rootroot00000000000000GroupTest('Calendar Tests'); $this->addTestFile('calendar_test.php'); $this->addTestFile('year_test.php'); $this->addTestFile('month_test.php'); $this->addTestFile('day_test.php'); $this->addTestFile('hour_test.php'); $this->addTestFile('minute_test.php'); $this->addTestFile('second_test.php'); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new CalendarTests(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/day_test.php000066400000000000000000000060421212436242500217250ustar00rootroot00000000000000UnitTestCase('Test of Day'); } function setUp() { $this->cal = new Calendar_Day(2003,10,25); } function testPrevDay_Array () { $this->assertEqual( array( 'year' => 2003, 'month' => 10, 'day' => 24, 'hour' => 0, 'minute' => 0, 'second' => 0), $this->cal->prevDay('array')); } function testPrevHour () { $this->assertEqual(23,$this->cal->prevHour()); } function testThisHour () { $this->assertEqual(0,$this->cal->thisHour()); } function testNextHour () { $this->assertEqual(1,$this->cal->nextHour()); } function testPrevMinute () { $this->assertEqual(59,$this->cal->prevMinute()); } function testThisMinute () { $this->assertEqual(0,$this->cal->thisMinute()); } function testNextMinute () { $this->assertEqual(1,$this->cal->nextMinute()); } function testPrevSecond () { $this->assertEqual(59,$this->cal->prevSecond()); } function testThisSecond () { $this->assertEqual(0,$this->cal->thisSecond()); } function testNextSecond () { $this->assertEqual(1,$this->cal->nextSecond()); } function testGetTimeStamp() { $stamp = mktime(0,0,0,10,25,2003); $this->assertEqual($stamp,$this->cal->getTimeStamp()); } } class TestOfDayBuild extends TestOfDay { function TestOfDayBuild() { $this->UnitTestCase('Test of Day::build()'); } function testSize() { $this->cal->build(); $this->assertEqual(24,$this->cal->size()); } function testFetch() { $this->cal->build(); $i=0; while ( $Child = $this->cal->fetch() ) { $i++; } $this->assertEqual(24,$i); } function testFetchAll() { $this->cal->build(); $children = array(); $i = 0; while ( $Child = $this->cal->fetch() ) { $children[$i]=$Child; $i++; } $this->assertEqual($children,$this->cal->fetchAll()); } function testSelection() { require_once(CALENDAR_ROOT . 'Hour.php'); $selection = array(new Calendar_Hour(2003,10,25,13)); $this->cal->build($selection); $i = 0; while ( $Child = $this->cal->fetch() ) { if ( $i == 13 ) break; $i++; } $this->assertTrue($Child->isSelected()); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfDay(); $test->run(new HtmlReporter()); $test = &new TestOfDayBuild(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/decorator_test.php000066400000000000000000000261641212436242500231410ustar00rootroot00000000000000UnitTestCase('Test of Calendar_Decorator'); } function setUp() { $this->mockengine = new Mock_Calendar_Engine($this); $this->mockcal = new Mock_Calendar_Second($this); $this->mockcal->setReturnValue('prevYear',2002); $this->mockcal->setReturnValue('thisYear',2003); $this->mockcal->setReturnValue('nextYear',2004); $this->mockcal->setReturnValue('prevMonth',9); $this->mockcal->setReturnValue('thisMonth',10); $this->mockcal->setReturnValue('nextMonth',11); $this->mockcal->setReturnValue('prevDay',14); $this->mockcal->setReturnValue('thisDay',15); $this->mockcal->setReturnValue('nextDay',16); $this->mockcal->setReturnValue('prevHour',12); $this->mockcal->setReturnValue('thisHour',13); $this->mockcal->setReturnValue('nextHour',14); $this->mockcal->setReturnValue('prevMinute',29); $this->mockcal->setReturnValue('thisMinute',30); $this->mockcal->setReturnValue('nextMinute',31); $this->mockcal->setReturnValue('prevSecond',44); $this->mockcal->setReturnValue('thisSecond',45); $this->mockcal->setReturnValue('nextSecond',46); $this->mockcal->setReturnValue('getEngine',$this->mockengine); $this->mockcal->setReturnValue('getTimestamp',12345); } function tearDown() { unset ( $this->engine ); unset ( $this->mockcal ); } function testPrevYear() { $this->mockcal->expectOnce('prevYear',array('int')); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(2002,$Decorator->prevYear()); } function testThisYear() { $this->mockcal->expectOnce('thisYear',array('int')); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(2003,$Decorator->thisYear()); } function testNextYear() { $this->mockcal->expectOnce('nextYear',array('int')); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(2004,$Decorator->nextYear()); } function testPrevMonth() { $this->mockcal->expectOnce('prevMonth',array('int')); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(9,$Decorator->prevMonth()); } function testThisMonth() { $this->mockcal->expectOnce('thisMonth',array('int')); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(10,$Decorator->thisMonth()); } function testNextMonth() { $this->mockcal->expectOnce('nextMonth',array('int')); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(11,$Decorator->nextMonth()); } function testPrevWeek() { $mockweek = & new Mock_Calendar_Week($this); $mockweek->setReturnValue('prevWeek',1); $mockweek->expectOnce('prevWeek',array('n_in_month')); $Decorator =& new Calendar_Decorator($mockweek); $this->assertEqual(1,$Decorator->prevWeek()); } function testThisWeek() { $mockweek = & new Mock_Calendar_Week($this); $mockweek->setReturnValue('thisWeek',2); $mockweek->expectOnce('thisWeek',array('n_in_month')); $Decorator =& new Calendar_Decorator($mockweek); $this->assertEqual(2,$Decorator->thisWeek()); } function testNextWeek() { $mockweek = & new Mock_Calendar_Week($this); $mockweek->setReturnValue('nextWeek',3); $mockweek->expectOnce('nextWeek',array('n_in_month')); $Decorator =& new Calendar_Decorator($mockweek); $this->assertEqual(3,$Decorator->nextWeek()); } function testPrevDay() { $this->mockcal->expectOnce('prevDay',array('int')); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(14,$Decorator->prevDay()); } function testThisDay() { $this->mockcal->expectOnce('thisDay',array('int')); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(15,$Decorator->thisDay()); } function testNextDay() { $this->mockcal->expectOnce('nextDay',array('int')); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(16,$Decorator->nextDay()); } function testPrevHour() { $this->mockcal->expectOnce('prevHour',array('int')); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(12,$Decorator->prevHour()); } function testThisHour() { $this->mockcal->expectOnce('thisHour',array('int')); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(13,$Decorator->thisHour()); } function testNextHour() { $this->mockcal->expectOnce('nextHour',array('int')); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(14,$Decorator->nextHour()); } function testPrevMinute() { $this->mockcal->expectOnce('prevMinute',array('int')); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(29,$Decorator->prevMinute()); } function testThisMinute() { $this->mockcal->expectOnce('thisMinute',array('int')); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(30,$Decorator->thisMinute()); } function testNextMinute() { $this->mockcal->expectOnce('nextMinute',array('int')); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(31,$Decorator->nextMinute()); } function testPrevSecond() { $this->mockcal->expectOnce('prevSecond',array('int')); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(44,$Decorator->prevSecond()); } function testThisSecond() { $this->mockcal->expectOnce('thisSecond',array('int')); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(45,$Decorator->thisSecond()); } function testNextSecond() { $this->mockcal->expectOnce('nextSecond',array('int')); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(46,$Decorator->nextSecond()); } function testGetEngine() { $Decorator = new Calendar_Decorator($this->mockcal); $this->assertIsA($Decorator->getEngine(),'Mock_Calendar_Engine'); } function testSetTimestamp() { $this->mockcal->expectOnce('setTimestamp',array('12345')); $Decorator = new Calendar_Decorator($this->mockcal); $Decorator->setTimestamp('12345'); } function testGetTimestamp() { $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual(12345,$Decorator->getTimestamp()); } function testSetSelected() { $this->mockcal->expectOnce('setSelected',array(true)); $Decorator = new Calendar_Decorator($this->mockcal); $Decorator->setSelected(); } function testIsSelected() { $this->mockcal->setReturnValue('isSelected',true); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertTrue($Decorator->isSelected()); } function testAdjust() { $this->mockcal->expectOnce('adjust',array()); $Decorator = new Calendar_Decorator($this->mockcal); $Decorator->adjust(); } function testToArray() { $this->mockcal->expectOnce('toArray',array(12345)); $testArray = array('foo'=>'bar'); $this->mockcal->setReturnValue('toArray',$testArray); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual($testArray,$Decorator->toArray(12345)); } function testReturnValue() { $this->mockcal->expectOnce('returnValue',array('a','b','c','d')); $this->mockcal->setReturnValue('returnValue','foo'); $Decorator = new Calendar_Decorator($this->mockcal); $this->assertEqual('foo',$Decorator->returnValue('a','b','c','d')); } function testSetFirst() { $mockday = & new Mock_Calendar_Day($this); $mockday->expectOnce('setFirst',array(true)); $Decorator =& new Calendar_Decorator($mockday); $Decorator->setFirst(); } function testSetLast() { $mockday = & new Mock_Calendar_Day($this); $mockday->expectOnce('setLast',array(true)); $Decorator =& new Calendar_Decorator($mockday); $Decorator->setLast(); } function testIsFirst() { $mockday = & new Mock_Calendar_Day($this); $mockday->setReturnValue('isFirst',TRUE); $Decorator =& new Calendar_Decorator($mockday); $this->assertTrue($Decorator->isFirst()); } function testIsLast() { $mockday = & new Mock_Calendar_Day($this); $mockday->setReturnValue('isLast',TRUE); $Decorator =& new Calendar_Decorator($mockday); $this->assertTrue($Decorator->isLast()); } function testSetEmpty() { $mockday = & new Mock_Calendar_Day($this); $mockday->expectOnce('setEmpty',array(true)); $Decorator =& new Calendar_Decorator($mockday); $Decorator->setEmpty(); } function testIsEmpty() { $mockday = & new Mock_Calendar_Day($this); $mockday->setReturnValue('isEmpty',TRUE); $Decorator =& new Calendar_Decorator($mockday); $this->assertTrue($Decorator->isEmpty()); } function testBuild() { $testArray=array('foo'=>'bar'); $this->mockcal->expectOnce('build',array($testArray)); $Decorator = new Calendar_Decorator($this->mockcal); $Decorator->build($testArray); } function testFetch() { $this->mockcal->expectOnce('fetch',array()); $Decorator = new Calendar_Decorator($this->mockcal); $Decorator->fetch(); } function testFetchAll() { $this->mockcal->expectOnce('fetchAll',array()); $Decorator = new Calendar_Decorator($this->mockcal); $Decorator->fetchAll(); } function testSize() { $this->mockcal->expectOnce('size',array()); $Decorator = new Calendar_Decorator($this->mockcal); $Decorator->size(); } function testIsValid() { $this->mockcal->expectOnce('isValid',array()); $Decorator = new Calendar_Decorator($this->mockcal); $Decorator->isValid(); } function testGetValidator() { $this->mockcal->expectOnce('getValidator',array()); $Decorator = new Calendar_Decorator($this->mockcal); $Decorator->getValidator(); } } ?> php-calendar-0.5.5/Calendar-0.5.5/tests/decorator_tests.php000066400000000000000000000011241212436242500233110ustar00rootroot00000000000000GroupTest('Decorator Tests'); $this->addTestFile('decorator_test.php'); $this->addTestFile('decorator_textual_test.php'); $this->addTestFile('decorator_uri_test.php'); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new DecoratorTests(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/decorator_textual_test.php000066400000000000000000000125041212436242500247000ustar00rootroot00000000000000UnitTestCase('Test of Calendar_Decorator_Textual'); } function testMonthNamesLong() { $Textual = new Calendar_Decorator_Textual($this->mockcal); $monthNames = array( 1=>'January', 2=>'February', 3=>'March', 4=>'April', 5=>'May', 6=>'June', 7=>'July', 8=>'August', 9=>'September', 10=>'October', 11=>'November', 12=>'December', ); $this->assertEqual($monthNames,$Textual->monthNames()); } function testMonthNamesShort() { $Textual = new Calendar_Decorator_Textual($this->mockcal); $monthNames = array( 1=>'Jan', 2=>'Feb', 3=>'Mar', 4=>'Apr', 5=>'May', 6=>'Jun', 7=>'Jul', 8=>'Aug', 9=>'Sep', 10=>'Oct', 11=>'Nov', 12=>'Dec', ); $this->assertEqual($monthNames,$Textual->monthNames('short')); } function testMonthNamesTwo() { $Textual = new Calendar_Decorator_Textual($this->mockcal); $monthNames = array( 1=>'Ja', 2=>'Fe', 3=>'Ma', 4=>'Ap', 5=>'Ma', 6=>'Ju', 7=>'Ju', 8=>'Au', 9=>'Se', 10=>'Oc', 11=>'No', 12=>'De', ); $this->assertEqual($monthNames,$Textual->monthNames('two')); } function testMonthNamesOne() { $Textual = new Calendar_Decorator_Textual($this->mockcal); $monthNames = array( 1=>'J', 2=>'F', 3=>'M', 4=>'A', 5=>'M', 6=>'J', 7=>'J', 8=>'A', 9=>'S', 10=>'O', 11=>'N', 12=>'D', ); $this->assertEqual($monthNames,$Textual->monthNames('one')); } function testWeekdayNamesLong() { $Textual = new Calendar_Decorator_Textual($this->mockcal); $weekdayNames = array( 0=>'Sunday', 1=>'Monday', 2=>'Tuesday', 3=>'Wednesday', 4=>'Thursday', 5=>'Friday', 6=>'Saturday', ); $this->assertEqual($weekdayNames,$Textual->weekdayNames()); } function testWeekdayNamesShort() { $Textual = new Calendar_Decorator_Textual($this->mockcal); $weekdayNames = array( 0=>'Sun', 1=>'Mon', 2=>'Tue', 3=>'Wed', 4=>'Thu', 5=>'Fri', 6=>'Sat', ); $this->assertEqual($weekdayNames,$Textual->weekdayNames('short')); } function testWeekdayNamesTwo() { $Textual = new Calendar_Decorator_Textual($this->mockcal); $weekdayNames = array( 0=>'Su', 1=>'Mo', 2=>'Tu', 3=>'We', 4=>'Th', 5=>'Fr', 6=>'Sa', ); $this->assertEqual($weekdayNames,$Textual->weekdayNames('two')); } function testWeekdayNamesOne() { $Textual = new Calendar_Decorator_Textual($this->mockcal); $weekdayNames = array( 0=>'S', 1=>'M', 2=>'T', 3=>'W', 4=>'T', 5=>'F', 6=>'S', ); $this->assertEqual($weekdayNames,$Textual->weekdayNames('one')); } function testPrevMonthNameShort() { $Textual = new Calendar_Decorator_Textual($this->mockcal); $this->assertEqual('Sep',$Textual->prevMonthName('short')); } function testThisMonthNameShort() { $Textual = new Calendar_Decorator_Textual($this->mockcal); $this->assertEqual('Oct',$Textual->thisMonthName('short')); } function testNextMonthNameShort() { $Textual = new Calendar_Decorator_Textual($this->mockcal); $this->assertEqual('Nov',$Textual->nextMonthName('short')); } function testThisDayNameShort() { $Textual = new Calendar_Decorator_Textual($this->mockcal); $this->assertEqual('Wed',$Textual->thisDayName('short')); } function testOrderedWeekdaysShort() { $weekdayNames = array( 0=>'Sun', 1=>'Mon', 2=>'Tue', 3=>'Wed', 4=>'Thu', 5=>'Fri', 6=>'Sat', ); $nShifts = CALENDAR_FIRST_DAY_OF_WEEK; while ($nShifts-- > 0) { $day = array_shift($weekdayNames); array_push($weekdayNames, $day); } $Textual = new Calendar_Decorator_Textual($this->mockcal); $this->assertEqual($weekdayNames,$Textual->orderedWeekdays('short')); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfDecoratorTextual(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/decorator_uri_test.php000066400000000000000000000025601212436242500240120ustar00rootroot00000000000000UnitTestCase('Test of Calendar_Decorator_Uri'); } function testFragments() { $Uri = new Calendar_Decorator_Uri($this->mockcal); $Uri->setFragments('year','month','day','hour','minute','second'); $this->assertEqual('year=&month=&day=&hour=&minute=&second=',$Uri->this('second')); } function testScalarFragments() { $Uri = new Calendar_Decorator_Uri($this->mockcal); $Uri->setFragments('year','month','day','hour','minute','second'); $Uri->setScalar(); $this->assertEqual('&&&&&',$Uri->this('second')); } function testSetSeperator() { $Uri = new Calendar_Decorator_Uri($this->mockcal); $Uri->setFragments('year','month','day','hour','minute','second'); $Uri->setSeparator('/'); $this->assertEqual('year=/month=/day=/hour=/minute=/second=',$Uri->this('second')); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfDecoratorUri(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/helper_test.php000066400000000000000000000070011212436242500224230ustar00rootroot00000000000000UnitTestCase('Test of Calendar_Table_Helper'); } function setUp() { $this->mockengine = new Mock_Calendar_Engine($this); $this->mockengine->setReturnValue('getMinYears',1970); $this->mockengine->setReturnValue('getMaxYears',2037); $this->mockengine->setReturnValue('getMonthsInYear',12); $this->mockengine->setReturnValue('getDaysInMonth',31); $this->mockengine->setReturnValue('getHoursInDay',24); $this->mockengine->setReturnValue('getMinutesInHour',60); $this->mockengine->setReturnValue('getSecondsInMinute',60); $this->mockengine->setReturnValue('getWeekDays',array(0,1,2,3,4,5,6)); $this->mockengine->setReturnValue('getDaysInWeek',7); $this->mockengine->setReturnValue('getFirstDayOfWeek',1); $this->mockengine->setReturnValue('getFirstDayInMonth',3); $this->mockcal = new Mock_Calendar_Second($this); $this->mockcal->setReturnValue('thisYear',2003); $this->mockcal->setReturnValue('thisMonth',10); $this->mockcal->setReturnValue('thisDay',15); $this->mockcal->setReturnValue('thisHour',13); $this->mockcal->setReturnValue('thisMinute',30); $this->mockcal->setReturnValue('thisSecond',45); $this->mockcal->setReturnValue('getEngine',$this->mockengine); } function testGetFirstDay() { for ( $i = 0; $i <= 7; $i++ ) { $Helper = & new Calendar_Table_Helper($this->mockcal,$i); $this->assertEqual($Helper->getFirstDay(),$i); } } function testGetDaysOfWeekMonday() { $Helper = new Calendar_Table_Helper($this->mockcal); $this->assertEqual($Helper->getDaysOfWeek(),array(1,2,3,4,5,6,0)); } function testGetDaysOfWeekSunday() { $Helper = new Calendar_Table_Helper($this->mockcal,0); $this->assertEqual($Helper->getDaysOfWeek(),array(0,1,2,3,4,5,6)); } function testGetDaysOfWeekThursday() { $Helper = new Calendar_Table_Helper($this->mockcal,4); $this->assertEqual($Helper->getDaysOfWeek(),array(4,5,6,0,1,2,3)); } function testGetNumWeeks() { $Helper = new Calendar_Table_Helper($this->mockcal); $this->assertEqual($Helper->getNumWeeks(),5); } function testGetNumTableDaysInMonth() { $Helper = new Calendar_Table_Helper($this->mockcal); $this->assertEqual($Helper->getNumTableDaysInMonth(),35); } function testGetEmptyDaysBefore() { $Helper = new Calendar_Table_Helper($this->mockcal); $this->assertEqual($Helper->getEmptyDaysBefore(),2); } function testGetEmptyDaysAfter() { $Helper = new Calendar_Table_Helper($this->mockcal); $this->assertEqual($Helper->getEmptyDaysAfter(),33); } function testGetEmptyDaysAfterOffset() { $Helper = new Calendar_Table_Helper($this->mockcal); $this->assertEqual($Helper->getEmptyDaysAfterOffset(),5); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfTableHelper(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/hour_test.php000066400000000000000000000054351212436242500221320ustar00rootroot00000000000000UnitTestCase('Test of Hour'); } function setUp() { $this->cal = new Calendar_Hour(2003,10,25,13); } function testPrevDay_Array () { $this->assertEqual( array( 'year' => 2003, 'month' => 10, 'day' => 24, 'hour' => 0, 'minute' => 0, 'second' => 0), $this->cal->prevDay('array')); } function testPrevMinute () { $this->assertEqual(59,$this->cal->prevMinute()); } function testThisMinute () { $this->assertEqual(0,$this->cal->thisMinute()); } function testNextMinute () { $this->assertEqual(1,$this->cal->nextMinute()); } function testPrevSecond () { $this->assertEqual(59,$this->cal->prevSecond()); } function testThisSecond () { $this->assertEqual(0,$this->cal->thisSecond()); } function testNextSecond () { $this->assertEqual(1,$this->cal->nextSecond()); } function testGetTimeStamp() { $stamp = mktime(13,0,0,10,25,2003); $this->assertEqual($stamp,$this->cal->getTimeStamp()); } } class TestOfHourBuild extends TestOfHour { function TestOfHourBuild() { $this->UnitTestCase('Test of Hour::build()'); } function testSize() { $this->cal->build(); $this->assertEqual(60,$this->cal->size()); } function testFetch() { $this->cal->build(); $i=0; while ( $Child = $this->cal->fetch() ) { $i++; } $this->assertEqual(60,$i); } function testFetchAll() { $this->cal->build(); $children = array(); $i = 0; while ( $Child = $this->cal->fetch() ) { $children[$i]=$Child; $i++; } $this->assertEqual($children,$this->cal->fetchAll()); } function testSelection() { require_once(CALENDAR_ROOT . 'Minute.php'); $selection = array(new Calendar_Minute(2003,10,25,13,32)); $this->cal->build($selection); $i = 0; while ( $Child = $this->cal->fetch() ) { if ( $i == 32 ) break; $i++; } $this->assertTrue($Child->isSelected()); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfHour(); $test->run(new HtmlReporter()); $test = &new TestOfHourBuild(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/minute_test.php000066400000000000000000000056471212436242500224630ustar00rootroot00000000000000UnitTestCase('Test of Minute'); } function setUp() { $this->cal = new Calendar_Minute(2003,10,25,13,32); } function testPrevDay_Array () { $this->assertEqual( array( 'year' => 2003, 'month' => 10, 'day' => 24, 'hour' => 0, 'minute' => 0, 'second' => 0), $this->cal->prevDay('array')); } function testPrevSecond () { $this->assertEqual(59,$this->cal->prevSecond()); } function testThisSecond () { $this->assertEqual(0,$this->cal->thisSecond()); } function testThisSecond_Timestamp () { $this->assertEqual($this->cal->cE->dateToStamp( 2003, 10, 25, 13, 32, 0), $this->cal->thisSecond('timestamp')); } function testNextSecond () { $this->assertEqual(1,$this->cal->nextSecond()); } function testNextSecond_Timestamp () { $this->assertEqual($this->cal->cE->dateToStamp( 2003, 10, 25, 13, 32, 1), $this->cal->nextSecond('timestamp')); } function testGetTimeStamp() { $stamp = mktime(13,32,0,10,25,2003); $this->assertEqual($stamp,$this->cal->getTimeStamp()); } } class TestOfMinuteBuild extends TestOfMinute { function TestOfMinuteBuild() { $this->UnitTestCase('Test of Minute::build()'); } function testSize() { $this->cal->build(); $this->assertEqual(60,$this->cal->size()); } function testFetch() { $this->cal->build(); $i=0; while ( $Child = $this->cal->fetch() ) { $i++; } $this->assertEqual(60,$i); } function testFetchAll() { $this->cal->build(); $children = array(); $i = 0; while ( $Child = $this->cal->fetch() ) { $children[$i]=$Child; $i++; } $this->assertEqual($children,$this->cal->fetchAll()); } function testSelection() { require_once(CALENDAR_ROOT . 'Second.php'); $selection = array(new Calendar_Second(2003,10,25,13,32,43)); $this->cal->build($selection); $i = 0; while ( $Child = $this->cal->fetch() ) { if ( $i == 43 ) break; $i++; } $this->assertTrue($Child->isSelected()); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfMinute(); $test->run(new HtmlReporter()); $test = &new TestOfMinuteBuild(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/month_test.php000066400000000000000000000067141212436242500223030ustar00rootroot00000000000000UnitTestCase('Test of Month'); } function setUp() { $this->cal = new Calendar_Month(2003,10); } function testPrevMonth_Object() { $this->assertEqual(new Calendar_Month(2003, 9), $this->cal->prevMonth('object')); } function testPrevDay () { $this->assertEqual(30,$this->cal->prevDay()); } function testPrevDay_Array () { $this->assertEqual( array( 'year' => 2003, 'month' => 9, 'day' => 30, 'hour' => 0, 'minute' => 0, 'second' => 0), $this->cal->prevDay('array')); } function testThisDay () { $this->assertEqual(1,$this->cal->thisDay()); } function testNextDay () { $this->assertEqual(2,$this->cal->nextDay()); } function testPrevHour () { $this->assertEqual(23,$this->cal->prevHour()); } function testThisHour () { $this->assertEqual(0,$this->cal->thisHour()); } function testNextHour () { $this->assertEqual(1,$this->cal->nextHour()); } function testPrevMinute () { $this->assertEqual(59,$this->cal->prevMinute()); } function testThisMinute () { $this->assertEqual(0,$this->cal->thisMinute()); } function testNextMinute () { $this->assertEqual(1,$this->cal->nextMinute()); } function testPrevSecond () { $this->assertEqual(59,$this->cal->prevSecond()); } function testThisSecond () { $this->assertEqual(0,$this->cal->thisSecond()); } function testNextSecond () { $this->assertEqual(1,$this->cal->nextSecond()); } function testGetTimeStamp() { $stamp = mktime(0,0,0,10,1,2003); $this->assertEqual($stamp,$this->cal->getTimeStamp()); } } class TestOfMonthBuild extends TestOfMonth { function TestOfMonthBuild() { $this->UnitTestCase('Test of Month::build()'); } function testSize() { $this->cal->build(); $this->assertEqual(31,$this->cal->size()); } function testFetch() { $this->cal->build(); $i=0; while ( $Child = $this->cal->fetch() ) { $i++; } $this->assertEqual(31,$i); } function testFetchAll() { $this->cal->build(); $children = array(); $i = 1; while ( $Child = $this->cal->fetch() ) { $children[$i]=$Child; $i++; } $this->assertEqual($children,$this->cal->fetchAll()); } function testSelection() { require_once(CALENDAR_ROOT . 'Day.php'); $selection = array(new Calendar_Day(2003,10,25)); $this->cal->build($selection); $i = 1; while ( $Child = $this->cal->fetch() ) { if ( $i == 25 ) break; $i++; } $this->assertTrue($Child->isSelected()); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfMonth(); $test->run(new HtmlReporter()); $test = &new TestOfMonthBuild(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/month_weekdays_test.php000066400000000000000000000136401212436242500241730ustar00rootroot00000000000000UnitTestCase('Test of Month Weekdays'); } function setUp() { $this->cal = new Calendar_Month_Weekdays(2003, 10); } function testPrevDay () { $this->assertEqual(30,$this->cal->prevDay()); } function testPrevDay_Array () { $this->assertEqual( array( 'year' => 2003, 'month' => 9, 'day' => 30, 'hour' => 0, 'minute' => 0, 'second' => 0), $this->cal->prevDay('array')); } function testThisDay () { $this->assertEqual(1, $this->cal->thisDay()); } function testNextDay () { $this->assertEqual(2, $this->cal->nextDay()); } function testPrevHour () { $this->assertEqual(23, $this->cal->prevHour()); } function testThisHour () { $this->assertEqual(0, $this->cal->thisHour()); } function testNextHour () { $this->assertEqual(1, $this->cal->nextHour()); } function testPrevMinute () { $this->assertEqual(59, $this->cal->prevMinute()); } function testThisMinute () { $this->assertEqual(0, $this->cal->thisMinute()); } function testNextMinute () { $this->assertEqual(1, $this->cal->nextMinute()); } function testPrevSecond () { $this->assertEqual(59, $this->cal->prevSecond()); } function testThisSecond () { $this->assertEqual(0, $this->cal->thisSecond()); } function testNextSecond () { $this->assertEqual(1, $this->cal->nextSecond()); } function testGetTimeStamp() { $stamp = mktime(0, 0, 0, 10, 1, 2003); $this->assertEqual($stamp, $this->cal->getTimeStamp()); } } class TestOfMonthWeekdaysBuild extends TestOfMonthWeekdays { function TestOfMonthWeekdaysBuild() { $this->UnitTestCase('Test of Month_Weekdays::build()'); } function testSize() { $this->cal->build(); $this->assertEqual(35, $this->cal->size()); } function testFetch() { $this->cal->build(); $i=0; while ($Child = $this->cal->fetch()) { $i++; } $this->assertEqual(35, $i); } function testFetchAll() { $this->cal->build(); $children = array(); $i = 1; while ($Child = $this->cal->fetch()) { $children[$i] = $Child; $i++; } $this->assertEqual($children,$this->cal->fetchAll()); } function testSelection() { include_once CALENDAR_ROOT . 'Day.php'; $selection = array(new Calendar_Day(2003, 10, 25)); $this->cal->build($selection); $daysInPrevMonth = (0 == CALENDAR_FIRST_DAY_OF_WEEK) ? 3 : 2; $end = 25 + $daysInPrevMonth; $i = 1; while ($Child = $this->cal->fetch()) { if ($i == $end) { break; } $i++; } $this->assertTrue($Child->isSelected()); $this->assertEqual(25, $Child->day); } function testEmptyCount() { $this->cal->build(); $empty = 0; while ($Child = $this->cal->fetch()) { if ($Child->isEmpty()) { $empty++; } } $this->assertEqual(4, $empty); } function testEmptyCount2() { $this->cal = new Calendar_Month_Weekdays(2010,3); $this->cal->build(); $empty = 0; while ($Child = $this->cal->fetch()) { if ($Child->isEmpty()) { $empty++; } } $this->assertEqual(4, $empty); } function testEmptyCount3() { $this->cal = new Calendar_Month_Weekdays(2010,6); $this->cal->build(); $empty = 0; while ($Child = $this->cal->fetch()) { if ($Child->isEmpty()) { $empty++; } } $this->assertEqual(5, $empty); } function testEmptyDaysBefore_AfterAdjust() { $this->cal = new Calendar_Month_Weekdays(2004, 0); $this->cal->build(); $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 1 : 0; $this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysBefore()); } function testEmptyDaysBefore() { $this->cal = new Calendar_Month_Weekdays(2010, 3); $this->cal->build(); $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 1 : 0; $this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysBefore()); } function testEmptyDaysBefore2() { $this->cal = new Calendar_Month_Weekdays(2010, 6); $this->cal->build(); $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 2 : 1; $this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysBefore()); } function testEmptyDaysAfter() { $this->cal = new Calendar_Month_Weekdays(2010, 3); $this->cal->build(); $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 30 : 31; $this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysAfter()); } function testEmptyDaysAfter2() { $this->cal = new Calendar_Month_Weekdays(2010, 6); $this->cal->build(); $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 30 : 31; $this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysAfter()); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfMonthWeekdays(); $test->run(new HtmlReporter()); $test = &new TestOfMonthWeekdaysBuild(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/month_weeks_test.php000066400000000000000000000077021212436242500234770ustar00rootroot00000000000000UnitTestCase('Test of Month Weeks'); } function setUp() { $this->cal = new Calendar_Month_Weeks(2003, 10); } function testPrevDay () { $this->assertEqual(30, $this->cal->prevDay()); } function testPrevDay_Array () { $this->assertEqual( array( 'year' => 2003, 'month' => 9, 'day' => 30, 'hour' => 0, 'minute' => 0, 'second' => 0), $this->cal->prevDay('array')); } function testThisDay () { $this->assertEqual(1, $this->cal->thisDay()); } function testNextDay () { $this->assertEqual(2, $this->cal->nextDay()); } function testPrevHour () { $this->assertEqual(23, $this->cal->prevHour()); } function testThisHour () { $this->assertEqual(0, $this->cal->thisHour()); } function testNextHour () { $this->assertEqual(1, $this->cal->nextHour()); } function testPrevMinute () { $this->assertEqual(59, $this->cal->prevMinute()); } function testThisMinute () { $this->assertEqual(0, $this->cal->thisMinute()); } function testNextMinute () { $this->assertEqual(1, $this->cal->nextMinute()); } function testPrevSecond () { $this->assertEqual(59, $this->cal->prevSecond()); } function testThisSecond () { $this->assertEqual(0, $this->cal->thisSecond()); } function testNextSecond () { $this->assertEqual(1, $this->cal->nextSecond()); } function testGetTimeStamp() { $stamp = mktime(0,0,0,10,1,2003); $this->assertEqual($stamp,$this->cal->getTimeStamp()); } } class TestOfMonthWeeksBuild extends TestOfMonthWeeks { function TestOfMonthWeeksBuild() { $this->UnitTestCase('Test of Month_Weeks::build()'); } function testSize() { $this->cal->build(); $this->assertEqual(5,$this->cal->size()); } function testFetch() { $this->cal->build(); $i=0; while ($Child = $this->cal->fetch()) { $i++; } $this->assertEqual(5,$i); } /* Recusive dependency issue with SimpleTest function testFetchAll() { $this->cal->build(); $children = array(); $i = 1; while ( $Child = $this->cal->fetch() ) { $children[$i]=$Child; $i++; } $this->assertEqual($children,$this->cal->fetchAll()); } */ function testSelection() { include_once CALENDAR_ROOT . 'Week.php'; $selection = array(new Calendar_Week(2003, 10, 12)); $this->cal->build($selection); $i = 1; $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 3 : 2; while ($Child = $this->cal->fetch()) { if ($i == $expected) { //12-10-2003 is in the 2nd week of the month if firstDay is Monday, //in the 3rd if firstDay is Sunday break; } $i++; } $this->assertTrue($Child->isSelected()); } function testEmptyDaysBefore_AfterAdjust() { $this->cal = new Calendar_Month_Weeks(2004, 0); $this->cal->build(); $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 1 : 0; $this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysBefore()); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfMonthWeeks(); $test->run(new HtmlReporter()); $test = &new TestOfMonthWeeksBuild(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/peardate_engine_test.php000066400000000000000000000114321212436242500242610ustar00rootroot00000000000000UnitTestCase('Test of Calendar_Engine_PearDate'); } function setUp() { $this->engine = new Calendar_Engine_PearDate(); } function testGetSecondsInMinute() { $this->assertEqual($this->engine->getSecondsInMinute(),60); } function testGetMinutesInHour() { $this->assertEqual($this->engine->getMinutesInHour(),60); } function testGetHoursInDay() { $this->assertEqual($this->engine->getHoursInDay(),24); } function testGetFirstDayOfWeek() { $this->assertEqual($this->engine->getFirstDayOfWeek(),1); } function testGetWeekDays() { $this->assertEqual($this->engine->getWeekDays(),array(0,1,2,3,4,5,6)); } function testGetDaysInWeek() { $this->assertEqual($this->engine->getDaysInWeek(),7); } function testGetWeekNInYear() { $this->assertEqual($this->engine->getWeekNInYear(2003, 11, 3), 45); } function testGetWeekNInMonth() { $this->assertEqual($this->engine->getWeekNInMonth(2003, 11, 3), 2); } function testGetWeeksInMonth0() { $this->assertEqual($this->engine->getWeeksInMonth(2003, 11, 0), 6); //week starts on sunday } function testGetWeeksInMonth1() { $this->assertEqual($this->engine->getWeeksInMonth(2003, 11, 1), 5); //week starts on monday } function testGetWeeksInMonth2() { $this->assertEqual($this->engine->getWeeksInMonth(2003, 2, 6), 4); //week starts on saturday } function testGetWeeksInMonth3() { // Unusual cases that can cause fails (shows up with example 21.php) $this->assertEqual($this->engine->getWeeksInMonth(2004,2,1),5); $this->assertEqual($this->engine->getWeeksInMonth(2004,8,1),6); } function testGetDayOfWeek() { $this->assertEqual($this->engine->getDayOfWeek(2003, 11, 18), 2); } function testGetFirstDayInMonth() { $this->assertEqual($this->engine->getFirstDayInMonth(2003,10),3); } function testGetDaysInMonth() { $this->assertEqual($this->engine->getDaysInMonth(2003,10),31); } function testGetMinYears() { $this->assertEqual($this->engine->getMinYears(),0); } function testGetMaxYears() { $this->assertEqual($this->engine->getMaxYears(),9999); } function testDateToStamp() { $stamp = '2003-10-15 13:30:45'; $this->assertEqual($this->engine->dateToStamp(2003,10,15,13,30,45),$stamp); } function testStampToSecond() { $stamp = '2003-10-15 13:30:45'; $this->assertEqual($this->engine->stampToSecond($stamp),45); } function testStampToMinute() { $stamp = '2003-10-15 13:30:45'; $this->assertEqual($this->engine->stampToMinute($stamp),30); } function testStampToHour() { $stamp = '2003-10-15 13:30:45'; $this->assertEqual($this->engine->stampToHour($stamp),13); } function testStampToDay() { $stamp = '2003-10-15 13:30:45'; $this->assertEqual($this->engine->stampToDay($stamp),15); } function testStampToMonth() { $stamp = '2003-10-15 13:30:45'; $this->assertEqual($this->engine->stampToMonth($stamp),10); } function testStampToYear() { $stamp = '2003-10-15 13:30:45'; $this->assertEqual($this->engine->stampToYear($stamp),2003); } function testAdjustDate() { $stamp = '2004-01-01 13:30:45'; $y = $this->engine->stampToYear($stamp); $m = $this->engine->stampToMonth($stamp); $d = $this->engine->stampToDay($stamp); //the first day of the month should be thursday $this->assertEqual($this->engine->getDayOfWeek($y, $m, $d), 4); $m--; // 2004-00-01 => 2003-12-01 $this->engine->adjustDate($y, $m, $d, $dummy, $dummy, $dummy); $this->assertEqual($y, 2003); $this->assertEqual($m, 12); $this->assertEqual($d, 1); // get last day and check if it's wednesday $d = $this->engine->getDaysInMonth($y, $m); $this->assertEqual($this->engine->getDayOfWeek($y, $m, $d), 3); } function testIsToday() { $stamp = date('Y-m-d H:i:s'); $this->assertTrue($this->engine->isToday($stamp)); $stamp = date('Y-m-d H:i:s', time() + 1000000000); $this->assertFalse($this->engine->isToday($stamp)); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfPearDateEngine(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/second_test.php000066400000000000000000000016021212436242500224200ustar00rootroot00000000000000UnitTestCase('Test of Second'); } function setUp() { $this->cal = new Calendar_Second(2003,10,25,13,32,43); } function testPrevDay_Array () { $this->assertEqual( array( 'year' => 2003, 'month' => 10, 'day' => 24, 'hour' => 0, 'minute' => 0, 'second' => 0), $this->cal->prevDay('array')); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfSecond(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/simple_include.php000066400000000000000000000004601212436242500231030ustar00rootroot00000000000000php-calendar-0.5.5/Calendar-0.5.5/tests/table_helper_tests.php000066400000000000000000000007531212436242500237640ustar00rootroot00000000000000GroupTest('Table Helper Tests'); $this->addTestFile('helper_test.php'); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TableHelperTests(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/unixts_engine_test.php000066400000000000000000000101001212436242500240150ustar00rootroot00000000000000UnitTestCase('Test of Calendar_Engine_UnixTs'); } function setUp() { $this->engine = new Calendar_Engine_UnixTs(); } function testGetSecondsInMinute() { $this->assertEqual($this->engine->getSecondsInMinute(),60); } function testGetMinutesInHour() { $this->assertEqual($this->engine->getMinutesInHour(),60); } function testGetHoursInDay() { $this->assertEqual($this->engine->getHoursInDay(),24); } function testGetFirstDayOfWeek() { $this->assertEqual($this->engine->getFirstDayOfWeek(),1); } function testGetWeekDays() { $this->assertEqual($this->engine->getWeekDays(),array(0,1,2,3,4,5,6)); } function testGetDaysInWeek() { $this->assertEqual($this->engine->getDaysInWeek(),7); } function testGetWeekNInYear() { $this->assertEqual($this->engine->getWeekNInYear(2003, 11, 3), 45); } function testGetWeekNInMonth() { $this->assertEqual($this->engine->getWeekNInMonth(2003, 11, 3), 2); } function testGetWeeksInMonth0() { $this->assertEqual($this->engine->getWeeksInMonth(2003, 11, 0), 6); //week starts on sunday } function testGetWeeksInMonth1() { $this->assertEqual($this->engine->getWeeksInMonth(2003, 11, 1), 5); //week starts on monday } function testGetWeeksInMonth2() { $this->assertEqual($this->engine->getWeeksInMonth(2003, 2, 6), 4); //week starts on saturday } function testGetWeeksInMonth3() { // Unusual cases that can cause fails (shows up with example 21.php) $this->assertEqual($this->engine->getWeeksInMonth(2004,2,1),5); $this->assertEqual($this->engine->getWeeksInMonth(2004,8,1),6); } function testGetDayOfWeek() { $this->assertEqual($this->engine->getDayOfWeek(2003, 11, 18), 2); } function testGetFirstDayInMonth() { $this->assertEqual($this->engine->getFirstDayInMonth(2003,10),3); } function testGetDaysInMonth() { $this->assertEqual($this->engine->getDaysInMonth(2003,10),31); } function testGetMinYears() { $test = strpos(PHP_OS, 'WIN') >= 0 ? 1970 : 1902; $this->assertEqual($this->engine->getMinYears(),$test); } function testGetMaxYears() { $this->assertEqual($this->engine->getMaxYears(),2037); } function testDateToStamp() { $stamp = mktime(0,0,0,10,15,2003); $this->assertEqual($this->engine->dateToStamp(2003,10,15,0,0,0),$stamp); } function testStampToSecond() { $stamp = mktime(13,30,45,10,15,2003); $this->assertEqual($this->engine->stampToSecond($stamp),45); } function testStampToMinute() { $stamp = mktime(13,30,45,10,15,2003); $this->assertEqual($this->engine->stampToMinute($stamp),30); } function testStampToHour() { $stamp = mktime(13,30,45,10,15,2003); $this->assertEqual($this->engine->stampToHour($stamp),13); } function testStampToDay() { $stamp = mktime(13,30,45,10,15,2003); $this->assertEqual($this->engine->stampToDay($stamp),15); } function testStampToMonth() { $stamp = mktime(13,30,45,10,15,2003); $this->assertEqual($this->engine->stampToMonth($stamp),10); } function testStampToYear() { $stamp = mktime(13,30,45,10,15,2003); $this->assertEqual($this->engine->stampToYear($stamp),2003); } function testIsToday() { $stamp = mktime(); $this->assertTrue($this->engine->isToday($stamp)); $stamp += 1000000000; $this->assertFalse($this->engine->isToday($stamp)); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfUnixTsEngine(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/util_tests.php000066400000000000000000000010001212436242500222750ustar00rootroot00000000000000GroupTest('Util Tests'); $this->addTestFile('util_uri_test.php'); $this->addTestFile('util_textual_test.php'); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new UtilTests(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/util_textual_test.php000066400000000000000000000141341212436242500236740ustar00rootroot00000000000000UnitTestCase('Test of Calendar_Util_Textual'); } function setUp() { $this->mockengine = new Mock_Calendar_Engine($this); $this->mockcal = new Mock_Calendar_Second($this); $this->mockcal->setReturnValue('prevYear',2002); $this->mockcal->setReturnValue('thisYear',2003); $this->mockcal->setReturnValue('nextYear',2004); $this->mockcal->setReturnValue('prevMonth',9); $this->mockcal->setReturnValue('thisMonth',10); $this->mockcal->setReturnValue('nextMonth',11); $this->mockcal->setReturnValue('prevDay',14); $this->mockcal->setReturnValue('thisDay',15); $this->mockcal->setReturnValue('nextDay',16); $this->mockcal->setReturnValue('prevHour',12); $this->mockcal->setReturnValue('thisHour',13); $this->mockcal->setReturnValue('nextHour',14); $this->mockcal->setReturnValue('prevMinute',29); $this->mockcal->setReturnValue('thisMinute',30); $this->mockcal->setReturnValue('nextMinute',31); $this->mockcal->setReturnValue('prevSecond',44); $this->mockcal->setReturnValue('thisSecond',45); $this->mockcal->setReturnValue('nextSecond',46); $this->mockcal->setReturnValue('getEngine',$this->mockengine); $this->mockcal->setReturnValue('getTimestamp',12345); } function tearDown() { unset ( $this->engine ); unset ( $this->mockcal ); } function testMonthNamesLong() { $monthNames = array( 1=>'January', 2=>'February', 3=>'March', 4=>'April', 5=>'May', 6=>'June', 7=>'July', 8=>'August', 9=>'September', 10=>'October', 11=>'November', 12=>'December', ); $this->assertEqual($monthNames,Calendar_Util_Textual::monthNames()); } function testMonthNamesShort() { $monthNames = array( 1=>'Jan', 2=>'Feb', 3=>'Mar', 4=>'Apr', 5=>'May', 6=>'Jun', 7=>'Jul', 8=>'Aug', 9=>'Sep', 10=>'Oct', 11=>'Nov', 12=>'Dec', ); $this->assertEqual($monthNames,Calendar_Util_Textual::monthNames('short')); } function testMonthNamesTwo() { $monthNames = array( 1=>'Ja', 2=>'Fe', 3=>'Ma', 4=>'Ap', 5=>'Ma', 6=>'Ju', 7=>'Ju', 8=>'Au', 9=>'Se', 10=>'Oc', 11=>'No', 12=>'De', ); $this->assertEqual($monthNames,Calendar_Util_Textual::monthNames('two')); } function testMonthNamesOne() { $monthNames = array( 1=>'J', 2=>'F', 3=>'M', 4=>'A', 5=>'M', 6=>'J', 7=>'J', 8=>'A', 9=>'S', 10=>'O', 11=>'N', 12=>'D', ); $this->assertEqual($monthNames,Calendar_Util_Textual::monthNames('one')); } function testWeekdayNamesLong() { $weekdayNames = array( 0=>'Sunday', 1=>'Monday', 2=>'Tuesday', 3=>'Wednesday', 4=>'Thursday', 5=>'Friday', 6=>'Saturday', ); $this->assertEqual($weekdayNames,Calendar_Util_Textual::weekdayNames()); } function testWeekdayNamesShort() { $weekdayNames = array( 0=>'Sun', 1=>'Mon', 2=>'Tue', 3=>'Wed', 4=>'Thu', 5=>'Fri', 6=>'Sat', ); $this->assertEqual($weekdayNames,Calendar_Util_Textual::weekdayNames('short')); } function testWeekdayNamesTwo() { $weekdayNames = array( 0=>'Su', 1=>'Mo', 2=>'Tu', 3=>'We', 4=>'Th', 5=>'Fr', 6=>'Sa', ); $this->assertEqual($weekdayNames,Calendar_Util_Textual::weekdayNames('two')); } function testWeekdayNamesOne() { $weekdayNames = array( 0=>'S', 1=>'M', 2=>'T', 3=>'W', 4=>'T', 5=>'F', 6=>'S', ); $this->assertEqual($weekdayNames,Calendar_Util_Textual::weekdayNames('one')); } function testPrevMonthNameShort() { $this->assertEqual('Sep',Calendar_Util_Textual::prevMonthName($this->mockcal,'short')); } function testThisMonthNameShort() { $this->assertEqual('Oct',Calendar_Util_Textual::thisMonthName($this->mockcal,'short')); } function testNextMonthNameShort() { $this->assertEqual('Nov',Calendar_Util_Textual::nextMonthName($this->mockcal,'short')); } function testThisDayNameShort() { $this->assertEqual('Wed',Calendar_Util_Textual::thisDayName($this->mockcal,'short')); } function testOrderedWeekdaysShort() { $weekdayNames = array( 0=>'Sun', 1=>'Mon', 2=>'Tue', 3=>'Wed', 4=>'Thu', 5=>'Fri', 6=>'Sat', ); $nShifts = CALENDAR_FIRST_DAY_OF_WEEK; while ($nShifts-- > 0) { $day = array_shift($weekdayNames); array_push($weekdayNames, $day); } $this->assertEqual($weekdayNames,Calendar_Util_Textual::orderedWeekdays($this->mockcal,'short')); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfUtilTextual(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/util_uri_test.php000066400000000000000000000033011212436242500227770ustar00rootroot00000000000000UnitTestCase('Test of Calendar_Util_Uri'); } function setUp() { $this->MockCal = & new Mock_Calendar_Day($this); $this->MockCal->setReturnValue('getEngine',new Mock_Calendar_Engine($this)); } function testFragments() { $Uri = new Calendar_Util_Uri('y','m','d','h','m','s'); $Uri->setFragments('year','month','day','hour','minute','second'); $this->assertEqual( 'year=&month=&day=&hour=&minute=&second=', $Uri->this($this->MockCal, 'second') ); } function testScalarFragments() { $Uri = new Calendar_Util_Uri('year','month','day','hour','minute','second'); $Uri->scalar = true; $this->assertEqual( '&&&&&', $Uri->this($this->MockCal, 'second') ); } function testSetSeperator() { $Uri = new Calendar_Util_Uri('year','month','day','hour','minute','second'); $Uri->separator = '/'; $this->assertEqual( 'year=/month=/day=/hour=/minute=/second=', $Uri->this($this->MockCal, 'second') ); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfUtilUri(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/validator_error_test.php000066400000000000000000000017531212436242500243520ustar00rootroot00000000000000UnitTestCase('Test of Validation Error'); } function setUp() { $this->vError = new Calendar_Validation_Error('foo',20,'bar'); } function testGetUnit() { $this->assertEqual($this->vError->getUnit(),'foo'); } function testGetValue() { $this->assertEqual($this->vError->getValue(),20); } function testGetMessage() { $this->assertEqual($this->vError->getMessage(),'bar'); } function testToString() { $this->assertEqual($this->vError->toString(),'foo = 20 [bar]'); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfValidationError(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/validator_tests.php000066400000000000000000000010401212436242500233110ustar00rootroot00000000000000GroupTest('Validator Tests'); $this->addTestFile('validator_unit_test.php'); $this->addTestFile('validator_error_test.php'); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new ValidatorTests(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/validator_unit_test.php000066400000000000000000000203511212436242500241730ustar00rootroot00000000000000UnitTestCase('Test of Validator'); } function setUp() { $this->mockengine = new Mock_Calendar_Engine($this); $this->mockengine->setReturnValue('getMinYears',1970); $this->mockengine->setReturnValue('getMaxYears',2037); $this->mockengine->setReturnValue('getMonthsInYear',12); $this->mockengine->setReturnValue('getDaysInMonth',30); $this->mockengine->setReturnValue('getHoursInDay',24); $this->mockengine->setReturnValue('getMinutesInHour',60); $this->mockengine->setReturnValue('getSecondsInMinute',60); $this->mockcal = new Mock_Calendar_Second($this); $this->mockcal->setReturnValue('getEngine',$this->mockengine); } function tearDown() { unset ($this->mockengine); unset ($this->mocksecond); } function testIsValidYear() { $this->mockcal->setReturnValue('thisYear',2000); $Validator = new Calendar_Validator($this->mockcal); $this->assertTrue($Validator->isValidYear()); } function testIsValidYearTooSmall() { $this->mockcal->setReturnValue('thisYear',1969); $Validator = new Calendar_Validator($this->mockcal); $this->assertFalse($Validator->isValidYear()); } function testIsValidYearTooLarge() { $this->mockcal->setReturnValue('thisYear',2038); $Validator = new Calendar_Validator($this->mockcal); $this->assertFalse($Validator->isValidYear()); } function testIsValidMonth() { $this->mockcal->setReturnValue('thisMonth',10); $Validator = new Calendar_Validator($this->mockcal); $this->assertTrue($Validator->isValidMonth()); } function testIsValidMonthTooSmall() { $this->mockcal->setReturnValue('thisMonth',0); $Validator = new Calendar_Validator($this->mockcal); $this->assertFalse($Validator->isValidMonth()); } function testIsValidMonthTooLarge() { $this->mockcal->setReturnValue('thisMonth',13); $Validator = new Calendar_Validator($this->mockcal); $this->assertFalse($Validator->isValidMonth()); } function testIsValidDay() { $this->mockcal->setReturnValue('thisDay',10); $Validator = new Calendar_Validator($this->mockcal); $this->assertTrue($Validator->isValidDay()); } function testIsValidDayTooSmall() { $this->mockcal->setReturnValue('thisDay',0); $Validator = new Calendar_Validator($this->mockcal); $this->assertFalse($Validator->isValidDay()); } function testIsValidDayTooLarge() { $this->mockcal->setReturnValue('thisDay',31); $Validator = new Calendar_Validator($this->mockcal); $this->assertFalse($Validator->isValidDay()); } function testIsValidHour() { $this->mockcal->setReturnValue('thisHour',10); $Validator = new Calendar_Validator($this->mockcal); $this->assertTrue($Validator->isValidHour()); } function testIsValidHourTooSmall() { $this->mockcal->setReturnValue('thisHour',-1); $Validator = new Calendar_Validator($this->mockcal); $this->assertFalse($Validator->isValidHour()); } function testIsValidHourTooLarge() { $this->mockcal->setReturnValue('thisHour',24); $Validator = new Calendar_Validator($this->mockcal); $this->assertFalse($Validator->isValidHour()); } function testIsValidMinute() { $this->mockcal->setReturnValue('thisMinute',30); $Validator = new Calendar_Validator($this->mockcal); $this->assertTrue($Validator->isValidMinute()); } function testIsValidMinuteTooSmall() { $this->mockcal->setReturnValue('thisMinute',-1); $Validator = new Calendar_Validator($this->mockcal); $this->assertFalse($Validator->isValidMinute()); } function testIsValidMinuteTooLarge() { $this->mockcal->setReturnValue('thisMinute',60); $Validator = new Calendar_Validator($this->mockcal); $this->assertFalse($Validator->isValidMinute()); } function testIsValidSecond() { $this->mockcal->setReturnValue('thisSecond',30); $Validator = new Calendar_Validator($this->mockcal); $this->assertTrue($Validator->isValidSecond()); } function testIsValidSecondTooSmall() { $this->mockcal->setReturnValue('thisSecond',-1); $Validator = new Calendar_Validator($this->mockcal); $this->assertFalse($Validator->isValidSecond()); } function testIsValidSecondTooLarge() { $this->mockcal->setReturnValue('thisSecond',60); $Validator = new Calendar_Validator($this->mockcal); $this->assertFalse($Validator->isValidSecond()); } function testIsValid() { $this->mockcal->setReturnValue('thisYear',2000); $this->mockcal->setReturnValue('thisMonth',5); $this->mockcal->setReturnValue('thisDay',15); $this->mockcal->setReturnValue('thisHour',13); $this->mockcal->setReturnValue('thisMinute',30); $this->mockcal->setReturnValue('thisSecond',40); $Validator = new Calendar_Validator($this->mockcal); $this->assertTrue($Validator->isValid()); } function testIsValidAllWrong() { $this->mockcal->setReturnValue('thisYear',2038); $this->mockcal->setReturnValue('thisMonth',13); $this->mockcal->setReturnValue('thisDay',31); $this->mockcal->day = 31; $this->mockcal->setReturnValue('thisHour',24); $this->mockcal->setReturnValue('thisMinute',60); $this->mockcal->setReturnValue('thisSecond',60); $Validator = new Calendar_Validator($this->mockcal); $this->assertFalse($Validator->isValid()); $i = 0; while ( $Validator->fetch() ) { $i++; } $this->assertEqual($i,6); } } class TestOfValidatorLive extends UnitTestCase { function TestOfValidatorLive() { $this->UnitTestCase('Test of Validator Live'); } function testYear() { $Unit = new Calendar_Year(2038); $Validator = & $Unit->getValidator(); $this->assertFalse($Validator->isValidYear()); } function testMonth() { $Unit = new Calendar_Month(2000,13); $Validator = & $Unit->getValidator(); $this->assertFalse($Validator->isValidMonth()); } /* function testWeek() { $Unit = new Calendar_Week(2000,12,7); $Validator = & $Unit->getValidator(); $this->assertFalse($Validator->isValidWeek()); } */ function testDay() { $Unit = new Calendar_Day(2000,12,32); $Validator = & $Unit->getValidator(); $this->assertFalse($Validator->isValidDay()); } function testHour() { $Unit = new Calendar_Hour(2000,12,20,24); $Validator = & $Unit->getValidator(); $this->assertFalse($Validator->isValidHour()); } function testMinute() { $Unit = new Calendar_Minute(2000,12,20,23,60); $Validator = & $Unit->getValidator(); $this->assertFalse($Validator->isValidMinute()); } function testSecond() { $Unit = new Calendar_Second(2000,12,20,23,59,60); $Validator = & $Unit->getValidator(); $this->assertFalse($Validator->isValidSecond()); } function testAllBad() { $Unit = new Calendar_Second(2000,13,32,24,60,60); $this->assertFalse($Unit->isValid()); $Validator = & $Unit->getValidator(); $i = 0; while ( $Validator->fetch() ) { $i++; } $this->assertEqual($i,5); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfValidator(); $test->run(new HtmlReporter()); $test = &new TestOfValidatorLive(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/week_firstday_0_test.php000066400000000000000000000211441212436242500242270ustar00rootroot00000000000000UnitTestCase('Test of Week - Week Starting on Sunday'); } function setUp() { $this->cal = Calendar_Factory::create('Week', 2003, 10, 9); //print_r($this->cal); } function testPrevDay () { $this->assertEqual(8, $this->cal->prevDay()); } function testPrevDay_Array () { $this->assertEqual( array( 'year' => 2003, 'month' => 10, 'day' => 8, 'hour' => 0, 'minute' => 0, 'second' => 0), $this->cal->prevDay('array')); } function testThisDay () { $this->assertEqual(9, $this->cal->thisDay()); } function testNextDay () { $this->assertEqual(10, $this->cal->nextDay()); } function testPrevHour () { $this->assertEqual(23, $this->cal->prevHour()); } function testThisHour () { $this->assertEqual(0, $this->cal->thisHour()); } function testNextHour () { $this->assertEqual(1, $this->cal->nextHour()); } function testPrevMinute () { $this->assertEqual(59, $this->cal->prevMinute()); } function testThisMinute () { $this->assertEqual(0, $this->cal->thisMinute()); } function testNextMinute () { $this->assertEqual(1, $this->cal->nextMinute()); } function testPrevSecond () { $this->assertEqual(59, $this->cal->prevSecond()); } function testThisSecond () { $this->assertEqual(0, $this->cal->thisSecond()); } function testNextSecond () { $this->assertEqual(1, $this->cal->nextSecond()); } function testGetTimeStamp() { $stamp = mktime(0,0,0,10,9,2003); $this->assertEqual($stamp,$this->cal->getTimeStamp()); } function testNewTimeStamp() { $stamp = mktime(0,0,0,7,28,2004); $this->cal->setTimestamp($stamp); $this->assertEqual('29 2004', date('W Y', $this->cal->prevWeek(true))); $this->assertEqual('30 2004', date('W Y', $this->cal->thisWeek(true))); $this->assertEqual('31 2004', date('W Y', $this->cal->nextWeek(true))); } function testPrevWeekInMonth() { $this->assertEqual(1, $this->cal->prevWeek()); $stamp = mktime(0,0,0,2,3,2005); $this->cal->setTimestamp($stamp); $this->assertEqual(0, $this->cal->prevWeek()); } function testThisWeekInMonth() { $this->assertEqual(2, $this->cal->thisWeek()); $stamp = mktime(0,0,0,2,3,2005); $this->cal->setTimestamp($stamp); $this->assertEqual(1, $this->cal->thisWeek()); $stamp = mktime(0,0,0,1,1,2005); $this->cal->setTimestamp($stamp); $this->assertEqual(1, $this->cal->thisWeek()); $stamp = mktime(0,0,0,1,3,2005); $this->cal->setTimestamp($stamp); $this->assertEqual(2, $this->cal->thisWeek()); } function testNextWeekInMonth() { $this->assertEqual(3, $this->cal->nextWeek()); $stamp = mktime(0,0,0,2,3,2005); $this->cal->setTimestamp($stamp); $this->assertEqual(2, $this->cal->nextWeek()); } function testPrevWeekInYear() { $this->assertEqual(date('W', $this->cal->prevWeek('timestamp')), $this->cal->prevWeek('n_in_year')); $stamp = mktime(0,0,0,1,1,2004); $this->cal->setTimestamp($stamp); $this->assertEqual(date('W', $this->cal->nextWeek('timestamp')), $this->cal->nextWeek('n_in_year')); } function testThisWeekInYear() { $this->assertEqual(date('W', $this->cal->thisWeek('timestamp')), $this->cal->thisWeek('n_in_year')); $stamp = mktime(0,0,0,1,1,2004); $this->cal->setTimestamp($stamp); $this->assertEqual(date('W', $this->cal->thisWeek('timestamp')), $this->cal->thisWeek('n_in_year')); } function testFirstWeekInYear() { $stamp = mktime(0,0,0,1,4,2004); $this->cal->setTimestamp($stamp); $this->assertEqual(1, $this->cal->thisWeek('n_in_year')); } function testNextWeekInYear() { $this->assertEqual(date('W', $this->cal->nextWeek('timestamp')), $this->cal->nextWeek('n_in_year')); } function testPrevWeekArray() { $testArray = array( 'year'=>2003, 'month'=>9, 'day'=>28, 'hour'=>0, 'minute'=>0, 'second'=>0 ); $this->assertEqual($testArray, $this->cal->prevWeek('array')); } function testThisWeekArray() { $testArray = array( 'year'=>2003, 'month'=>10, 'day'=>5, 'hour'=>0, 'minute'=>0, 'second'=>0 ); $this->assertEqual($testArray, $this->cal->thisWeek('array')); } function testNextWeekArray() { $testArray = array( 'year'=>2003, 'month'=>10, 'day'=>12, 'hour'=>0, 'minute'=>0, 'second'=>0 ); $this->assertEqual($testArray, $this->cal->nextWeek('array')); } function testPrevWeekObject() { $testWeek = Calendar_Factory::create('Week', 2003,9,28); $Week = $this->cal->prevWeek('object'); $this->assertEqual($testWeek->getTimeStamp(),$Week->getTimeStamp()); } function testThisWeekObject() { $testWeek = Calendar_Factory::create('Week', 2003,10,5); $Week = $this->cal->thisWeek('object'); $this->assertEqual($testWeek->getTimeStamp(),$Week->getTimeStamp()); } function testNextWeekObject() { $testWeek = Calendar_Factory::create('Week', 2003,10,12); $Week = $this->cal->nextWeek('object'); $this->assertEqual($testWeek->getTimeStamp(),$Week->getTimeStamp()); } } class TestOfWeek_firstday_0_Build extends TestOfWeek_firstday_0 { function TestOfWeek_firstday_0_Build() { $this->UnitTestCase('Test of Week::build() - FirstDay = Sunday'); } function testSize() { $this->cal->build(); $this->assertEqual(7, $this->cal->size()); } function testFetch() { $this->cal->build(); $i=0; while ($Child = $this->cal->fetch()) { $i++; } $this->assertEqual(7, $i); } function testFetchAll() { $this->cal->build(); $children = array(); $i = 1; while ( $Child = $this->cal->fetch() ) { $children[$i]=$Child; $i++; } $this->assertEqual($children,$this->cal->fetchAll()); } function testSelection() { require_once(CALENDAR_ROOT . 'Day.php'); $selection = array(Calendar_Factory::create('Day', 2003, 10, 6)); $this->cal->build($selection); $i = 1; while ($Child = $this->cal->fetch()) { if ($i == 2) { break; //06-10-2003 is the 2nd day of the week } $i++; } $this->assertTrue($Child->isSelected()); } function testSelectionCornerCase() { require_once(CALENDAR_ROOT . 'Day.php'); $selectedDays = array( Calendar_Factory::create('Day', 2003, 12, 28), Calendar_Factory::create('Day', 2003, 12, 29), Calendar_Factory::create('Day', 2003, 12, 30), Calendar_Factory::create('Day', 2003, 12, 31), Calendar_Factory::create('Day', 2004, 01, 01), Calendar_Factory::create('Day', 2004, 01, 02), Calendar_Factory::create('Day', 2004, 01, 03) ); $this->cal = Calendar_Factory::create('Week', 2003, 12, 31, 0); $this->cal->build($selectedDays); while ($Day = $this->cal->fetch()) { $this->assertTrue($Day->isSelected()); } $this->cal = Calendar_Factory::create('Week', 2004, 1, 1, 0); $this->cal->build($selectedDays); while ($Day = $this->cal->fetch()) { $this->assertTrue($Day->isSelected()); } } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfWeek_firstday_0(); $test->run(new HtmlReporter()); $test = &new TestOfWeek_firstday_0_Build(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/week_test.php000066400000000000000000000235231212436242500221060ustar00rootroot00000000000000UnitTestCase('Test of Week'); } function setUp() { $this->cal = Calendar_Factory::create('Week', 2003, 10, 9); //print_r($this->cal); } function testThisYear () { $this->assertEqual(2003, $this->cal->thisYear()); $stamp = mktime(0,0,0,1,1,2003); $this->cal->setTimestamp($stamp); $this->assertEqual(2003, $this->cal->thisYear()); $stamp = mktime(0,0,0,12,31,2003); $this->cal->setTimestamp($stamp); $this->assertEqual(2004, $this->cal->thisYear()); $stamp = mktime(0,0,0,1,1,2005); $this->cal->setTimestamp($stamp); $this->assertEqual(2004, $this->cal->thisYear()); $stamp = mktime(0,0,0,12,31,2004); $this->cal->setTimestamp($stamp); $this->assertEqual(2004, $this->cal->thisYear()); $stamp = mktime(0,0,0,1,1,2005); $this->cal->setTimestamp($stamp); $this->assertEqual(2004, $this->cal->thisYear()); $stamp = mktime(0,0,0,12,31,2005); $this->cal->setTimestamp($stamp); $this->assertEqual(2005, $this->cal->thisYear()); $stamp = mktime(0,0,0,1,1,2006); $this->cal->setTimestamp($stamp); $this->assertEqual(2005, $this->cal->thisYear()); $stamp = mktime(0,0,0,12,31,2006); $this->cal->setTimestamp($stamp); $this->assertEqual(2006, $this->cal->thisYear()); } function testPrevDay () { $this->assertEqual(8, $this->cal->prevDay()); } function testPrevDay_Array () { $this->assertEqual( array( 'year' => 2003, 'month' => 10, 'day' => 8, 'hour' => 0, 'minute' => 0, 'second' => 0), $this->cal->prevDay('array')); } function testThisDay () { $this->assertEqual(9, $this->cal->thisDay()); } function testNextDay () { $this->assertEqual(10, $this->cal->nextDay()); } function testPrevHour () { $this->assertEqual(23, $this->cal->prevHour()); } function testThisHour () { $this->assertEqual(0, $this->cal->thisHour()); } function testNextHour () { $this->assertEqual(1, $this->cal->nextHour()); } function testPrevMinute () { $this->assertEqual(59, $this->cal->prevMinute()); } function testThisMinute () { $this->assertEqual(0, $this->cal->thisMinute()); } function testNextMinute () { $this->assertEqual(1, $this->cal->nextMinute()); } function testPrevSecond () { $this->assertEqual(59, $this->cal->prevSecond()); } function testThisSecond () { $this->assertEqual(0, $this->cal->thisSecond()); } function testNextSecond () { $this->assertEqual(1, $this->cal->nextSecond()); } function testGetTimeStamp() { $stamp = mktime(0,0,0,10,9,2003); $this->assertEqual($stamp,$this->cal->getTimeStamp()); } function testNewTimeStamp() { $stamp = mktime(0,0,0,7,28,2004); $this->cal->setTimestamp($stamp); $this->assertEqual('30 2004', date('W Y', $this->cal->prevWeek(true))); $this->assertEqual('31 2004', date('W Y', $this->cal->thisWeek(true))); $this->assertEqual('32 2004', date('W Y', $this->cal->nextWeek(true))); } function testPrevWeekInMonth() { $this->assertEqual(1, $this->cal->prevWeek()); $stamp = mktime(0,0,0,2,3,2005); $this->cal->setTimestamp($stamp); $this->assertEqual(0, $this->cal->prevWeek()); } function testThisWeekInMonth() { $this->assertEqual(2, $this->cal->thisWeek()); $stamp = mktime(0,0,0,2,3,2005); $this->cal->setTimestamp($stamp); $this->assertEqual(1, $this->cal->thisWeek()); $stamp = mktime(0,0,0,1,1,2005); $this->cal->setTimestamp($stamp); $this->assertEqual(1, $this->cal->thisWeek()); $stamp = mktime(0,0,0,1,3,2005); $this->cal->setTimestamp($stamp); $this->assertEqual(2, $this->cal->thisWeek()); } function testNextWeekInMonth() { $this->assertEqual(3, $this->cal->nextWeek()); $stamp = mktime(0,0,0,2,3,2005); $this->cal->setTimestamp($stamp); $this->assertEqual(2, $this->cal->nextWeek()); } function testPrevWeekInYear() { $this->assertEqual(date('W', $this->cal->prevWeek('timestamp')), $this->cal->prevWeek('n_in_year')); $stamp = mktime(0,0,0,1,1,2004); $this->cal->setTimestamp($stamp); $this->assertEqual(date('W', $this->cal->nextWeek('timestamp')), $this->cal->nextWeek('n_in_year')); } function testThisWeekInYear() { $this->assertEqual(date('W', $this->cal->thisWeek('timestamp')), $this->cal->thisWeek('n_in_year')); $stamp = mktime(0,0,0,1,1,2004); $this->cal->setTimestamp($stamp); $this->assertEqual(date('W', $this->cal->thisWeek('timestamp')), $this->cal->thisWeek('n_in_year')); } function testFirstWeekInYear() { $stamp = mktime(0,0,0,1,4,2004); $this->cal->setTimestamp($stamp); $this->assertEqual(1, $this->cal->thisWeek('n_in_year')); } function testNextWeekInYear() { $this->assertEqual(date('W', $this->cal->nextWeek('timestamp')), $this->cal->nextWeek('n_in_year')); } function testPrevWeekArray() { $testArray = array( 'year'=>2003, 'month'=>9, 'day'=>29, 'hour'=>0, 'minute'=>0, 'second'=>0 ); $this->assertEqual($testArray, $this->cal->prevWeek('array')); } function testThisWeekArray() { $testArray = array( 'year'=>2003, 'month'=>10, 'day'=>6, 'hour'=>0, 'minute'=>0, 'second'=>0 ); $this->assertEqual($testArray, $this->cal->thisWeek('array')); } function testNextWeekArray() { $testArray = array( 'year'=>2003, 'month'=>10, 'day'=>13, 'hour'=>0, 'minute'=>0, 'second'=>0 ); $this->assertEqual($testArray, $this->cal->nextWeek('array')); } function testPrevWeekObject() { $testWeek = Calendar_Factory::create('Week', 2003, 9, 29); //week starts on monday $Week = $this->cal->prevWeek('object'); $this->assertEqual($testWeek->getTimeStamp(), $Week->getTimeStamp()); } function testThisWeekObject() { $testWeek = Calendar_Factory::create('Week', 2003, 10, 6); //week starts on monday $Week = $this->cal->thisWeek('object'); $this->assertEqual($testWeek->getTimeStamp(), $Week->getTimeStamp()); } function testNextWeekObject() { $testWeek = Calendar_Factory::create('Week', 2003, 10, 13); //week starts on monday $Week = $this->cal->nextWeek('object'); $this->assertEqual($testWeek->getTimeStamp(), $Week->getTimeStamp()); } } class TestOfWeekBuild extends TestOfWeek { function TestOfWeekBuild() { $this->UnitTestCase('Test of Week::build()'); } function testSize() { $this->cal->build(); $this->assertEqual(7, $this->cal->size()); } function testFetch() { $this->cal->build(); $i=0; while ($Child = $this->cal->fetch()) { $i++; } $this->assertEqual(7, $i); } function testFetchAll() { $this->cal->build(); $children = array(); $i = 1; while ( $Child = $this->cal->fetch() ) { $children[$i]=$Child; $i++; } $this->assertEqual($children,$this->cal->fetchAll()); } function testSelection() { require_once(CALENDAR_ROOT . 'Day.php'); $selection = array(Calendar_Factory::create('Day', 2003, 10, 7)); $this->cal->build($selection); $i = 1; while ($Child = $this->cal->fetch()) { if ($i == 2) { break; //07-10-2003 is the 2nd day of the week (starting on monday) } $i++; } $this->assertTrue($Child->isSelected()); } function testSelectionCornerCase() { require_once(CALENDAR_ROOT . 'Day.php'); $selectedDays = array( Calendar_Factory::create('Day', 2003, 12, 29), Calendar_Factory::create('Day', 2003, 12, 30), Calendar_Factory::create('Day', 2003, 12, 31), Calendar_Factory::create('Day', 2004, 01, 01), Calendar_Factory::create('Day', 2004, 01, 02), Calendar_Factory::create('Day', 2004, 01, 03), Calendar_Factory::create('Day', 2004, 01, 04) ); $this->cal = Calendar_Factory::create('Week', 2003, 12, 31, 0); $this->cal->build($selectedDays); while ($Day = $this->cal->fetch()) { $this->assertTrue($Day->isSelected()); } $this->cal = Calendar_Factory::create('Week', 2004, 1, 1, 0); $this->cal->build($selectedDays); while ($Day = $this->cal->fetch()) { $this->assertTrue($Day->isSelected()); } } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfWeek(); $test->run(new HtmlReporter()); $test = &new TestOfWeekBuild(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/Calendar-0.5.5/tests/year_test.php000066400000000000000000000102571212436242500221130ustar00rootroot00000000000000UnitTestCase('Test of Year'); } function setUp() { $this->cal = new Calendar_Year(2003); } function testPrevYear_Object() { $this->assertEqual(new Calendar_Year(2002), $this->cal->prevYear('object')); } function testThisYear_Object() { $this->assertEqual(new Calendar_Year(2003), $this->cal->thisYear('object')); } function testPrevMonth () { $this->assertEqual(12,$this->cal->prevMonth()); } function testPrevMonth_Array () { $this->assertEqual( array( 'year' => 2002, 'month' => 12, 'day' => 1, 'hour' => 0, 'minute' => 0, 'second' => 0), $this->cal->prevMonth('array')); } function testThisMonth () { $this->assertEqual(1,$this->cal->thisMonth()); } function testNextMonth () { $this->assertEqual(2,$this->cal->nextMonth()); } function testPrevDay () { $this->assertEqual(31,$this->cal->prevDay()); } function testPrevDay_Array () { $this->assertEqual( array( 'year' => 2002, 'month' => 12, 'day' => 31, 'hour' => 0, 'minute' => 0, 'second' => 0), $this->cal->prevDay('array')); } function testThisDay () { $this->assertEqual(1,$this->cal->thisDay()); } function testNextDay () { $this->assertEqual(2,$this->cal->nextDay()); } function testPrevHour () { $this->assertEqual(23,$this->cal->prevHour()); } function testThisHour () { $this->assertEqual(0,$this->cal->thisHour()); } function testNextHour () { $this->assertEqual(1,$this->cal->nextHour()); } function testPrevMinute () { $this->assertEqual(59,$this->cal->prevMinute()); } function testThisMinute () { $this->assertEqual(0,$this->cal->thisMinute()); } function testNextMinute () { $this->assertEqual(1,$this->cal->nextMinute()); } function testPrevSecond () { $this->assertEqual(59,$this->cal->prevSecond()); } function testThisSecond () { $this->assertEqual(0,$this->cal->thisSecond()); } function testNextSecond () { $this->assertEqual(1,$this->cal->nextSecond()); } function testGetTimeStamp() { $stamp = mktime(0,0,0,1,1,2003); $this->assertEqual($stamp,$this->cal->getTimeStamp()); } } class TestOfYearBuild extends TestOfYear { function TestOfYearBuild() { $this->UnitTestCase('Test of Year::build()'); } function testSize() { $this->cal->build(); $this->assertEqual(12,$this->cal->size()); } function testFetch() { $this->cal->build(); $i=0; while ( $Child = $this->cal->fetch() ) { $i++; } $this->assertEqual(12,$i); } function testFetchAll() { $this->cal->build(); $children = array(); $i = 1; while ( $Child = $this->cal->fetch() ) { $children[$i]=$Child; $i++; } $this->assertEqual($children,$this->cal->fetchAll()); } function testSelection() { require_once(CALENDAR_ROOT . 'Month.php'); $selection = array(new Calendar_Month(2003,10)); $this->cal->build($selection); $i = 1; while ( $Child = $this->cal->fetch() ) { if ( $i == 10 ) break; $i++; } $this->assertTrue($Child->isSelected()); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfYear(); $test->run(new HtmlReporter()); $test = &new TestOfYearBuild(); $test->run(new HtmlReporter()); } ?>php-calendar-0.5.5/package.xml000066400000000000000000000470071212436242500162050ustar00rootroot00000000000000 Calendar pear.php.net A package for building Calendar data structures (irrespective of output) Calendar provides an API for building Calendar data structures. Using the simple iterator and it's "query" API, a user interface can easily be built on top of the calendar data structure, at the same time easily connecting it to some kind of underlying data store, where "event" information is being held. It provides different calculation "engines" the default being based on Unix timestamps (offering fastest performance) with an alternative using PEAR::Date which extends the calendar past the limitations of Unix timestamps. Other engines should be implementable for other types of calendar (e.g. a Chinese Calendar based on lunar cycles). Harry Fuecks hfuecks hfuecks@phppatterns.com yes Lorenzo Alberton quipo l.alberton@quipo.it yes Greg Beaver cellog greg@chiaraquartet.net yes 2010-06-24 0.5.5 0.5.5 beta beta PHP * fixed bug #17182: fixed Calendar_Month_Weeks' empty day handling (bug introduced in v.0.5.4) * PHP5 fixes 5.0.0 1.5.0 Date pear.php.net 0.5.4 0.5.4 beta beta 2008-12-12 PHP * fixed return by reference NOTICE in Decorator * fixed bug #8758: fixed Calendar_Week::thisYear() according the ISO-8601 standard * fixed bug #12542: Calendar_Util_Textual::orderedWeekdays() doesn't consider $firstDay * added new tests and fixed test to consider the CALENDAR_FIRST_DAY_OF_WEEK constant * fixed getWeekNInYear() in the PearDate engine with new Date package * request #2642: added Calendar::isToday() method * switched to package.xml v.2 * updated header comment blocks according to the Coding Standards 0.5.3 0.5.3 beta beta 2005-10-22 PHP * fixed bug #3073, Calendar_Month_Weekdays: invalid empty days at year change * fixed bug #3445, thisWeek('n_in_month') off by one in some cases * use CALENDAR_FIRST_DAY_OF_WEEK constant throughout the package * fixed return by reference NOTICEs * added new tests 0.5.2 0.5.2 beta beta 2004-08-03 PHP * Small refactoring in the date engines to significantly reduce the number of date() calls * make url default separator xhtml compliant (& => &amp;) * fix bug #1798 with week selection * fix bug #1995: thisWeek, prevWeek, nextWeek were not affected when a new timestamp was set (thanks to johnschaefer at gmx dot de) * fix bug in return value from Calendar_Week::thisWeek and n_in_month * getMinYears() returned 1970 on all platforms (thanks to Andy Crain) * added some new examples * Moved logic from Calendar_Decorator_Uri and Calendar_Decorator_Textual to Calendar_Util_Uri and Calendar_Util_Textual (BC preserved) - offers better performance, reducing number of decorators required * extended engine interface for week related methods to meet rare use cases with (not yet implemented) calendar engines 0.5.1 0.5.1 beta beta 2004-05-25 PHP * Fixed bug in Calendar_Week::setSelection(): the "selected" property was set, but not the decorated object. * Fixed bug in Calendar_Month_[Weekdays|Weeks]: the number of empty days at the beginning of the month could be wrong when the adjust() method was called to fix an invalid date. 0.5 0.5 beta beta 2004-01-29 PHP * Added new return-value-formats for each [prev|this|next]*() method Allowed formats are: 'int', 'timestamp' , 'array' and 'object'. Returns data of specified type e.g. $Day = $Hour->prevDay('object'); * Added factory for creating calendar objects (in conjunction with above change) * Added decorator to determine the day of the week for any calendar object * Minor bug fix in Decorator 0.4 0.4 beta beta 2003-11-22 PHP * Fixed bug in setTimeStamp where year wasn't set * Fixed bugs and changed API for Calendar_Week * Added Calendar::adjust method to adjust invalid dates * Added Calendar_Decorator_Uri to help with building links * Added Calendar_Decorator_Textual to help fetching month and weekday names * Added Calendar_Decorator_Wrapper to help apply decorators to built calendar objects 0.3 0.3 beta beta 2003-10-30 PHP * Fixed bugs in Calendar_Validator for day and month ranges * Fixed bug with first day of week as 0 * Modified weeks to extend beyond current month with prevWeek() and nextWeek() * More unit tests 0.2 0.2 beta beta 2003-10-28 PHP First release