Source for file Driver.php
Documentation is available at Driver.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
* Copyright (c) 1997-2008 The PHP Group
* This source file is subject to version 2.0 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/2_02.txt.
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license@php.net so we can mail you a copy immediately.
* Authors: Carsten Lucke <luckec@tool-garage.de>
* CVS file id: $Id: Driver.php,v 1.31 2008/03/17 11:13:36 kguest Exp $
* @author Carsten Lucke <luckec@tool-garage.de>
* @license http://www.php.net/license/3_01.txt PHP License 3.0.1
* @version CVS: $Id: Driver.php,v 1.31 2008/03/17 11:13:36 kguest Exp $
* @link http://pear.php.net/package/Date_Holidays
* DriverClass and associated defines.
* @author Carsten Lucke <luckec@tool-garage.de>
* @license http://www.php.net/license/3_01.txt PHP License 3.0.1
* @version CVS: $Id: Driver.php,v 1.31 2008/03/17 11:13:36 kguest Exp $
* @link http://pear.php.net/package/Date_Holidays
require_once 'PEAR/ErrorStack.php';
require_once 'Date/Holidays/Filter.php';
require_once 'Date/Holidays/Filter/Whitelist.php';
require_once 'Date/Holidays/Filter/Blacklist.php';
define('DATE_HOLIDAYS_INVALID_INTERNAL_NAME', 51 );
* title for a holiday is not available
define('DATE_HOLIDAYS_TITLE_UNAVAILABLE', 52 );
* date could not be converted into a PEAR::Date object
* date was neither a timestamp nor a string
* @deprecated will certainly be removed
define('DATE_HOLIDAYS_INVALID_DATE', 53 );
* string that represents a date has wrong format
* format must be YYYY-MM-DD
* @deprecated will certainly be removed
define('DATE_HOLIDAYS_INVALID_DATE_FORMAT', 54 );
* date for a holiday is not available
define('DATE_HOLIDAYS_DATE_UNAVAILABLE', 55 );
* language-file doesn't exist
define('DATE_HOLIDAYS_LANGUAGEFILE_NOT_FOUND', 56 );
* unable to read language-file
define('DATE_HOLIDAYS_UNABLE_TO_READ_TRANSLATIONDATA', 57 );
* Name of the static {@link Date_Holidays_Driver} method returning
* a array of possible ISO3166 codes that identify itself.
define('DATE_HOLIDAYS_DRIVER_IDENTIFY_ISO3166_METHOD', 'getISO3166Codes');
* class that helps you to locate holidays for a year
* @author Carsten Lucke <luckec@tool-garage.de>
* @license http://www.php.net/license/3_01.txt PHP License 3.0.1
* @version CVS: $Id: Driver.php,v 1.31 2008/03/17 11:13:36 kguest Exp $
* @link http://pear.php.net/package/Date_Holidays
* locale setting for output
* locales for which translations of holiday titles are available
var $_availableLocales = array ('C');
* internal names for the available holidays
* dates of the available holidays
* array of the available holidays indexed by date
* localized names of the available holidays
* Array of holiday-properties indexed by internal-names and
* furthermore by locales.
* $_holidayProperties = array(
* 'internalName1' => array(
* 'internalName2' => array(
var $_holidayProperties = array ();
* Use the Date_Holidays::factory() method to construct an object of a
* Method that returns an array containing the ISO3166 codes that may possibly
* @return array possible ISO3166 codes
* Sets the driver's current year
* Calling this method forces the object to rebuild the holidays
* @return boolean true on success, otherwise a PEAR_ErrorStack object
* @throws object PEAR_ErrorStack
* Returns the driver's current year
* @return int current year
* Build the internal arrays that contain data about the calculated holidays
* @return boolean true on success, otherwise a PEAR_ErrorStack object
* @throws object PEAR_ErrorStack
* @param object $driver Date_Holidays_Driver object
* Remove a driver component
* @param object $driver Date_Holidays_Driver driver-object
* @return boolean true on success, otherwise a PEAR_Error object
* @throws object PEAR_Error DATE_HOLIDAYS_DRIVER_NOT_FOUND
* Returns the internal names of holidays that were calculated
* Returns localized titles of all holidays or those accepted by the filter
* @param Date_Holidays_Filter $filter filter-object (or an array !DEPRECATED!)
* @param string $locale locale setting that shall be used
* @return array $filter array with localized holiday titles on success,
* otherwise a PEAR_Error object
* @throws object PEAR_Error DATE_HOLIDAYS_INVALID_INTERNAL_NAME
* @uses getHolidayTitle()
if ($filter->accept ($internalName)) {
$titles[$internalName] = $title;
* Returns localized title for a holiday
* @param string $internalName internal name for holiday
* @param string $locale locale setting to be used by this method
* @return string title on success, otherwise a PEAR_Error object
* @throws object PEAR_Error DATE_HOLIDAYS_INVALID_INTERNAL_NAME
* @throws object PEAR_Error DATE_HOLIDAYS_TITLE_UNAVAILABLE
$msg = 'Invalid internal name: ' . $internalName;
if (! isset ($this->_titles[$locale][$internalName])) {
$msg = 'The internal name (' . $internalName . ') ' .
'for the holiday was correct but no ' .
'localized title could be found';
if (isset ($this->_titles[$locale][$internalName])) {
return $this->_titles[$locale][$internalName];
return $this->_titles['C'][$internalName];
* Returns the localized properties of a holiday. If no properties have
* been stored an empty array will be returned.
* @param string $internalName internal name for holiday
* @param string $locale locale setting that shall be used by this method
* @return array array of properties on success, otherwise
* @throws object PEAR_Error DATE_HOLIDAYS_INVALID_INTERNAL_NAME
$msg = 'Invalid internal name: ' . $internalName;
if (isset ($this->_holidayProperties[$internalName][$locale])) {
$properties = $this->_holidayProperties[$internalName][$locale];
* Returns all holidays that the driver knows.
* You can limit the holidays by passing a filter, then only those
* holidays accepted by the filter will be returned.
* 'easter' => object of type Date_Holidays_Holiday,
* 'eastermonday' => object of type Date_Holidays_Holiday,
* @param Date_Holidays_Filter $filter filter-object
* (or an array !DEPRECATED!)
* @param string $locale locale setting that shall be used
* @return array numeric array containing objects of
* Date_Holidays_Holiday on success, otherwise a
* @throws object PEAR_Error DATE_HOLIDAYS_INVALID_INTERNAL_NAME
if ($filter->accept ($internalName)) {
// no need to check for valid internal-name, will be
$holidays[$internalName] = $this->getHoliday($internalName,
* Returns the specified holiday
* 'title' => 'Easter Sunday'
* @param string $internalName internal name of the holiday
* @param string $locale locale setting that shall be used
* @return object Date_Holidays_Holiday holiday's information on
* success, otherwise a PEAR_Error
* @throws object PEAR_Error DATE_HOLIDAYS_INVALID_INTERNAL_NAME
* @uses getHolidayTitle()
function getHoliday($internalName, $locale = null )
'Invalid internal name: ' . $internalName);
* Determines whether a date represents a holiday or not
* @param mixed $date a timestamp, string or PEAR::Date object
* @param Date_Holidays_Filter $filter filter-object (or an array !DEPRECATED!)
* @return boolean true if date represents a holiday, otherwise false
* @throws object PEAR_Error DATE_HOLIDAYS_INVALID_DATE_FORMAT
* @throws object PEAR_Error DATE_HOLIDAYS_INVALID_DATE
if (! is_a($date, 'Date')) {
$date = $this->_convertDate ($date);
//rebuild internal array of holidays if required.
$compare_year = $date->getYear ();
if ($this_year !== $compare_year) {
if ($filter->accept ($internalName)) {
$this->_dates[$internalName]) != 0 ) {
* Returns a <code>Date_Holidays_Holiday</code> object, if any was found,
* matching the specified date.
* Normally the method will return the object of the first holiday matching
* the date. If you want the method to continue searching holidays for the
* specified date, set the 4th param to true.
* If multiple holidays match your date, the return value will be an array
* containing a number of <code>Date_Holidays_Holiday</code> items.
* @param mixed $date date (timestamp | string | PEAR::Date object)
* @param string $locale locale setting that shall be used by this method
* @param boolean $multiple if true, continue searching holidays for
* @return object object of type Date_Holidays_Holiday on success
* (numeric array of those on multiple search),
* if no holiday was found, matching this date,
* @throws object PEAR_Error DATE_HOLIDAYS_INVALID_DATE_FORMAT
* @throws object PEAR_Error DATE_HOLIDAYS_INVALID_DATE
* @uses getHolidayTitle()
if (!is_a($date, 'Date')) {
$date = $this->_convertDate ($date);
//get only the first feast for this day
$internalName = $this->_holidays[$isodate][0 ];
$result = $this->getHoliday($internalName, $locale);
// array that collects data, if multiple searching is done
foreach ($this->_holidays[$isodate] as $internalName) {
$result = $this->getHoliday($internalName, $locale);
|