/** * Build the internal arrays that contain data about holidays. * * @access protected * @return boolean true on success, otherwise a PEAR_ErrorStack object * @throws object PEAR_ErrorStack */ function _buildHolidays() { parent::_buildHolidays(); /* * Labour Day. */ $labourDay = Date_Calc::nWeekdayOfMonth(1, 1, 3, $this->_year); $this->_addHoliday('labourDay', $labourDay, "Labour Day"); /* * Foundation Day (Queen's Birthday in other states). * See http://en.wikipedia.org/wiki/Queen%27s_Official_Birthday#Australia */ $foundationDay = Date_Calc::nWeekdayOfMonth(1, 1, 6, $this->_year); $this->_addHoliday('foundationDay', $foundationDay, "Foundation Day"); /* * The Queen's Birthday. There is no firm rule to determine this date before * it is proclaimed, but it is usually the last Monday of September or the * first Monday of October, to fit in with school terms and the Perth Royal * Show. Here we assume that whichever of the two is closest to the start of * Octber will be the holiday; this has been verified to be correct up to and * including 2013, but dates beyond then should be verified once they've been * proclaimed (and something added here to account for historical and future * irregularities). */ $y = $this->_year; $lastMonSept = new Date(Date_Calc::nWeekdayOfMonth('last', 1, 9, $y)); $firstMonOct = new Date(Date_Calc::nWeekdayOfMonth(1, 1, 10, $y)); $daysToEnd = 30 - $lastMonSept->getDay(); $daysToStart = $firstMonOct->getDay(); if ($daysToEnd < $daysToStart) { $queensBirthday = $lastMonSept; } else { $queensBirthday = $firstMonOct; } $this->_addHoliday('queensBirthday', $queensBirthday, "Queen's Birthday"); }
/** * 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!) * * @access public * @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 */ function isHoliday($date, $filter = null) { if (!is_a($date, 'Date')) { $date = $this->_convertDate($date); if (Date_Holidays::isError($date)) { return $date; } } //rebuild internal array of holidays if required. $compare_year = $date->getYear(); $this_year = $this->getYear(); if ($this_year !== $compare_year) { $this->setYear($compare_year); } if (is_null($filter)) { $filter = new Date_Holidays_Filter_Blacklist(array()); } elseif (is_array($filter)) { $filter = new Date_Holidays_Filter_Whitelist($filter); } foreach (array_keys($this->_dates) as $internalName) { if ($filter->accept($internalName)) { if (Date_Holidays_Driver::dateSloppyCompare($date, $this->_dates[$internalName]) != 0) { continue; } $this->setYear($this_year); return true; } } $this->setYear($this_year); return false; }
/** * Build the internal arrays that contain data about holidays. * * @access protected * @return boolean true on success, otherwise a PEAR_ErrorStack object * @throws object PEAR_ErrorStack */ function _buildHolidays() { parent::_buildHolidays(); /** * Method that returns the date of the nearest Monday to the specified date * * @return Monday date closest to specified date * */ /** * New Year's Day and Day after New Year's Day * always observed on a working day (1..5) * always show New Year's Day regardless of day of week */ $newYearsDay = new Date($this->_year . '-01-01'); $dayAfterNewYearsDay = new Date($this->_year . '-01-02'); $this->_addHoliday('newYearsDay', $newYearsDay, 'New Year\'s Day'); if ($newYearsDay->getDayOfWeek() == 0) { $this->_addHoliday('dayAfterNewYearsDay', $this->_year . '-01-02', 'Day after New Year\'s Day'); $this->_addHoliday('newYearsDayHoliday', $this->_year . '-01-03', 'New Year\'s Holiday'); } elseif ($newYearsDay->getDayOfWeek() == 5) { $this->_addHoliday('dayAfterNewYearsDay', $this->_year . '-01-04', 'New Year\'s Holiday'); } elseif ($newYearsDay->getDayOfWeek() == 6) { $this->_addHoliday('newYearsDayHoliday', $this->_year . '-01-03', 'New Year\'s Holiday'); $this->_addHoliday('dayAfterNewYearsDay', $this->_year . '-01-04', 'New Year\'s Holiday'); } else { $this->_addHoliday('dayAfterNewYearsDay', $dayAfterNewYearsDay, 'Day after New Year\'s Day'); } /** * Waitangi Day * always observed on 6 February */ $waitangiDay = new Date($this->_year . '-02-06'); $this->_addHoliday('waitangiDay', $waitangiDay, 'Waitangi Day'); /** * Easter */ $easter = Date_Holidays_Driver_Christian::calcEaster($this->_year); $goodFridayDate = new Date($easter); $goodFridayDate = $this->_addDays($easter, -2); $this->_addHoliday('goodFriday', $goodFridayDate, 'Good Friday'); $this->_addHoliday('easterMonday', $easter->getNextDay(), 'Easter Monday'); /** * Anzac Day * always observed on 25 April * differs from Australia in that there is no working day lost if Anzac Day falls on a weekend */ $anzacDay = new Date($this->_year . '-04-25'); $this->_addHoliday('anzacDay', $anzacDay, 'Anzac Day'); /** * The Queen's Birthday. * always observed on 1st Monday in June */ $queensBirthday = Date_Calc::NWeekdayOfMonth(1, 1, 6, $this->_year); $this->_addHoliday('queensBirthday', $queensBirthday, "Queen\\'s Birthday"); /** * Labour Day. * observed as 4th Monday in October */ $labourDay = Date_Calc::NWeekdayOfMonth(4, 1, 10, $this->_year); $this->_addHoliday('labourDay', $labourDay, "Labour Day"); /** * Christmas and Boxing days * always observed on a working day (1..5) * always show Christmas and Boxing days */ $christmasDay = new Date($this->_year . '-12-25'); $boxingDay = new Date($this->_year . '-12-26'); $this->_addHoliday('christmasDay', $christmasDay, 'Christmas Day'); $this->_addHoliday('boxingDay', $boxingDay, 'Boxing Day'); if ($christmasDay->getDayOfWeek() == 0) { $this->_addHoliday('christmasDayHoliday', $this->_year . '-12-27', 'Christmas Day Holiday'); } elseif ($christmasDay->getDayOfWeek() == 5) { $this->_addHoliday('boxingDayHoliday', $this->_year . '-12-28', 'Boxing Day Holiday'); } elseif ($christmasDay->getDayOfWeek() == 6) { $this->_addHoliday('christmasDayHoliday', $this->_year . '-12-27', 'Christmas Day Holiday'); $this->_addHoliday('boxingDayHoliday', $this->_year . '-12-28', 'Boxing Day Holiday'); } /** * Regional anniversary calculations * http://www.dol.govt.nz/er/holidaysandleave/publicholidays/publicholidaydates/current.asp * ordered by date of observation * Note - where rule may be modified by proximity of Easter, this is NOT taken into account * * Each of 8 regions can use common rule of nearest Monday * Southland 17 Jan * Wellington 22 Jan * Auckland 29 Jan * Nelson 1 Feb * Otago 23 Mar (some local variation) * Marlborough 1 Nov * Chatam Islands 30 Nov * Westland 1 Dec (some local variation) */ $anniversaryDaySd = new Date($this->_year . '-01-17'); $this->_addHoliday('anniversaryDaySd', Date_Holidays_Driver_NewZealand::nearestMonday($anniversaryDaySd), "Southland Anniversary Day"); $anniversaryDayWn = new Date($this->_year . '-01-22'); $this->_addHoliday('anniversaryDayWn', Date_Holidays_Driver_NewZealand::nearestMonday($anniversaryDayWn), "Wellington Anniversary Day"); $anniversaryDayAk = new Date($this->_year . '-01-29'); $this->_addHoliday('anniversaryDayAk', Date_Holidays_Driver_NewZealand::nearestMonday($anniversaryDayAk), "Auckland Anniversary Day"); $anniversaryDayNn = new Date($this->_year . '-02-01'); $this->_addHoliday('anniversaryDayNn', Date_Holidays_Driver_NewZealand::nearestMonday($anniversaryDayNn), "Nelson Anniversary Day"); $anniversaryDayOo = new Date($this->_year . '-03-23'); $this->_addHoliday('anniversaryDayOo', Date_Holidays_Driver_NewZealand::nearestMonday($anniversaryDayOo), "Otago Anniversary Day"); $anniversaryDayMb = new Date($this->_year . '-11-01'); $this->_addHoliday('anniversaryDayMb', Date_Holidays_Driver_NewZealand::nearestMonday($anniversaryDayMb), "Marlborough Anniversary Day"); $anniversaryDayCi = new Date($this->_year . '-11-30'); $this->_addHoliday('anniversaryDayCi', Date_Holidays_Driver_NewZealand::nearestMonday($anniversaryDayCi), "Chatam Islands Anniversary Day"); $anniversaryDayWd = new Date($this->_year . '-12-01'); $this->_addHoliday('anniversaryDayWd', Date_Holidays_Driver_NewZealand::nearestMonday($anniversaryDayWd), "Westland Anniversary Day"); /** * Taranaki Anniversary. * 2nd Monday in March. */ $anniversaryDayTk = Date_Calc::nWeekdayOfMonth(2, 1, 3, $this->_year); $this->_addHoliday('anniversaryDayTk', $anniversaryDayTk, "Taranaki Anniversary Day"); /** * South Canterbury Anniversary. * 4th Monday in September. */ $anniversaryDaySc = Date_Calc::nWeekdayOfMonth(4, 1, 9, $this->_year); $this->_addHoliday('anniversaryDaySc', $anniversaryDaySc, "South Canterbury Anniversary Day"); /** * Hawkes' Bay Anniversary. * Friday before Labour Day (or 3rd Friday in October). * */ $anniversaryDayHb = Date_Calc::nWeekdayOfMonth(3, 5, 10, $this->_year); $this->_addHoliday('anniversaryDayHb', $anniversaryDayHb, "Hawkes\\' Bay Anniversary"); /** * Canterbury Anniversary or Show Day for North and Central Canterbury. * 2nd Friday after 1st Tuesday in month of November. * find 1st Tuesday then add 10 days */ $anniversaryDayNc = $this->_calcNthWeekDayInMonth(1, 2, 11); $anniversaryDayNc = $this->_addDays($anniversaryDayNc, 10); $this->_addHoliday('anniversaryDayNc', $anniversaryDayNc, "Canterbury Anniversary Day"); /** * Check for errors, and return. */ if (Date_Holidays::errorsOccurred()) { return Date_Holidays::getErrorStack(); } return true; }
/** * Determines whether a date represents a holiday or not * * @access public * @param mixed $date date (can be 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, DATE_HOLIDAYS_INVALID_DATE_FORMAT */ function isHoliday($date, $filter = null) { if (!is_a($date, 'Date')) { $date = $this->_convertDate($date); if (Date_Holidays::isError($date)) { return $date; } } if (is_null($filter)) { $filter = new Date_Holidays_Filter_Blacklist(array()); } elseif (is_array($filter)) { $filter = new Date_Holidays_Filter_Whitelist($filter); } foreach (array_keys($this->_dates) as $internalName) { if ($filter->accept($internalName)) { if (Date_Holidays_Driver::dateSloppyCompare($date, $this->_dates[$internalName]) != 0) { continue; } return true; } } return false; }
/** * Add a compiled language-file's content * * The language-file's content will be unserialized and translations, * properties, etc. for holidays will be made available with the * specified locale. * * @param string $file filename of the compiled language file * @param string $locale locale-code of the translation * * @access public * @return boolean true on success, otherwise a PEAR_ErrorStack object * @throws object PEAR_Errorstack */ function addCompiledTranslationFile($file, $locale) { $result = parent::addCompiledTranslationFile($file, $locale); if (PEAR::isError($result)) { return $result; } $this->_translationFile = $file; $this->_translationLocale = $locale; return $result; }
/** * Build the internal arrays that contain data about holidays. * * @access protected * @return boolean true on success, otherwise a PEAR_ErrorStack object * @throws object PEAR_ErrorStack */ function _buildHolidays() { parent::_buildHolidays(); /* * New Year's Day */ $newYearsDay = new Date($this->_year . '-01-01'); if ($newYearsDay->getDayOfWeek() == 0) { // 0 = Sunday $newYearsDay = $this->_year . '-01-02'; } elseif ($newYearsDay->getDayOfWeek() == 6) { // 6 = Saturday $newYearsDay = $this->_year . '-01-03'; } $this->_addHoliday('newYearsDay', $newYearsDay, 'New Year\'s Day'); /* * Australia Day */ $australiaDay = new Date($this->_year . '-01-26'); if ($australiaDay->getDayOfWeek() == 0) { // 0 = Sunday $australiaDay = $this->_year . '-01-27'; } elseif ($australiaDay->getDayOfWeek() == 6) { // 6 = Saturday $australiaDay = $this->_year . '-01-28'; } $this->_addHoliday('australiaDay', $australiaDay, 'Australia Day'); /* * Easter */ $easter = Date_Holidays_Driver_Christian::calcEaster($this->_year); $goodFridayDate = new Date($easter); $goodFridayDate = $this->_addDays($easter, -2); $this->_addHoliday('goodFriday', $goodFridayDate, 'Good Friday'); $this->_addHoliday('easterMonday', $easter->getNextDay(), 'Easter Monday'); /* * Anzac Day */ $anzacDay = new Date($this->_year . '-04-25'); $this->_addHoliday('anzacDay', $anzacDay, 'Anzac Day'); if ($anzacDay->getDayOfWeek() == 0) { // 0 = Sunday $anzacDayHol = $this->_year . '-04-26'; $this->_addHoliday('anzacDayHoliday', $anzacDayHol, 'Anzac Day Holiday'); } elseif ($anzacDay->getDayOfWeek() == 6) { // 6 = Saturday $anzacDayHol = $this->_year . '-04-27'; $this->_addHoliday('anzacDayHoliday', $anzacDayHol, 'Anzac Day Holiday'); } /* * The Queen's Birthday. * See http://en.wikipedia.org/wiki/Queen%27s_Official_Birthday#Australia */ $queensBirthday = Date_Calc::nWeekdayOfMonth(1, 1, 6, $this->_year); $this->_addHoliday('queensBirthday', $queensBirthday, "Queen's Birthday"); /* * Christmas and Boxing days */ $christmasDay = new Date($this->_year . '-12-25'); $boxingDay = new Date($this->_year . '-12-26'); $this->_addHoliday('christmasDay', $christmasDay, 'Christmas Day'); $this->_addHoliday('boxingDay', $boxingDay, 'Boxing Day'); if ($christmasDay->getDayName() == 'Sunday') { $this->_addHoliday('boxingDayHoliday', $this->_year . '-12-27', 'Boxing Day Holiday'); } elseif ($christmasDay->getDayName() == 'Friday') { $this->_addHoliday('boxingDayHoliday', $this->_year . '-12-28', 'Boxing Day Holiday'); } elseif ($christmasDay->getDayName() == 'Saturday') { $this->_addHoliday('christmasDayHoliday', $this->_year . '-12-27', 'Christmas Day Holiday'); $this->_addHoliday('boxingDayHoliday', $this->_year . '-12-28', 'Boxing Day Holiday'); } /* * Check for errors, and return. */ if (Date_Holidays::errorsOccurred()) { return Date_Holidays::getErrorStack(); } return true; }