/** * Calculate Nth day of the week in a month * * @param int $position position * @param int $weekday day of the week starting from 1 == sunday * @param int $month month * * @access private * @return object Date date */ function _calcNthWeekDayInMonth($position, $weekday, $month) { if ($position == 1) { $startday = '01'; } elseif ($position == 2) { $startday = '08'; } elseif ($position == 3) { $startday = '15'; } elseif ($position == 4) { $startday = '22'; } elseif ($position == 5) { $startday = '29'; } $month = sprintf("%02d", $month); $date = new Date($this->_year . '-' . $month . '-' . $startday); while ($date->getDayOfWeek() != $weekday) { $date = $date->getNextDay(); } return $date; }
function get_weekly_volume_graph() { global $wpdb; global $userdata; get_currentuserinfo(); $beg_date = new Date(); $end_date = new Date(); $wk = array(0, 0, 0, 0); $label = array(0, 0, 0, 0); $filename = array("filename" => "/var/www/vanhlebarsoftware/wp-content/plugins/fitnesslog/graphs/wklygraph.png"); // Get current weeks and prior three weeks volume numbers. $day_of_wk = $beg_date->getDayOfWeek(); $beg_date->addDays(-($day_of_wk - 1)); $end_date->copy($beg_date); $end_date->addDays(6); for ($i = 0; $i < 4; $i++) { $query = "SELECT user_id, SUM(seconds) AS seconds FROM " . $wpdb->prefix . "flmain WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userdata->ID . " GROUP BY user_id"; $result = $wpdb->get_results($query, ARRAY_A); if ($result) { foreach ($result as $row) { $wk[$i] = convert_seconds_minutes($row["seconds"]); } } else { $wk[$i] = 0; } // Add any strength training that we have done to the total. $query = "SELECT user_id, SUM(seconds) AS seconds FROM " . $wpdb->prefix . "flstrength WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userdata->ID . " GROUP BY user_id"; $result = $wpdb->get_results($query, ARRAY_A); if ($result) { foreach ($result as $row) { $wk[$i] = $wk[$i] + convert_seconds_minutes($row["seconds"]); } } // Create the labels. $label[$i] = $end_date->format("%m/%d"); // Move the dates back by one week. $beg_date->addDays(-7); $end_date->addDays(-7); } //Setup the graph. $Graph =& Image_Graph::factory('graph', array(175, 175), true); $Plotarea =& $Graph->addNew('plotarea'); $Dataset =& Image_Graph::factory('dataset'); $Dataset->addPoint($label[3], $wk[3]); $Dataset->addPoint($label[2], $wk[2]); $Dataset->addPoint($label[1], $wk[1]); $Dataset->addPoint($label[0], $wk[0]); $Plot =& $Plotarea->addNew('bar', &$Dataset); $Plot->setFillColor('green'); $YAxis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y); $YAxis->setTitle('Minutes', 'vertical'); $XAxis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X); // $XAxis->setFontAngle( "vertical" ); $XAxis->setTitle("Week", array('angle' => 0)); //Output the finished graph to the graphs directory. $result = $Graph->done($filename); if ($result) { var_dump("error creating graph!"); } }
/** * Build the internal arrays that contain data about the calculated holidays * * @access protected * @return boolean true on success, otherwise a PEAR_ErrorStack object * @throws object PEAR_ErrorStack */ function _buildHolidays() { /** * World's leprosy day */ $this->_addHoliday('leprosyDay', $this->_year . '-01-28', 'World\'s leprosy day'); /** * International day of the native tongue */ $this->_addHoliday('nativeTongueDay', $this->_year . '-02-21', 'International Day of the native tongue'); /** * International Women's Day */ $this->_addHoliday('womensDay', $this->_year . '-03-08', 'International Women\'s Day'); /** * International World Consumers' Day */ $this->_addHoliday('worldConsumersDay', $this->_year . '-03-15', 'International World Consumers\' Day'); /** * International day of the forest */ $this->_addHoliday('intForestDay', $this->_year . '-03-21', 'International day of the forest'); /** * International day of beating racism */ $this->_addHoliday('intDayBeatingRacism', $this->_year . '-03-21', 'International day of beating racism'); /** * Day of poesy */ $this->_addHoliday('dayOfPoesy', $this->_year . '-03-21', 'Day of poesy'); /** * Day of water */ $this->_addHoliday('dayOfWater', $this->_year . '-03-22', 'Day of water'); /** * World's meteorology day */ $this->_addHoliday('meteorologyDay', $this->_year . '-03-23', 'World\'s meteorology day'); /** * World's tuberculosis day */ $this->_addHoliday('tuberculosisDay', $this->_year . '-03-24', 'World\'s tuberculosis day'); /** * World's Health Day */ $this->_addHoliday('worldsHealthDay', $this->_year . '-04-07', 'World\'s Health Day'); /** * Book and Copyright's Day */ $this->_addHoliday('bookAndCopyrightDay', $this->_year . '-04-23', 'Book and Copyright\'s Day'); /** * Tree's Day */ $this->_addHoliday('treesDay', $this->_year . '-04-25', 'Tree\'s Day'); /** * World's day of intellectual property */ $this->_addHoliday('intellectualPropertyDay', $this->_year . '-04-26', 'World\'s day of intellectual property'); /** * International day of work */ $this->_addHoliday('intDayOfWork', $this->_year . '-05-01', 'International day of work'); /** * International day for freedom of the press */ $this->_addHoliday('freedomOfPressDay', $this->_year . '-05-03', 'International day for freedom of the press'); /** * Day of the sun */ $this->_addHoliday('dayOfTheSun', $this->_year . '-05-03', 'Day of the sun'); /** * International Family's Day */ $this->_addHoliday('intFamilyDay', $this->_year . '-05-15', 'International Family\'s Day'); /** * World's Telecommunications Day */ $this->_addHoliday('telecommunicationsDay', $this->_year . '-05-17', 'World\'s Telecommunications Day'); /** * International day of cultural development */ $this->_addHoliday('culturalDevelopmentDay', $this->_year . '-05-21', 'International day of cultural development'); /** * International day of biological diversity */ if ($this->_year >= 2001) { $this->_addHoliday('biologicalDiversityDay', $this->_year . '-05-22', 'International day of biological diversity'); } else { $this->_addHoliday('biologicalDiversityDay', $this->_year . '-12-29', 'International day of biological diversity'); } /** * African Liberation Day */ $this->_addHoliday('africanLiberationDay', $this->_year . '-05-25', 'African Liberation Day'); /** * International UN Peace Squads' Day */ $this->_addHoliday('unPeaceSquadsDay', $this->_year . '-05-29', 'International UN Peace Squads\' Day'); /** * World's Nonsmokers' Day */ $this->_addHoliday('nonsmokersDay', $this->_year . '-05-31', 'World\'s Nonsmokers\' Day'); /** * World's Agriculturalists' Day */ $this->_addHoliday('farmersDay', $this->_year . '-06-01', 'World\'s Agriculturalists\' Day'); /** * World's Environment Day */ $this->_addHoliday('environmentDay', $this->_year . '-06-05', 'World\'s Environment Day'); /** * African Children's Day */ $this->_addHoliday('africanChildrenDay', $this->_year . '-06-16', 'African Children\'s Day'); /** * World's Desert's Day */ $this->_addHoliday('desertDay', $this->_year . '-06-17', 'World\'s Desert\'s Day'); /** * African Fugitives' Day */ $this->_addHoliday('africanFugitiveDay', $this->_year . '-06-20', 'African Fugitives\' Day'); /** * International day against drugs */ $this->_addHoliday('antiDrugsDay', $this->_year . '-06-26', 'International day against drugs'); /** * International Cooperative Societies' Day */ $coopDayDate = new Date($this->_year . '-07-01'); while ($coopDayDate->getDayOfWeek() != 6) { $coopDayDate = $coopDayDate->getNextDay(); } $this->_addHoliday('intCoopDay', $coopDayDate, 'International Cooperative Societies\' Day'); /** * World's Population Day */ $this->_addHoliday('populationDay', $this->_year . '-07-11', 'World\'s Population Day'); /** * International day of indigenous people */ $this->_addHoliday('indigenousPeopleDay', $this->_year . '-08-09', 'International day of indigenous people'); /** * International Youth' Day */ $this->_addHoliday('intYouthDay', $this->_year . '-08-12', 'International Youth\' Day'); /** * International day of slave trade's abolishment */ $this->_addHoliday('slaveTradeDay', $this->_year . '-08-23', 'International day of slave trade\'s abolishment'); /** * World's Alphabetization Day */ $this->_addHoliday('alphabetizationDay', $this->_year . '-09-08', 'World\'s Alphabetization Day'); /** * Ozone Layer's Protection Day */ $this->_addHoliday('ozoneLayerProtectionDay', $this->_year . '-09-16', 'Ozone Layer\'s Protection Day'); /** * International day of peace */ $peaceDayDate = new Date($this->_year . '-09-01'); while ($peaceDayDate->getDayOfWeek() != 2) { $peaceDayDate = $peaceDayDate->getNextDay(); } $peaceDayDate->addSpan(new Date_Span('14, 0, 0, 0')); $this->_addHoliday('intPeaceDay', $peaceDayDate, 'International day of peace'); /** * World's day of tourism */ $this->_addHoliday('tourismDay', $this->_year . '-09-27', 'World\'s day of tourism'); /** * International fugitives' day */ $this->_addHoliday('intFugitiveDay', $this->_year . '-09-28', 'International fugitives\' day'); /** * International aged people's day */ $this->_addHoliday('agedPeopleDay', $this->_year . '-10-01', 'International aged people\'s day'); /** * World's day for prevention of cruelty to animals */ $this->_addHoliday('animalsDay', $this->_year . '-10-04', 'World\'s day for prevention of cruelty to animals'); /** * Beginning of the International Outer Space Week */ $this->_addHoliday('outerSpaceWeek', $this->_year . '-10-04', 'Beginning of the International Outer Space Week'); /** * World's Habitat Day */ $habitatDayDate = new Date($this->_year . '-10-01'); while ($habitatDayDate->getDayOfWeek() != 1) { $habitatDayDate = $habitatDayDate->getNextDay(); } $this->_addHoliday('habitatDay', $coopDayDate, 'World\'s Habitat Day'); /** * International Teachers' Day */ $this->_addHoliday('teachersDay', $this->_year . '-10-05', 'International Teachers\' Day'); /** * World Post Association's Day */ $this->_addHoliday('postAssociationDay', $this->_year . '-10-09', 'World Post Association\'s Day'); /** * World's Sanity Day */ $this->_addHoliday('sanityDay', $this->_year . '-10-10', 'World\'s Sanity Day'); /** * World's Nourishment Day */ $this->_addHoliday('nourishmentDay', $this->_year . '-10-16', 'World\'s Nourishment Day'); /** * International day for removal of poverty */ $this->_addHoliday('povertyRemovalDay', $this->_year . '-10-17', 'International day for removal of poverty'); /** * United Nations' Day */ $this->_addHoliday('unitedNationsDay', $this->_year . '-10-24', 'United Nations\' Day'); /** * World's day of information about evolvement */ $this->_addHoliday('evolvementInfoDay', $this->_year . '-10-24', 'World\'s day of information about evolvement'); /** * Beginning of the Disarmament Week */ $this->_addHoliday('evolvementInfoDay', $this->_year . '-10-24', 'Beginning of the Disarmament Week'); /** * International day against environmental exploitation in wartime */ $this->_addHoliday('environmentalExploitationDay', $this->_year . '-11-06', 'International day against environmental exploitation in wartime'); /** * International day of tolerance */ $this->_addHoliday('toleranceDay', $this->_year . '-11-16', 'International day of tolerance'); /** * African Industrialization Day */ $this->_addHoliday('africanIndustrializationDay', $this->_year . '-11-20', 'African Industrialization Day'); /** * World's Children's Day */ $this->_addHoliday('worldChildrenDay', $this->_year . '-11-20', 'World\'s Children\'s Day'); /** * World's Television Day */ $this->_addHoliday('televisionDay', $this->_year . '-11-21', 'World\'s Television Day'); /** * International day for removal of violence against women */ $this->_addHoliday('noViolenceAgainstWomen', $this->_year . '-11-25', 'International day for removal of violence against women'); /** * International day of solidarity with Palestinian people */ $this->_addHoliday('palestinianSolidarity', $this->_year . '-11-29', 'International day of solidarity with Palestinian people'); /** * World AIDS Day */ $this->_addHoliday('worldAidsDay', $this->_year . '-12-01', 'World AIDS Day'); /** * International day for abolishment of slavery */ $this->_addHoliday('againstSlaveryDay', $this->_year . '-12-01', 'International day for abolishment of slavery'); /** * International day for disabled people */ $this->_addHoliday('disabledPeopleDay', $this->_year . '-12-03', 'International day for disabled people'); /** * International evolvement helpers' day */ $this->_addHoliday('evolvementHelperDay', $this->_year . '-12-05', 'International evolvement helpers\' day'); /** * International day of civil aeronautics */ $this->_addHoliday('civilAeronauticsDay', $this->_year . '-12-07', 'International day of civil aeronautics'); /** * International day of human rights */ $this->_addHoliday('humanRightsDay', $this->_year . '-12-10', 'International day of human rights'); /** * UNICEF Day */ $this->_addHoliday('unicefDay', $this->_year . '-12-11', 'UNICEF Day'); /** * International migrants' day */ $this->_addHoliday('migrantsDay', $this->_year . '-12-18', 'International migrants\' day'); if (Date_Holidays::errorsOccurred()) { return Date_Holidays::getErrorStack(); } return true; }
function get_weekly_volume_graph($userID, $connection) { $beg_date = new Date(); $end_date = new Date(); $wk = array(0, 0, 0, 0, 0, 0, 0); $wk_actual = array(0, 0, 0, 0, 0, 0, 0); $label = array(0, 0, 0, 0, 0, 0, 0); $filename = array("filename" => "/var/www/vanhlebarsoftware/fitlog/graphs/wklygraph.jpg"); // Get current weeks and prior three weeks volume numbers and the next three weeks. $day_of_wk = $beg_date->getDayOfWeek(); $beg_date->addDays(-($day_of_wk - 1) + 21); $end_date->copy($beg_date); $end_date->addDays(6); for ($i = 0; $i < 7; $i++) { // Get the planned volume for this particular week. $query = "SELECT SUM(seconds) AS seconds FROM flmain WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userID . " AND plan_type='p'"; $queryStr = "SELECT SUM(seconds) AS seconds FROM flstrength WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userID . " AND plan_type='p'"; $result = @mysql_query($query, $connection); $resultStr = @mysql_query($query, $connection); if ($result || $resultStr) { $tmp = 0; if ($result) { $row = mysql_fetch_array($result); $tmp = convert_seconds_minutes($row["seconds"]); } if ($resultStr) { $rowStr = mysql_fetch_array($resultStr); $tmp += convert_seconds_minutes($rowStr["seconds"]); } $wk[$i] = $tmp; } else { $wk[$i] = 0; } // Get the actual volume for this particular week. $query = "SELECT SUM(seconds) AS seconds FROM flmain WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userID . " AND plan_type='a'"; $queryStr = "SELECT SUM(seconds) AS seconds FROM flstrength WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userID . " AND plan_type='a'"; $result = @mysql_query($query, $connection); $resultStr = @mysql_query($queryStr, $connection); if ($result || $resultStr) { $tmp = 0; if ($result) { $row = mysql_fetch_array($result); $tmp = convert_seconds_minutes($row["seconds"]); } if ($resultStr) { $rowStr = mysql_fetch_array($resultStr); $tmp += convert_seconds_minutes($rowStr["seconds"]); } $wk_actual[$i] = $tmp; } else { $wk_actual[$i] = 0; } // Create the labels. $label[$i] = $end_date->format("%m/%d"); // Move the dates back by one week. $beg_date->addDays(-7); $end_date->addDays(-7); } for ($i = 0; $i < 7; $i++) { } //Setup the graph. $Graph =& Image_Graph::factory('graph', array(300, 210, TRUE)); $Graph->add(Image_Graph::factory('title', array('Weekly Volume - Actual vs. Planned'), 12)); $Plotarea =& $Graph->addNew('plotarea'); $Dataset =& Image_Graph::factory('dataset'); $Dataset1 =& Image_Graph::factory('dataset'); // Add the actual volume to the graph. $Dataset1->addPoint($label[6], $wk_actual[6]); $Dataset1->addPoint($label[5], $wk_actual[5]); $Dataset1->addPoint($label[4], $wk_actual[4]); $Dataset1->addPoint($label[3], $wk_actual[3]); $Dataset1->addPoint($label[2], $wk_actual[2]); $Dataset1->addPoint($label[1], $wk_actual[1]); $Dataset1->addPoint($label[0], $wk_actual[0]); // Add the planned volume to the graph. $Dataset->addPoint($label[6], $wk[6]); $Dataset->addPoint($label[5], $wk[5]); $Dataset->addPoint($label[4], $wk[4]); $Dataset->addPoint($label[3], $wk[3]); $Dataset->addPoint($label[2], $wk[2]); $Dataset->addPoint($label[1], $wk[1]); $Dataset->addPoint($label[0], $wk[0]); // Plot the actual data to the graph. $Plot =& $Plotarea->addNew('line', &$Dataset); $Plot1 =& $Plotarea->addNew('bar', &$Dataset1); $Plot1->setFillColor('green@.8'); // Set the axis titles. $YAxis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y); $YAxis->setTitle('Minutes', 'vertical'); $XAxis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X); $XAxis->setTitle("Week", array('angle' => 0)); //Output the finished graph to the graphs directory. $result = $Graph->done($filename); if ($result) { var_dump("error creating graph!"); } }
/** * DB_DataObject_FormBuilder::_date2array() * * Takes a string representing a date or a unix timestamp and turns it into an * array suitable for use with the QuickForm data element. * When using a string, make sure the format can be handled by the PEAR::Date constructor! * * Beware: For the date conversion to work, you must at least use the letters "d", "m" and "Y" in * your format string (see "dateElementFormat" option). If you want to enter a time as well, * you will have to use "H", "i" and "s" as well. Other letters will not work! Exception: You can * also use "M" instead of "m" if you want plain text month names. * * @param mixed $date A unix timestamp or the string representation of a date, compatible to strtotime() * @return array * @access protected */ function _date2array($date) { $da = array(); if (is_string($date)) { // Get PEAR::Date class definition, if needed include_once 'Date.php'; $dObj = new Date($date); $da['d'] = $dObj->getDay(); $da['l'] = $da['D'] = $dObj->getDayOfWeek(); $da['m'] = $da['M'] = $da['F'] = $dObj->getMonth(); $da['Y'] = $da['y'] = $dObj->getYear(); $da['H'] = $dObj->getHour(); $da['h'] = $da['H'] % 12; if ($da['h'] == 0) { $da['h'] = 12; } $da['i'] = $dObj->getMinute(); $da['s'] = $dObj->getSecond(); if ($da['H'] >= 12) { $da['a'] = 'pm'; $da['A'] = 'PM'; } else { $da['a'] = 'am'; $da['A'] = 'AM'; } unset($dObj); } else { if (is_int($date)) { $time = $date; } else { $time = time(); } $da['d'] = date('d', $time); $da['l'] = $da['D'] = date('w', $time); $da['m'] = $da['M'] = $da['F'] = date('m', $time); $da['Y'] = $da['y'] = date('Y', $time); $da['H'] = date('H', $time); $da['h'] = date('h', $time); $da['i'] = date('i', $time); $da['s'] = date('s', $time); $da['a'] = date('a', $time); $da['A'] = date('A', $time); } $this->debug('<i>_date2array():</i> from ' . $date . ' ...'); return $da; }
/** * A method to modify an array of history data so that it can be displayed in a format * compatible with the weekly breakdown template. * * @param array $aData A reference to an array of arrays, containing the rows of data. * @param object $oCaller The calling object. Expected to have the the class variable * "statsBreakdown" set. */ function prepareWeekBreakdown(&$aData, $oCaller) { // Only prepare the weekly breakdown if the statsBreakdown // in the caller is set to "week" if ($oCaller->statsBreakdown != 'week') { return; } $beginOfWeek = OA_Admin_DaySpan::getBeginOfWeek(); $aWeekData = array(); ksort($aData); foreach ($aData as $key => $aRowData) { // Get the date for this row's data $oDate = new Date($key); if ($beginOfWeek != 0) { // Need to change the date used for the data so // that the day appears in the correct week $daysToGoback = (int) (SECONDS_PER_DAY * $beginOfWeek); $oDate->subtractSeconds($daysToGoback); } // Get the week this date is in, in YYYY-MM format $week = sprintf('%04d-%02d', $oDate->getYear(), $oDate->getWeekOfYear()); // Prepare the data array for this week, if not set, where // the week is in the "week" index, there is a "data" index // for all the rows that make up the week, and the array // has all the columns of an empty data row if (!isset($aWeekData[$week])) { $aWeekData[$week] = $oCaller->aEmptyRow; $aWeekData[$week]['week'] = $week; $aWeekData[$week]['data'] = array(); } // Add the data from the row to the totals of the week foreach (array_keys($oCaller->aColumns) as $colKey) { $aWeekData[$week][$colKey] += $aRowData[$colKey]; } // Store the row in the week $aWeekData[$week]['data'][$key] = $aRowData; } foreach (array_keys($aWeekData) as $week) { // Now that the totals are complete, fill any // remaining days in the week with empty data $days = count($aWeekData[$week]['data']); if ($days < 7) { // Locate the first day of the week in the days that make // up the week so far ksort($aWeekData[$week]['data']); $key = key($aWeekData[$week]['data']); $oDate = new Date($key); $firstDataDayOfWeek = $oDate->getDayOfWeek(); // Is this after the start of the week? if ($firstDataDayOfWeek > $beginOfWeek) { // Change the date to be the first day of this week $daysToGoback = (int) (SECONDS_PER_DAY * ($firstDataDayOfWeek - $beginOfWeek)); $oDate->subtractSeconds($daysToGoback); } // Check each day in the week for ($counter = 0; $counter < 7; $counter++) { if (is_null($aWeekData[$week]['data'][$oDate->format('%Y-%m-%d')])) { // Set the day's data to the empty row, plus the "day" heading for the day $aWeekData[$week]['data'][$oDate->format('%Y-%m-%d')] = $oCaller->aEmptyRow; $aWeekData[$week]['data'][$oDate->format('%Y-%m-%d')]['day'] = $oDate->format($GLOBALS['date_format']); } elseif (!is_null($aWeekData[$week]['data'][$oDate->format('%Y-%m-%d')]) && !array_key_exists('day', $aWeekData[$week]['data'][$oDate->format('%Y-%m-%d')])) { $aWeekData[$week]['data'][$oDate->format('%Y-%m-%d')]['day'] = $oDate->format($GLOBALS['date_format']); } $oDate->addSeconds(SECONDS_PER_DAY); } } // Ensure the day data is sorted correctly ksort($aWeekData[$week]['data']); // Format all day rows foreach (array_keys($aWeekData[$week]['data']) as $key) { $oCaller->_formatStatsRowRecursive($aWeekData[$week]['data'][$key]); } // Calculate CTR and other columns, making sure that the method is available if (is_callable(array($oCaller, '_summarizeStats'))) { $oCaller->_summarizeStats($aWeekData[$week]); } } // Set the new weekly-formatted data as the new data array to use $aData = $aWeekData; }
/** * Build the internal arrays that contain data about the calculated holidays * * @access protected * @return boolean true on success, otherwise a PEAR_ErrorStack object * @throws object PEAR_ErrorStack */ function _buildHolidays() { parent::_buildHolidays(); $easterDate = $this->getHolidayDate('easter'); $ashWednesdayDate = $this->getHolidayDate('ashWednesday'); $ascensionDayDate = $this->getHolidayDate('ascensionDay'); $advent1Date = $this->getHolidayDate('advent1'); /** * New Year's Day */ $this->_addHoliday('newYearsDay', $this->_year . '-01-01', 'New Year\'s Day'); /** * Valentine's Day */ $this->_addHoliday('valentinesDay', $this->_year . '-02-14', 'Valentine\'s Day'); /** * "Weiberfastnacht" */ $wFasnetDate = $this->_addDays($ashWednesdayDate, -6); $this->_addHoliday('womenFasnet', $wFasnetDate, 'Carnival'); /** * Carnival / "Fastnacht" */ $fasnetDate = $this->_addDays($easterDate, -47); $this->_addHoliday('fasnet', $fasnetDate, 'Carnival'); /** * Rose Monday */ $roseMondayDate = $this->_addDays($easterDate, -48); $this->_addHoliday('roseMonday', $roseMondayDate, 'Rose Monday'); /** * International Women's Day */ $this->_addHoliday('womensDay', $this->_year . '-03-08', 'International Women\'s Day'); /** * April 1st */ $this->_addHoliday('april1st', $this->_year . '-04-01', 'April 1st'); /** * Girls' Day (fourth Thursday in April) */ $girlsDayDate = new Date($this->_year . '-04-01'); $dayOfWeek = $girlsDayDate->getDayOfWeek(); switch ($dayOfWeek) { case 0: case 1: case 2: case 3: $girlsDayDate = $this->_addDays($girlsDayDate, 4 - $dayOfWeek + 21); break; case 4: $girlsDayDate = $this->_addDays($girlsDayDate, 21); break; case 5: case 6: $girlsDayDate = $this->_addDays($girlsDayDate, -1 * $dayOfWeek + 11 + 21); break; } $this->_addHoliday('girlsDay', $girlsDayDate, 'Girls\' Day'); /** * International Earth' Day */ $this->_addHoliday('earthDay', $this->_year . '-04-22', 'International Earth\' Day'); /** * German Beer's Day */ $this->_addHoliday('beersDay', $this->_year . '-04-23', 'German Beer\'s Day'); /** * Walpurgis Night */ $this->_addHoliday('walpurgisNight', $this->_year . '-04-30', 'Walpurgis Night'); /** * Day of Work */ $this->_addHoliday('dayOfWork', $this->_year . '-05-01', 'Day of Work'); /** * World's Laughing Day */ $laughingDayDate = new Date($this->_year . '-05-01'); while ($laughingDayDate->getDayOfWeek() != 0) { $laughingDayDate = $laughingDayDate->getNextDay(); } $this->_addHoliday('laughingDay', $laughingDayDate, 'World\'s Laughing Day'); /** * Europe Day */ $this->_addHoliday('europeDay', $this->_year . '-05-05', 'Europe Day'); /** * Mothers' Day */ $mothersDay = $this->_addDays($laughingDayDate, 7); $this->_addHoliday('mothersDay', $mothersDay, 'Mothers\' Day'); /** * End of World War 2 in Germany */ $this->_addHoliday('endOfWWar2', $this->_year . '-05-08', 'End of World War 2 in Germany'); /** * Fathers' Day */ $this->_addHoliday('fathersDay', $ascensionDayDate, 'Fathers\' Day'); /** * Amnesty International Day */ $this->_addHoliday('aiDay', $this->_year . '-05-28', 'Amnesty International Day'); /** * International Children' Day */ $this->_addHoliday('intChildrenDay', $this->_year . '-06-01', 'International Children\'s Day'); /** * Day of organ donation */ $organDonationDate = new Date($this->_year . '-06-01'); while ($organDonationDate->getDayOfWeek() != 6) { $organDonationDate = $organDonationDate->getNextDay(); } $this->_addHoliday('organDonationDay', $organDonationDate, 'Day of organ donation'); /** * Dormouse' Day */ $this->_addHoliday('dormouseDay', $this->_year . '-06-27', 'Dormouse\' Day'); /** * Christopher Street Day */ $this->_addHoliday('christopherStreetDay', $this->_year . '-06-27', 'Christopher Street Day'); /** * Hiroshima Commemoration Day */ $this->_addHoliday('hiroshimaCommemorationDay', $this->_year . '-08-06', 'Hiroshima Commemoration Day'); /** * Augsburg peace celebration */ $this->_addHoliday('augsburgPeaceCelebration', $this->_year . '-08-08', 'Augsburg peace celebration'); /** * International left-handeds' Day */ $this->_addHoliday('leftHandedDay', $this->_year . '-08-13', 'International left-handeds\' Day'); /** * Anti-War Day */ $this->_addHoliday('antiWarDay', $this->_year . '-09-01', 'Anti-War Day'); /** * Day of German Language */ $germanLangDayDate = new Date($this->_year . '-09-01'); while ($germanLangDayDate->getDayOfWeek() != 6) { $germanLangDayDate = $germanLangDayDate->getNextDay(); } $germanLangDayDate = $this->_addDays($germanLangDayDate, 7); $this->_addHoliday('germanLanguageDay', $germanLangDayDate, 'Day of German Language'); /** * International diabetes day */ $this->_addHoliday('diabetesDay', $this->_year . '-11-14', 'International diabetes day'); /** * German Unification Day */ $this->_addHoliday('germanUnificationDay', $this->_year . '-10-03', 'German Unification Day'); /** * Libraries' Day */ $this->_addHoliday('librariesDay', $this->_year . '-10-24', 'Libraries\' Day'); /** * World's Savings Day */ $this->_addHoliday('savingsDay', $this->_year . '-10-30', 'World\'s Savings Day'); /** * Halloween */ $this->_addHoliday('halloween', $this->_year . '-10-31', 'Halloween'); /** * Stamp's Day * * year <= 1948: 7th of January * year > 1948: last Sunday in October */ $stampsDayDate = null; if ($this->_year <= 1948) { $stampsDayDate = new Date($this->_year . '-01-07'); while ($stampsDayDate->getDayOfWeek() != 0) { $stampsDayDate = $stampsDayDate->getNextDay(); } } else { $stampsDayDate = new Date($this->_year . '-10-31'); while ($stampsDayDate->getDayOfWeek() != 0) { $stampsDayDate = $stampsDayDate->getPrevDay(); } } $this->_addHoliday('stampsDay', $stampsDayDate, 'Stamp\'s Day'); /** * International Men's Day */ $this->_addHoliday('mensDay', $this->_year . '-11-03', 'International Men\'s Day'); /** * Fall of the Wall of Berlin */ $this->_addHoliday('wallOfBerlin', $this->_year . '-11-09', 'Fall of the Wall of Berlin 1989'); /** * Beginning of the Carnival */ $this->_addHoliday('carnivalBeginning', $this->_year . '-11-11', 'Beginning of the Carnival'); /** * People's Day of Mourning */ $dayOfMourning = $this->_addDays($advent1Date, -14); $this->_addHoliday('dayOfMourning', $dayOfMourning, 'People\'s Day of Mourning'); if (Date_Holidays::errorsOccurred()) { return Date_Holidays::getErrorStack(); } return true; }
/** * DB_DataObject_FormBuilder::_date2array() * * Takes a string representing a date or a unix timestamp and turns it into an * array suitable for use with the QuickForm data element. * When using a string, make sure the format can be handled by the PEAR::Date constructor! * * Beware: For the date conversion to work, you must at least use the letters "d", "m" and "Y" in * your format string (see "dateElementFormat" option). If you want to enter a time as well, * you will have to use "H", "i" and "s" as well. Other letters will not work! Exception: You can * also use "M" instead of "m" if you want plain text month names. * * @param mixed $date A unix timestamp or the string representation of a date, compatible to strtotime() * @return array * @access protected */ function _date2array($date) { $da = array(); if (is_string($date)) { if (preg_match('/^\\d+:\\d+(:\\d+|)(\\s+[ap]m|)$/i', $date)) { $date = date('Y-m-d ') . $date; $getDate = false; } else { $getDate = true; } include_once 'Date.php'; $dObj = new Date($date); if ($getDate) { $da['d'] = $dObj->getDay(); $da['l'] = $da['D'] = $dObj->getDayOfWeek(); $da['m'] = $da['M'] = $da['F'] = $dObj->getMonth(); $da['Y'] = $da['y'] = $dObj->getYear(); } $da['H'] = $dObj->getHour(); $da['h'] = $da['H'] % 12; if ($da['h'] == 0) { $da['h'] = 12; } $da['g'] = $da['h']; $da['i'] = $dObj->getMinute(); $da['s'] = $dObj->getSecond(); if ($da['H'] >= 12) { $da['a'] = 'pm'; $da['A'] = 'PM'; } else { $da['a'] = 'am'; $da['A'] = 'AM'; } unset($dObj); } else { if (is_int($date)) { $time = $date; } else { $time = time(); } $da['d'] = date('d', $time); $da['l'] = $da['D'] = date('w', $time); $da['m'] = $da['M'] = $da['F'] = date('m', $time); $da['Y'] = $da['y'] = date('Y', $time); $da['H'] = date('H', $time); $da['g'] = date('g', $time); $da['h'] = date('h', $time); $da['i'] = date('i', $time); $da['s'] = date('s', $time); $da['a'] = date('a', $time); $da['A'] = date('A', $time); } DB_DataObject_FormBuilder::debug('<i>_date2array():</i> from ' . $date . ' to ' . serialize($da) . ' ...'); return $da; }
/** * Build the internal arrays that contain data about the calculated holidays * * @access protected * @return boolean true on success, otherwise a PEAR_ErrorStack object * @throws object PEAR_ErrorStack */ function _buildHolidays() { /** * New Year's Day */ $newYearsDay = new Date($this->_year . '-01-01'); if ($newYearsDay->getDayOfWeek() == 0) { $this->_addHoliday('newYearsDay', $this->_year . '-01-02', 'Substitute Bank Holiday in lieu of New Year\'s Day'); } elseif ($newYearsDay->getDayOfWeek() == 6) { $this->_addHoliday('newYearsDay', $this->_year . '-01-03', 'Substitute Bank Holiday in lieu of New Year\'s Day'); } else { $this->_addHoliday('newYearsDay', $newYearsDay, 'New Year\'s Day'); } /** * Easter Sunday */ $easterDate = Date_Holidays_Driver_Christian::calcEaster($this->_year); /** * Good Friday */ $goodFridayDate = new Date($easterDate); $goodFridayDate = $this->_addDays($easterDate, -2); $this->_addHoliday('goodFriday', $goodFridayDate, 'Good Friday'); /** * Easter Monday */ $this->_addHoliday('easterMonday', $easterDate->getNextDay(), 'Easter Monday'); /** * May Day Bank Holiday */ $earlyMayDate = Date_Holidays_Driver_USA::_calcNthMondayInMonth(5, 1); $this->_addHoliday('mayDay', $earlyMayDate, 'May Day Bank Holiday'); /** * Spring Bank Holiday */ $springBankDate = Date_Holidays_Driver_USA::_calcLastMondayInMonth(5); $this->_addHoliday('springBank', $springBankDate, 'Spring Bank Holiday'); /** * Summer Bank Holiday */ $summerBankDate = Date_Holidays_Driver_USA::_calcLastMondayInMonth(8); $this->_addHoliday('summerBank', $summerBankDate, 'Summer Bank Holiday'); /** * Christmas and Boxing Day */ $christmasDay = new Date($this->_year . '-12-25'); if ($christmasDay->getDayOfWeek() == 0) { $this->_addHoliday('boxingDay', $this->_year . '-12-26', 'Boxing Day'); $this->_addHoliday('christmasDay', $this->_year . '-12-27', 'Substitute Bank Holiday in lieu of Christmas Day'); } elseif ($christmasDay->getDayOfWeek() == 5) { $this->_addHoliday('christmasDay', $christmasDay, 'Christmas Day'); $this->_addHoliday('boxingDay', $this->_year . '-12-28', 'Substitute Bank Holiday in lieu of Boxing Day'); } elseif ($christmasDay->getDayOfWeek() == 6) { $this->_addHoliday('christmasDay', $this->_year . '-12-28', 'Substitute Bank Holiday in lieu of Christmas Day'); $this->_addHoliday('boxingDay', $this->_year . '-12-27', 'Substitute Bank Holiday in lieu of Boxing Day'); } else { $this->_addHoliday('christmasDay', $christmasDay, 'Christmas Day'); $this->_addHoliday('boxingDay', $this->_year . '-12-26', 'Boxing Day'); } if (Date_Holidays::errorsOccurred()) { return Date_Holidays::getErrorStack(); } return true; }
/** * Calculate nearest workday for a certain day * * @access private * @param int $month month * @param int $day day * @return object Date date */ function _calcNearestWorkDay($month, $day) { $month = sprintf("%02d", $month); $day = sprintf("%02d", $day); $date = new Date($this->_year . '-' . $month . '-' . $day); // When one of these holidays falls on a Saturday, the previous day is also a holiday // When New Year's Day, Independence Day, or Christmas Day falls on a Sunday, the next day is also a holiday. if ($date->getDayOfWeek() == 0) { // bump it up one $date = $date->getNextDay(); } if ($date->getDayOfWeek() == 6) { // push it back one $date = $date->getPrevDay(); } return $date; }
/** * Calculate nearest workday for a certain day * * @param int $month month * @param int $day day * * @access private * @return object Date date */ function _calcNearestWorkDay($month, $day) { $month = sprintf("%02d", $month); $day = sprintf("%02d", $day); $date = new Date($this->_year . '-' . $month . '-' . $day); // When a public holiday falls on a // Sunday, the next day is also a holiday. if ($date->getDayOfWeek() == 0) { // bump it up one $date = $date->getNextDay(); } return $date; }
/** * Build the internal arrays that contain data about the calculated holidays * * @access protected * @return boolean true on success, otherwise a PEAR_ErrorStack object * @throws object PEAR_ErrorStack */ function _buildHolidays() { /** * Circumcision of Jesus */ $this->_addHoliday('jesusCircumcision', $this->_year . '-01-01', 'Circumcision of Jesus'); /** * Epiphanias */ $this->_addHoliday('epiphany', $this->_year . '-01-06', 'Epiphany'); /** * Cleaning of Mariä */ $this->_addHoliday('mariaCleaning', $this->_year . '-02-02', 'Cleaning of Maria'); /** * Josef's Day */ $this->_addHoliday('josefsDay', $this->_year . '-03-19', 'Josef\'s Day'); /** * Maria Announcement */ $this->_addHoliday('mariaAnnouncement', $this->_year . '-03-25', 'Maria Announcement'); /** * Easter Sunday */ $easterDate = Date_Holidays_Driver_Christian::calcEaster($this->_year); $this->_addHoliday('easter', $easterDate, 'Easter Sunday'); /** * Palm Sunday */ $palmSundayDate = new Date($easterDate); $palmSundayDate->subtractSpan(new Date_Span('7, 0, 0, 0')); $this->_addHoliday('palmSunday', $palmSundayDate, 'Palm Sunday'); /** * Passion Sunday */ $passionSundayDate = new Date($palmSundayDate); $passionSundayDate->subtractSpan(new Date_Span('7, 0, 0, 0')); $this->_addHoliday('passionSunday', $passionSundayDate, 'Passion Sunday'); /** * Painful Friday */ $painfulFridayDate = new Date($palmSundayDate); $painfulFridayDate->subtractSpan(new Date_Span('2, 0, 0, 0')); $this->_addHoliday('painfulFriday', $painfulFridayDate, 'Painful Friday'); /** * White Sunday */ $whiteSundayDate = new Date($easterDate); $whiteSundayDate->addSpan(new Date_Span('7, 0, 0, 0')); $this->_addHoliday('whiteSunday', $whiteSundayDate, 'White Sunday'); /** * Ash Wednesday */ $ashWednesdayDate = new Date($easterDate); $ashWednesdayDate->subtractSpan(new Date_Span('46, 0, 0, 0')); $this->_addHoliday('ashWednesday', $ashWednesdayDate, 'Ash Wednesday'); /** * Good Friday / Black Friday */ $goodFridayDate = new Date($easterDate); $goodFridayDate->subtractSpan(new Date_Span('2, 0, 0, 0')); $this->_addHoliday('goodFriday', $goodFridayDate, 'Good Friday'); /** * Green Thursday */ $this->_addHoliday('greenThursday', $goodFridayDate->getPrevDay(), 'Green Thursday'); /** * Easter Monday */ $this->_addHoliday('easterMonday', $easterDate->getNextDay(), 'Easter Monday'); /** * Whitsun (determines Whit Monday, Ascension Day and Feast of Corpus Christi) */ $whitsunDate = new Date($easterDate); $whitsunDate->addSpan(new Date_Span('49, 0, 0, 0')); $this->_addHoliday('whitsun', $whitsunDate, 'Whitsun'); /** * Request Sunday */ $requestSunday = new Date($whitsunDate); $requestSunday->subtractSpan(new Date_Span('14, 0, 0, 0')); $this->_addHoliday('requestSunday', $requestSunday, 'Request Sunday'); /** * Ascension Day */ $ascensionDayDate = new Date($whitsunDate); $ascensionDayDate->subtractSpan(new Date_Span('10, 0, 0, 0')); $this->_addHoliday('ascensionDay', $ascensionDayDate, 'Ascension Day'); /** * Whit Monday */ $this->_addHoliday('whitMonday', $whitsunDate->getNextDay(), 'Whit Monday'); /** * Haunting of Mariä */ $this->_addHoliday('mariaHaunting', $this->_year . '-05-31', 'Haunting of Maria'); /** * Trinitatis */ $trinitatisDate = new Date($whitsunDate); $trinitatisDate->addSpan(new Date_Span('7, 0, 0, 0')); $this->_addHoliday('trinitatis', $trinitatisDate, 'Trinitatis'); /** * Feast of Corpus Christi */ $corpusChristiDate = new Date($whitsunDate); $corpusChristiDate->addSpan(new Date_Span('11, 0, 0, 0')); $this->_addHoliday('corpusChristi', $corpusChristiDate, 'Feast of Corpus Christi'); /** * Heart of Jesus * * Friday of the 3rd week past Whitsun */ $heartJesusDate = new Date($whitsunDate); $heartJesusDate->addSpan(new Date_Span('19, 0, 0, 0')); $this->_addHoliday('heartJesus', $heartJesusDate, 'Heart of Jesus celebration'); /** * Johannis celebration */ $this->_addHoliday('johannisCelebration', $this->_year . '-06-24', 'Johannis celebration'); /** * Petrus and Paulus */ $this->_addHoliday('petrusAndPaulus', $this->_year . '-06-29', 'Petrus and Paulus'); /** * Ascension of Maria */ $this->_addHoliday('mariaAscension', $this->_year . '-08-15', 'Ascension of Maria'); /** * Celebration of raising the Cross */ $this->_addHoliday('crossRaising', $this->_year . '-09-14', 'Celebration of raising the Cross'); /** * Thanks Giving * * Sunday past Michaelis (29. September) */ $michaelisDate = new Date($this->_year . '-09-29'); $dayOfWeek = $michaelisDate->getDayOfWeek(); $michaelisDate->addSpan(new Date_Span(sprintf('%d, 0, 0, 0', 7 - $dayOfWeek))); $thanksGivingDate = $michaelisDate; $this->_addHoliday('thanksGiving', $thanksGivingDate, 'Thanks Giving'); /** * Kermis * * 3rd Sunday in October */ $kermisDate = new Date($this->_year . '-10-01'); $dayOfWeek = $kermisDate->getDayOfWeek(); if ($dayOfWeek != 0) { $kermisDate->addSpan(new Date_Span(sprintf('%d, 0, 0, 0', 7 - $dayOfWeek))); } $kermisDate->addSpan(new Date_Span('14, 0, 0, 0')); $this->_addHoliday('kermis', $kermisDate, 'Kermis'); /** * Reformation Day */ $this->_addHoliday('reformationDay', $this->_year . '-10-31', 'Reformation Day'); /** * All Saints' Day */ $this->_addHoliday('allSaintsDay', $this->_year . '-11-01', 'All Saints\' Day'); /** * All Souls' Day */ $this->_addHoliday('allSoulsDay', $this->_year . '-11-02', 'All Souls\' Day'); /** * Martin's Day */ $this->_addHoliday('martinsDay', $this->_year . '-11-11', 'Martin\'s Day'); /** * 4th Advent */ $Advent4Date = new Date($this->_year . '-12-24'); $dayOfWeek = $Advent4Date->getDayOfWeek(); if ($dayOfWeek == 0) { $dayOfWeek = 7; } $Advent4Date->subtractSpan(new Date_Span(sprintf('%d, 0, 0, 0', $dayOfWeek))); $this->_addHoliday('advent4', $Advent4Date, '4th Advent'); /** * 1st Advent */ $Advent1Date = new Date($Advent4Date); $Advent1Date->subtractSpan(new Date_Span('21, 0, 0, 0')); $this->_addHoliday('advent1', $Advent1Date, '1st Advent'); /** * 2nd Advent */ $Advent2Date = new Date($Advent4Date); $Advent2Date->subtractSpan(new Date_Span('14, 0, 0, 0')); $this->_addHoliday('advent2', $Advent2Date, '2nd Advent'); /** * 3rd Advent */ $Advent3Date = new Date($Advent4Date); $Advent3Date->subtractSpan(new Date_Span('7, 0, 0, 0')); $this->_addHoliday('advent3', $Advent3Date, '3rd Advent'); /** * Death' Sunday */ $deathSundayDate = new Date($Advent1Date); $deathSundayDate->subtractSpan(new Date_Span('7, 0, 0, 0')); $this->_addHoliday('deathSunday', $deathSundayDate, 'Death\' Sunday'); /** * Day of Repentance */ $dayOfRepentance = new Date($deathSundayDate); $dayOfRepentance->subtractSpan(new Date_Span('4, 0, 0, 0')); $this->_addHoliday('dayOfRepentance', $dayOfRepentance, 'Day of Repentance'); /** * St. Nicholas' Day */ $this->_addHoliday('stNicholasDay', $this->_year . '-12-06', 'St. Nicholas\' Day'); /** * Maria' conception */ $this->_addHoliday('mariaConception', $this->_year . '-12-08', 'Conception of Maria'); /** * Christmas Eve */ $this->_addHoliday('xmasEve', $this->_year . '-12-24', 'Christmas Eve'); /** * Christmas day */ $this->_addHoliday('xmasDay', $this->_year . '-12-25', 'Christmas Day'); /** * Boxing day */ $this->_addHoliday('boxingDay', $this->_year . '-12-26', 'Boxing Day'); /** * New Year's Eve */ $this->_addHoliday('newYearsEve', $this->_year . '-12-31', 'New Year\'s Eve'); if (Date_Holidays::errorsOccurred()) { return Date_Holidays::getErrorStack(); } return true; }
/** * Build the internal arrays that contain data about the calculated holidays * * @access protected * @return boolean true on success, otherwise a PEAR_ErrorStack object * @throws object PEAR_ErrorStack */ function _buildHolidays() { $easterDate = Date_Holidays_Driver_Iceland::calcEaster($this->_year); /** * New Year's Day */ $this->_addHoliday('newYearsDay', $this->_year . '-01-01', 'New Year\'s Day'); $this->_addTranslationForHoliday('newYearsDay', 'is_IS', 'Nýársdagur'); /** * Epiphany */ $this->_addHoliday('epiphany', $this->_year . '-01-06', 'Epiphany'); $this->_addTranslationForHoliday('epiphany', 'is_IS', 'Þrettándinn'); /** * Husband's Day * From http://www.isholf.is/gullis/jo/feasts_and_celebrations.htm * Þorri is one of the old Icelandic months. It always begins on * a Friday, between the 19th and the 25th of January, and ends on * a Saturday between the 18th and 24th of February. The first day * of Þorri is called Bóndadagur or "Husband's Day/Farmer's Day" */ $hdate = new Date($this->_year . "-01-19"); while ($hdate->getDayOfWeek() != 5) { $hdate = $hdate->getNextDay(); } $this->_addHoliday('husbandsDay', $hdate, 'Husband\'s Day'); $this->_addTranslationForHoliday('husbandsDay', 'is_IS', 'Bóndadagur'); /** * Woman's Day * Calculate Sunday in the 18th week of winter, ie between Feb 18-24. */ $wdate = new Date($this->_year . "-02-18"); while ($wdate->getDayOfWeek() != 0) { $wdate = $wdate->getNextDay(); } $this->_addHoliday('womansDay', $wdate, 'Woman\'s Day'); $this->_addTranslationForHoliday('womansDay', 'is_IS', 'Konudagur'); $shroveMondayDate = $this->_addDays($easterDate, -41); $this->_addHoliday('shroveMonday', $shroveMondayDate, 'Shrove Monday'); $this->_addTranslationForHoliday('shroveMonday', 'is_IS', 'Bolludagur'); $shroveTuesdayDate = $this->_addDays($easterDate, -40); $this->_addHoliday('shroveTuesday', $shroveTuesdayDate, 'Shrove Tuesday'); $this->_addTranslationForHoliday('shroveTuesday', 'is_IS', 'Sprengidagur'); $ashWednesdayDate = $this->_addDays($easterDate, -39); $this->_addHoliday('ashWednesday', $ashWednesdayDate, 'Ash Wednesday'); $this->_addTranslationForHoliday('ashWednesday', 'is_IS', 'Öskudagur'); /** * Palm Sunday */ $palmSundayDate = $this->_addDays($easterDate, -7); $this->_addHoliday('palmSunday', $palmSundayDate, 'Palm Sunday'); $this->_addTranslationForHoliday('palmSunday', 'is_IS', 'Pálmasunnudagur'); /** * Maundy Thursday */ $maundyThursdayDate = $this->_addDays($easterDate, -3); $this->_addHoliday('maundyThursday', $maundyThursdayDate, 'Maundy Thursday'); $this->_addTranslationForHoliday('maundyThursday', 'is_IS', 'Skírdagur'); /** * Good Friday / Black Friday */ $goodFridayDate = $this->_addDays($easterDate, -2); $this->_addHoliday('goodFriday', $goodFridayDate, 'Good Friday'); $this->_addTranslationForHoliday('goodFriday', 'is_IS', 'Föstudaginn langi'); /** * Easter Day */ $this->_addHoliday('easter', $easterDate, 'Easter Day'); $this->_addTranslationForHoliday('easter', 'is_IS', 'Páskadagur'); /** * Easter Monday */ $this->_addHoliday('easterMonday', $easterDate->getNextDay(), 'Easter Monday'); $this->_addTranslationForHoliday('easterMonday', 'is_IS', 'Annar í páskum'); /** * First Day of Summer * First Thursday after 18 April */ $juneDate = new Date($this->_year . '-04-18'); $dayOfWeek = $juneDate->getDayOfWeek(); $midSummerDate = $this->_addDays($juneDate, 4 - $dayOfWeek); $this->_addHoliday('firstDayOfSummer', $midSummerDate, 'First Day of Summer'); $this->_addTranslationForHoliday('firstDayOfSummer', 'is_IS', 'Sumardagurinn fyrsti'); $mayDay = new Date($this->_year . '-05-01'); $this->_addHoliday('mayDay', $mayDay, 'May Day'); $this->_addTranslationForHoliday('mayDay', 'is_IS', 'Verkalýðsdagurinn'); $mothersDay = new Date($this->_year . '-05-13'); $this->_addHoliday('mothersDay', $mothersDay, 'Mothers\' Day'); $this->_addTranslationForHoliday('mothersDay', 'is_IS', 'Mæðradagurinn'); $whitsunDate = $this->_addDays($easterDate, 49); $this->_addHoliday('whitsun', $whitsunDate, 'White Sunday'); $this->_addTranslationForHoliday('whitsun', 'is_IS', 'Hvítasunnudagur'); /** * Whit Monday */ $this->_addHoliday('whitMonday', $whitsunDate->getNextDay(), 'White Monday'); $this->_addTranslationForHoliday('whitMonday', 'is_IS', 'Annar í hvítasunnu'); $ascensionDayDate = $this->_addDays($whitsunDate, -10); $this->_addHoliday('ascensionDay', $ascensionDayDate, 'Ascension Day'); $this->_addTranslationForHoliday('ascensionDay', 'is_IS', 'Uppstigningardagur'); $this->_addHoliday('seamansDay', $this->_year . '-06-03', 'The Seamen\'s Day'); $this->_addTranslationForHoliday('seamansDay', 'is_IS', 'Sjómannadagurinn'); $this->_addHoliday('nationalDay', $this->_year . '-06-17', 'Icelandic National Day'); $this->_addTranslationForHoliday('nationalDay', 'is_IS', 'Lýðveldisdagurinn'); $this->_addHoliday('jonsMass', $this->_year . '-06-24', 'Jón\'s Mass'); $this->_addTranslationForHoliday('jonsMass', 'is_IS', 'Jónsmessa'); $augDate = new Date($this->_year . '-08-01'); $dayOfWeek = $augDate->getDayOfWeek(); $commerceDate = $this->_addDays($augDate, 6 - $dayOfWeek); $this->_addHoliday('commerceDay', $commerceDate, 'Commerce Day'); $this->_addTranslationForHoliday('commerceDay', 'is_IS', 'Frídagur verslunarmanna'); $this->_addHoliday('languageDay', $this->_year . '-11-16', 'Icelandic Language Day'); $this->_addTranslationForHoliday('languageDay', 'is_IS', 'Dagur íslenskrar tungu'); $this->_addHoliday('independenceDay', $this->_year . '-12-01', 'Independence Day'); $this->_addTranslationForHoliday('independenceDay', 'is_IS', 'Fullveldisdagurinn'); /** * Christmas Eve */ $this->_addHoliday('christmas', $this->_year . '-12-24', 'Christmas Eve'); $this->_addTranslationForHoliday('christmas', 'is_IS', 'Aðfangadagur'); $this->_addHoliday('christmasDay', $this->_year . '-12-25', 'Christmas Day'); $this->_addTranslationForHoliday('christmasDay', 'is_IS', 'Jóladagur'); $this->_addHoliday('secondChristmasDay', $this->_year . '-12-26', 'Boxing Day'); $this->_addTranslationForHoliday('secondChristmasDay', 'is_IS', 'Annar í jólum'); /** * New Year's Eve */ $this->_addHoliday('newYearsEve', $this->_year . '-12-31', 'New Year\'s Eve'); $this->_addTranslationForHoliday('newYearsEve', 'is_IS', 'Gamlárskvöld'); if (Date_Holidays::errorsOccurred()) { return Date_Holidays::getErrorStack(); } return true; }
/** * A method to convert a Date object into the appropriate operation * interval ID (of the week). * * Works by finding out how many days, hours, minutes into the week the time is, and * then converting that into how many minutes into the week the time is. This value * is then divided by the interval length (in minutes) to determine how many intervals * into the week the time is. * * @static * @param Date $oDate The date to convert. * @param integer $operation_interval Optional length of the operation interval * in minutes. If not given, will use the * currently defined operation interval. * @return integer The operation interval ID that the time is in. */ function convertDateToOperationIntervalID($oDate, $operationInterval = 0) { if ($operationInterval < 1) { $operationInterval = OX_OperationInterval::getOperationInterval(); } // Convert to UTC $oDateCopy = new Date($oDate); $oDateCopy->toUTC(); $days = $oDateCopy->getDayOfWeek(); $hours = $oDateCopy->getHour(); $minutes = $oDateCopy->getMinute(); $totalMinutes = $days * 24 * 60 + $hours * 60 + $minutes; return (int) floor($totalMinutes / $operationInterval); }
/** * Build the internal arrays that contain data about the calculated holidays * * @access protected * @return boolean true on success, otherwise a PEAR_ErrorStack object * @throws object PEAR_ErrorStack */ function _buildHolidays() { /** * New Year's Day */ $this->_addHoliday('newYearsDay', $this->_year . '-01-01', 'New Year\'s Day'); $this->_addTranslationForHoliday('newYearsDay', 'ga_IE', 'Lá na Caille'); /** * Epiphany */ $this->_addHoliday('epiphany', $this->_year . '-01-06', 'Epiphany'); $this->_addTranslationForHoliday('epiphany', 'ga_IE', 'Nollag na mBan'); /** * St Patrick's Day. */ $this->_addHoliday('stPatricksDay', $this->_year . '-03-17', 'Saint Patrick\'s Day'); $this->_addTranslationForHoliday('stPatricksDay', 'ga_IE', 'Lá Fhéile Pádraig'); /** * Easter Sunday */ $easterDate = Date_Holidays_Driver_Ireland::calcEaster($this->_year); $this->_addHoliday('easter', $easterDate, 'Easter Sunday'); $this->_addTranslationForHoliday('easter', 'ga_IE', 'Domhnach Cásca'); /** * Good Friday / Black Friday */ $goodFridayDate = $this->_addDays($easterDate, -2); $this->_addHoliday('goodFriday', $goodFridayDate, 'Good Friday'); $this->_addTranslationForHoliday('goodFriday', 'ga_IE', 'Aoine Cásca'); /** * Easter Monday */ $this->_addHoliday('easterMonday', $easterDate->getNextDay(), 'Easter Monday'); $this->_addTranslationForHoliday('easterMonday', 'ga_IE', 'Luan Cásca'); /** * May Bank Holiday */ $dn = $this->_calcFirstMonday('05'); $this->_addHoliday('mayDayBankHoliday', $dn, 'May Bank Holiday'); $this->_addTranslationForHoliday('mayDayBankHoliday', 'ga_IE', 'Lá Bealtaine'); /** * Pentecost (determines Whit Monday, Ascension Day and * Feast of Corpus Christi) */ $pentecostDate = $this->_addDays($easterDate, 49); $this->_addHoliday('pentecost', $pentecostDate, 'Pentecost'); $this->_addTranslationForHoliday('pentecost', 'ga_IE', 'An Chincís'); /** * Ascension Day */ $ascensionDayDate = $this->_addDays($pentecostDate, -10); $this->_addHoliday('ascensionDay', $ascensionDayDate, 'Ascension Day'); $this->_addTranslationForHoliday('ascensionDay', 'ga_IE', 'Deascabhála'); /** * June Bank Holiday */ $dn = $this->_calcFirstMonday('06'); $this->_addHoliday('juneBankHoliday', $dn, 'June Bank Holiday'); $this->_addTranslationForHoliday('juneBankHoliday', 'ga_IE', 'Lá Meitheamh'); /** * Midsummer * Saturday past 20th, June */ $juneDate = new Date($this->_year . '-06-20'); $dayOfWeek = $juneDate->getDayOfWeek(); $midSummerDate = $this->_addDays($juneDate, 6 - $dayOfWeek); $this->_addHoliday('midSummer', $midSummerDate, 'Midsummer Day'); $this->_addTranslationForHoliday('midSummer', 'ga_IE', 'Lá Fhéile Eoin'); /** * August Bank Holiday */ $dn = $this->_calcFirstMonday('08'); $this->_addHoliday('augustBankHoliday', $dn, 'August Bank Holiday'); $this->_addTranslationForHoliday('augustBankHoliday', 'ga_IE', 'Lá Lúnasa'); /** * October Bank Holiday */ $dn = $this->_calcLastMonday('10'); $this->_addHoliday('octoberBankHoliday', $dn, 'October Bank Holiday'); $this->_addTranslationForHoliday('octoberBankHoliday', 'ga_IE', 'Lá Samhna'); /** * Christmas Eve */ $this->_addHoliday('christmasEve', $this->_year . '-12-24', 'Christmas Eve'); $this->_addTranslationForHoliday('christmasEve', 'ga_IE', 'Oíche Nollag'); /** * Christmas day */ $this->_addHoliday('christmasDay', $this->_year . '-12-25', 'Christmas Day'); $this->_addTranslationForHoliday('christmasDay', 'ga_IE', 'Lá Nollag'); /** * St. Stephen's Day */ $this->_addHoliday('stStephensDay', $this->_year . '-12-26', 'Saint Stephen\'s Day'); $this->_addTranslationForHoliday('stStephensDay', 'ga_IE', 'Lá Fhéile Stiofáin'); /** * New Year's Eve */ $this->_addHoliday('newYearsEve', $this->_year . '-12-31', 'New Year\'s Eve'); $this->_addTranslationForHoliday('newYearsEve', 'ga_IE', 'Oíche Chinn Bliana'); if (Date_Holidays::errorsOccurred()) { return Date_Holidays::getErrorStack(); } return true; }
/** * Build the internal arrays that contain data about the calculated holidays * * @access protected * @return boolean true on success, otherwise a PEAR_ErrorStack object * @throws object PEAR_ErrorStack */ function _buildHolidays() { /** * New Year's Day */ $this->_addHoliday('newYearsDay', $this->_year . '-01-01', 'New Year\'s Day'); /** * Epiphanias */ $this->_addHoliday('epiphany', $this->_year . '-01-06', 'Epiphany'); /** * Easter Sunday */ $easterDate = Date_Holidays_Driver_Sweden::calcEaster($this->_year); $this->_addHoliday('easter', $easterDate, 'Easter Sunday'); /** * Good Friday / Black Friday */ $goodFridayDate = $this->_addDays($easterDate, -2); $this->_addHoliday('goodFriday', $goodFridayDate, 'Good Friday'); /** * Easter Monday */ $this->_addHoliday('easterMonday', $easterDate->getNextDay(), 'Easter Monday'); /** * May Day */ $this->_addHoliday('mayDay', $this->_year . '-05-01', 'May Day'); /** * Pentecost (determines Whit Monday, Ascension Day and * Feast of Corpus Christi) */ $pentecostDate = $this->_addDays($easterDate, 49); $this->_addHoliday('pentecost', $pentecostDate, 'Pentecost'); /** * Ascension Day */ $ascensionDayDate = $this->_addDays($pentecostDate, -10); $this->_addHoliday('ascensionDay', $ascensionDayDate, 'Ascension Day'); /** * Swedish National Day and the Swedish Flag's Day */ $this->_addHoliday('swedenNationalDay', $this->_year . '-06-06', 'Swedish National Day and the Swedish Flag\'s Day'); /** * Midsummer * Saturday past 20th, June */ $juneDate = new Date($this->_year . '-06-20'); $dayOfWeek = $juneDate->getDayOfWeek(); $midSummerDate = $this->_addDays($juneDate, 6 - $dayOfWeek); $this->_addHoliday('midSummer', $midSummerDate, 'Midsummer Day'); /** * Midsummer Eve * Day before Midsummer. */ $this->_addHoliday('midSummerEve', $midSummerDate->getPrevDay(), 'Midsummer Eve'); /** * All Saints' Day */ $saintspanDate = new Date($this->_year . '-10-31'); $dayOfWeek = $saintspanDate->getDayOfWeek(); $allSaintsDate = $this->_addDays($saintspanDate, 6 - $dayOfWeek); $this->_addHoliday('allSaintsDay', $allSaintsDate, 'All Saints\' Day'); /** * Christmas Eve */ $this->_addHoliday('christmasEve', $this->_year . '-12-24', 'Christmas Eve'); /** * Christmas day */ $this->_addHoliday('christmasDay', $this->_year . '-12-25', 'Christmas Day'); /** * Boxing day */ $this->_addHoliday('boxingDay', $this->_year . '-12-26', 'Boxing Day'); /** * New Year's Eve */ $this->_addHoliday('newYearsEve', $this->_year . '-12-31', 'New Year\'s Eve'); if (Date_Holidays::errorsOccurred()) { return Date_Holidays::getErrorStack(); } return true; }
/** * A private method that returns the start and end dates * that bound the span, based based on a pre-defined 'friendly' * value. * * See the {@link OA_Admin_DaySpan::setSpanPresetValue()} method * for the pre-defined values. * * @param string $presetValue The preset value string. * @return array An array of two elements, "start" and "end", * representing the start and end dates of * the span, respectively. */ function _getSpanDates($presetValue) { switch ($presetValue) { case 'today': $oDateStart = new Date($this->oNowDate->format('%Y-%m-%d')); $oDateEnd = new Date($this->oNowDate->format('%Y-%m-%d')); break; case 'yesterday': $oDateStart = new Date(Date_Calc::prevDay($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y'))); $oDateEnd = new Date(Date_Calc::prevDay($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y'))); break; case 'this_week': $oDateStart = new Date(Date_Calc::beginOfWeek($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y'))); $oSixDaySpan = new Date_Span(); $oSixDaySpan->setFromDays(6); $oSevenDaySpan = new Date_Span(); $oSevenDaySpan->setFromDays(7); // Now have week start and end when week starts on Sunday // Does the user want to start on a different day? $beginOfWeek = OA_Admin_DaySpan::getBeginOfWeek(); if ($beginOfWeek > 0) { $oRequiredDaysSpan = new Date_Span(); $oRequiredDaysSpan->setFromDays($beginOfWeek); $oDateStart->addSpan($oRequiredDaysSpan); $oDateToday = new Date($this->oNowDate->format('%Y-%m-%d')); if ($oDateToday->getDayOfWeek() < $beginOfWeek) { $oDateStart->subtractSpan($oSevenDaySpan); } } $oDateEnd = new Date($this->oNowDate->format('%Y-%m-%d')); break; case 'last_week': $oDateStart = new Date(Date_Calc::beginOfPrevWeek($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y'))); $oSixDaySpan = new Date_Span(); $oSixDaySpan->setFromDays(6); $oSevenDaySpan = new Date_Span(); $oSevenDaySpan->setFromDays(7); // Now have week start and end when week starts on Sunday // Does the user want to start on a different day? $beginOfWeek = OA_Admin_DaySpan::getBeginOfWeek(); if ($beginOfWeek > 0) { $oRequiredDaysSpan = new Date_Span(); $oRequiredDaysSpan->setFromDays($beginOfWeek); $oDateStart->addSpan($oRequiredDaysSpan); $oDateToday = new Date($this->oNowDate->format('%Y-%m-%d')); if ($oDateToday->getDayOfWeek() < $beginOfWeek) { $oDateStart->subtractSpan($oSevenDaySpan); } } $oDateEnd = new Date($this->oNowDate->format('%Y-%m-%d')); $oDateEnd->copy($oDateStart); $oDateEnd->addSpan($oSixDaySpan); break; case 'last_7_days': $oDateStart = new Date($this->oNowDate->format('%Y-%m-%d')); $oDateEnd = new Date($this->oNowDate->format('%Y-%m-%d')); $oOneDaySpan = new Date_Span(); $oOneDaySpan->setFromDays(1); $oSevenDaySpan = new Date_Span(); $oSevenDaySpan->setFromDays(7); $oDateStart->subtractSpan($oSevenDaySpan); $oDateEnd->subtractSpan($oOneDaySpan); break; case 'this_month': $oDateStart = new Date(Date_Calc::beginOfMonth($this->oNowDate->format('%m'), $this->oNowDate->format('%Y'))); $oDateEnd = new Date($this->oNowDate->format('%Y-%m-%d')); break; case 'this_month_full': $oDateStart = new Date(Date_Calc::beginOfMonth($this->oNowDate->format('%m'), $this->oNowDate->format('%Y'))); $oDateEnd = new Date(Date_Calc::beginOfNextMonth($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y'))); $oOneDaySpan = new Date_Span(); $oOneDaySpan->setFromDays(1); $oDateEnd->subtractSpan($oOneDaySpan); break; case 'this_month_remainder': $oDateStart = new Date($this->oNowDate->format('%Y-%m-%d')); $oDateEnd = new Date(Date_Calc::beginOfNextMonth($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y'))); $oOneDaySpan = new Date_Span(); $oOneDaySpan->setFromDays(1); $oDateEnd->subtractSpan($oOneDaySpan); break; case 'next_month': $oDateStart = new Date(Date_Calc::beginOfNextMonth($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y'))); $oDateEnd = new Date(Date_Calc::endOfNextMonth($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y'))); break; case 'last_month': $oDateStart = new Date(Date_Calc::beginOfPrevMonth($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y'))); $oDateEnd = new Date(Date_Calc::beginOfMonth($this->oNowDate->format('%m'), $this->oNowDate->format('%Y'))); $oOneDaySpan = new Date_Span(); $oOneDaySpan->setFromDays(1); $oDateEnd->subtractSpan($oOneDaySpan); break; case 'all_stats': $oDateStart = null; $oDateEnd = null; break; case 'specific': $startDate = MAX_getStoredValue('startDate', date('Y-m-d')); $oDateStart = new Date($startDate); $endDate = MAX_getStoredValue('endDate', date('Y-m-d')); $oDateEnd = new Date($endDate); break; } $this->_setStartDate($oDateStart); $this->_setEndDate($oDateEnd); $aDates = array('start' => $oDateStart, 'end' => $oDateEnd); return $aDates; }
public function getNextRunTime($date) { // check if $date is a timestamp... if ($date instanceof Date == false && is_integer($date)) { $date = new Date($date); } // assume now $date IS instanceof Date $cSecond = $date->getSecond(); $cMinute = $date->getMinute(); $cHour = $date->getHour(); $cDay = $date->getDay(); $cMonth = $date->getMonth(); $cYear = $date->getYear(); // required to check the number of days in the month $found = false; while ($found === false) { while ($found === false) { // iterate months... $cMonth = $this->findNextInArray($cMonth, $this->monthArray); if ($cMonth === null) { break; } // find the day now while ($found === false) { $cDay = $this->findNextInArray($cDay, $this->dayArray); if ($cDay === null) { break; } // here dayOfWeek and number of days in month should be checked! $date = new Date(); $date->setYear($cYear); $date->setMonth($cMonth); $numberOfDaysInMonth = $date->getDaysInMonth(); if ($cDay > $numberOfDaysInMonth) { break; } if ($this->dayOfWeekArray !== null) { // get day of the week $date->setDay($cDay); $dayOfWeek = $date->getDayOfWeek(); if (!in_array($dayOfWeek, $this->dayOfWeekArray)) { $cDay++; continue; } } while ($found === false) { if ($cHour == 24) { break; } $cHour = $this->findNextInArray($cHour, $this->hourArray); if ($cHour === null) { break; } while ($found === false) { if ($cMinute == 60) { break; } $cMinute = $this->findNextInArray($cMinute, $this->minuteArray); if ($cMinute === null) { break; } while ($found === false) { if ($cSecond == 60) { break; } $cSecond = $this->findNextInArray($cSecond, $this->secondArray); if ($cSecond === null) { break; } else { // FOUND IT!!! WOOOO! // create Date object $date = new Date(); $date->setYear($cYear); $date->setMonth($cMonth); $date->setDay($cDay); $date->setHour($cHour); $date->setMinute($cMinute); $date->setSecond($cSecond); return $date; } } $cMinute++; $cSecond = 0; } $cHour++; $cMinute = 0; $cSecond = 0; } $cDay++; $cHour = 0; $cMinute = 0; $cSecond = 0; } $cMonth++; $cDay = 0; $cHour = 0; $cMinute = 0; $cSecond = 0; } $cYear++; $cMonth = 0; $cDay = 0; $cHour = 0; $cMinute = 0; $cSecond = 0; } }
/** * 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; }