/** * 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(); /** * New Year's Day */ $this->_addHoliday('newYearsDay', $this->_year . '-01-01', 'New Year\'s Day'); /** * Epiphanias */ $firstSunday = $this->_calcNthWeekDayInMonth(1, 0, 1); if ($firstSunday->getDay() == 1) { $firstSunday = $this->_addDays($firstSunday, 7); } $this->_addHoliday('epiphanySunday', $firstSunday, 'Epiphany'); /** * Valentine's Day */ $this->_addHoliday('valentinesDay', $this->_year . '-02-14', 'Valentine\'s Day'); /** * Easter Sunday */ $easterDate = $this->getHolidayDate('easter'); /** * Shrove Monday */ $shroveMondayDate = $this->_addDays($easterDate, -48); $this->_addHoliday('shroveMonday', $shroveMondayDate, 'Shrove Monday'); /** * Shrove Tuesday */ $shroveTuesdayDate = $this->_addDays($shroveMondayDate, 1); $this->_addHoliday('shroveTuesday', $shroveTuesdayDate, 'Shrove Tuesday'); /** * International day of work */ $this->_addHoliday('dayOfWork', $this->_year . '-05-01', 'International day of work'); /** * 1945 victory */ $this->_addHoliday('victory1945', $this->_year . '-05-08', 'Victory of 1945'); /** * Mother's Day */ $mothersDay = $this->_calcLastSunday(5); $whitsun = $this->getHolidayDate('whitsun'); $mothersDay2 = new Date($mothersDay); if ($mothersDay2->equals(clone $whitsun)) { $mothersDay = $this->_addDays($mothersDay, 7); } $this->_addHoliday('mothersDay', $mothersDay, 'Mothers\' Day'); /** * Abolition of Slavery Day (Mayotte) */ $this->_addHoliday('abolitionOfSlaveryDayMayotte', $this->_year . '-04-27', 'Abolition of Slavery Day'); /** * Saint-Pierre-Chanel Day (Wallis and Futuna) */ $this->_addHoliday('saintPierreChanelDay', $this->_year . '-04-28', 'Saint-Pierre-Chanel Day'); /** * Abolition of Slavery Day (Martinique) */ $this->_addHoliday('abolitionOfSlaveryDayMartinique', $this->_year . '-05-22', 'Abolition of Slavery Day'); /** * Abolition of Slavery Day (Guadeloupe) */ $this->_addHoliday('abolitionOfSlaveryDayGuadeloupe', $this->_year . '-05-27', 'Abolition of Slavery Day'); /** * Abolition of Slavery Day (Guyana) */ $this->_addHoliday('abolitionOfSlaveryDayGuyana', $this->_year . '-06-10', 'Abolition of Slavery Day'); /** * Autonomy Day (French Polynesia) */ $this->_addHoliday('autonomyDay', $this->_year . '-06-29', 'Autonomy Day'); /** * French National Day */ $this->_addHoliday('frenchNationalDay', $this->_year . '-07-14', 'French National Day'); /** * Victor Schoelcher Day */ $this->_addHoliday('victorSchoelcherDay', $this->_year . '-07-21', 'Victor Schoelcher Day'); /** * Territory Day (Wallis and Futuna) */ $this->_addHoliday('territoryDay', $this->_year . '-07-29', 'Territory Day'); /** * Celebration of citizenship Day (New Caledonia) */ $this->_addHoliday('celebrationOfCitizenshipDay', $this->_year . '-09-24', 'Celebration of citizenship Day'); /** * Veteran's Day */ $this->_addHoliday('veteransDay', $this->_year . '-11-11', 'Veteran\'s Day'); /** * Abolition of Slavery Day (Reunion) */ $this->_addHoliday('abolitionOfSlaveryDayReunion', $this->_year . '-12-20', 'Abolition of Slavery Day'); /** * Saint Étienne Day(Alsace & Moselle) */ $this->_addHoliday('saintEtienneDay', $this->_year . '-12-26', 'Saint Étienne Day'); if (Date_Holidays::errorsOccurred()) { return Date_Holidays::getErrorStack(); } return true; }
/** * ??? * * @param integer $zoneId The ID of the zone to be tested. * @param unknown_type $campaignid ??? * @param unknown_type $newStart ??? * @param unknown_type $newEnd ??? * @return unknown ??? */ function _checkEmailZoneAdAssoc($zoneId, $campaignid, $newStart = false, $newEnd = false) { // Suppress PEAR error handling for this method... PEAR::pushErrorHandling(null); require_once 'Date.php'; // This is an email zone, so check all current linked ads for active date ranges $aOtherAds = Admin_DA::getAdZones(array('zone_id' => $zoneId)); $campaignVariables = Admin_DA::getPlacement($campaignid); if ($newStart) { $campaignVariables['activate_time'] = $newStart; } if ($newEnd) { $campaignVariables['expire_time'] = $newEnd; } if (empty($campaignVariables['activate_time']) && empty($campaignVariables['expire_time'])) { return PEAR::raiseError($GLOBALS['strEmailNoDates'], MAX_ERROR_EMAILNODATES); } $campaignStart = new Date($campaignVariables['activate_time']); $campaignStart->setTZbyID('UTC'); $campaignEnd = new Date($campaignVariables['expire_time']); $campaignEnd->setTZbyID('UTC'); $okToLink = true; foreach ($aOtherAds as $azaID => $aAdVariables) { $aOtherAdVariables = Admin_DA::getAd($aAdVariables['ad_id']); if ($aOtherAdVariables['placement_id'] == $campaignid) { continue; } $otherCampaignVariables = Admin_DA::getPlacement($aOtherAdVariables['placement_id']); if (empty($otherCampaignVariables['activate_time']) || empty($otherCampaignVariables['expire_time'])) { $okToLink = false; break; } // Do not allow link if either start or end date is within another linked campaign dates $otherCampaignStart = new Date($otherCampaignVariables['activate_time']); $otherCampaignStart->setTZbyID('UTC'); $otherCampaignEnd = new Date($otherCampaignVariables['expire_time']); $otherCampaignEnd->setTZbyID('UTC'); if ($campaignStart->after($otherCampaignStart) && $campaignStart->before($otherCampaignEnd) || $campaignStart->equals($otherCampaignStart)) { $okToLink = false; break; } if ($campaignEnd->after($otherCampaignStart) && $campaignEnd->before($otherCampaignEnd) || $campaignEnd->equals($otherCampaignEnd)) { $okToLink = false; break; } } if (!$okToLink) { $link = "campaign-edit.php?clientid={$otherCampaignVariables['advertiser_id']}&campaignid={$otherCampaignVariables['placement_id']}"; return PEAR::raiseError($GLOBALS['strDatesConflict'] . ": <a href='{$link}'>" . $otherCampaignVariables['name'] . "</a>", MAX_ERROR_EXISTINGCAMPAIGNFORDATES); } PEAR::popErrorHandling(); return true; }
function testGetLastRun() { $oMaintenance = new OX_Maintenance(); $this->assertNull($oMaintenance->getLastRun()); $iLastRun = strtotime('2002-01-01'); OA_Dal_ApplicationVariables::set('maintenance_timestamp', $iLastRun); $oDate = new Date((int) $iLastRun); $this->assertTrue($oDate->equals($oMaintenance->getLastRun())); OA_Dal_ApplicationVariables::delete('maintenance_timestamp'); }
echo "Adding " . $oOIStart->format('%Y-%m-%d %H:%M:%S') . "' -> '" . $oOIEnd->format('%Y-%m-%d %H:%M:%S') . " to the list of run dates<br />\n"; // Store the dates $oStoreStartDate = new Date(); $oStoreStartDate->copy($oOIStart); $oStoreEndDate = new Date(); $oStoreEndDate->copy($oOIEnd); $aRunDates[] = array('start' => $oStoreStartDate, 'end' => $oStoreEndDate); $oOIEnd = OX_OperationInterval::addOperationIntervalTimeSpan($oOIEnd); $oOIStart = OX_OperationInterval::addOperationIntervalTimeSpan($oOIStart); } // The summariseFinal process requires complete hours (not OI's), so record these too $oOIStart = new Date(INTERVAL_START); $oOIEnd = new Date(INTERVAL_START); $oOIEnd->addSeconds(60 * 60 - 1); $aRunHours = array(); while ($oOIEnd->before($oEndDate) || $oOIEnd->equals($oEndDate)) { echo "Adding " . $oOIStart->format('%Y-%m-%d %H:%M:%S') . "' -> '" . $oOIEnd->format('%Y-%m-%d %H:%M:%S') . " to the list of run dates<br />\n"; // Store the dates $oStoreStartDate = new Date(); $oStoreStartDate->copy($oOIStart); $oStoreEndDate = new Date(); $oStoreEndDate->copy($oOIEnd); $aRunHours[] = array('start' => $oStoreStartDate, 'end' => $oStoreEndDate); $oOIEnd->addSeconds(60 * 60); $oOIStart->addSeconds(60 * 60); } // Create and register an instance of the OA_Dal_Maintenance_Statistics DAL class for the following tasks to use $oServiceLocator =& OA_ServiceLocator::instance(); if (!$oServiceLocator->get('OX_Dal_Maintenance_Statistics')) { $oFactory = new OX_Dal_Maintenance_Statistics_Factory(); $oDal = $oFactory->factory();
/** * The implementation of the OA_Task::run() method that performs * the required task of logging the completion of the MSE process. * * @param PEAR::Date $oEndDate Optional date/time representing the end of the tasks. */ function run($oEndDate = null) { $oServiceLocator =& OA_ServiceLocator::instance(); $oNowDate =& $oServiceLocator->get('now'); if (is_null($oEndDate)) { $oEndDate = new Date(); } // Prepare the duraction to log from the start and end dates $oDuration = new Date_Span(); $oStartDateCopy = new Date(); $oStartDateCopy->copy($oNowDate); $oEndDateCopy = new Date(); $oEndDateCopy->copy($oEndDate); $oDuration->setFromDateDiff($oStartDateCopy, $oEndDateCopy); $message = '- Logging the completion of the maintenance statistics run'; $this->oController->report .= "{$message}.\n"; OA::debug($message, PEAR_LOG_DEBUG); // Determine the type of MSE completion logging required if ($this->oController->updateFinal && $this->oController->updateIntermediate) { // Need to log that both the intermediate and final tables were updated; // however, need to ensure that we log the correct "updated to" times $oUpdateIntermediateToDate = new Date(); $oUpdateIntermediateToDate->copy($this->oController->oUpdateIntermediateToDate); $oUpdateFinalToDate = new Date(); $oUpdateFinalToDate->copy($this->oController->oUpdateFinalToDate); if ($oUpdateIntermediateToDate->equals($oUpdateFinalToDate)) { // The dates are the same, log info with one row $doLog_maintenance_statistics = OA_Dal::factoryDO('log_maintenance_statistics'); $doLog_maintenance_statistics->start_run = $oNowDate->format('%Y-%m-%d %H:%M:%S'); $doLog_maintenance_statistics->end_run = $oEndDate->format('%Y-%m-%d %H:%M:%S'); $doLog_maintenance_statistics->duration = $oDuration->toSeconds(); $doLog_maintenance_statistics->adserver_run_type = OX_DAL_MAINTENANCE_STATISTICS_UPDATE_BOTH; $doLog_maintenance_statistics->updated_to = $this->oController->oUpdateIntermediateToDate->format('%Y-%m-%d %H:%M:%S'); $doLog_maintenance_statistics->insert(); } else { // The dates are not the same, log info with two rows $doLog_maintenance_statistics = OA_Dal::factoryDO('log_maintenance_statistics'); $doLog_maintenance_statistics->start_run = $oNowDate->format('%Y-%m-%d %H:%M:%S'); $doLog_maintenance_statistics->end_run = $oEndDate->format('%Y-%m-%d %H:%M:%S'); $doLog_maintenance_statistics->duration = $oDuration->toSeconds(); $doLog_maintenance_statistics->adserver_run_type = OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI; $doLog_maintenance_statistics->updated_to = $this->oController->oUpdateIntermediateToDate->format('%Y-%m-%d %H:%M:%S'); $doLog_maintenance_statistics->insert(); $doLog_maintenance_statistics = OA_Dal::factoryDO('log_maintenance_statistics'); $doLog_maintenance_statistics->start_run = $oNowDate->format('%Y-%m-%d %H:%M:%S'); $doLog_maintenance_statistics->end_run = $oEndDate->format('%Y-%m-%d %H:%M:%S'); $doLog_maintenance_statistics->duration = $oDuration->toSeconds(); $doLog_maintenance_statistics->adserver_run_type = OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR; $doLog_maintenance_statistics->updated_to = $this->oController->oUpdateFinalToDate->format('%Y-%m-%d %H:%M:%S'); $doLog_maintenance_statistics->insert(); } } else { if ($this->oController->updateIntermediate) { $doLog_maintenance_statistics = OA_Dal::factoryDO('log_maintenance_statistics'); $doLog_maintenance_statistics->start_run = $oNowDate->format('%Y-%m-%d %H:%M:%S'); $doLog_maintenance_statistics->end_run = $oEndDate->format('%Y-%m-%d %H:%M:%S'); $doLog_maintenance_statistics->duration = $oDuration->toSeconds(); $doLog_maintenance_statistics->adserver_run_type = OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI; $doLog_maintenance_statistics->updated_to = $this->oController->oUpdateIntermediateToDate->format('%Y-%m-%d %H:%M:%S'); $doLog_maintenance_statistics->insert(); } else { if ($this->oController->updateFinal) { $doLog_maintenance_statistics = OA_Dal::factoryDO('log_maintenance_statistics'); $doLog_maintenance_statistics->start_run = $oNowDate->format('%Y-%m-%d %H:%M:%S'); $doLog_maintenance_statistics->end_run = $oEndDate->format('%Y-%m-%d %H:%M:%S'); $doLog_maintenance_statistics->duration = $oDuration->toSeconds(); $doLog_maintenance_statistics->adserver_run_type = OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR; $doLog_maintenance_statistics->updated_to = $this->oController->oUpdateFinalToDate->format('%Y-%m-%d %H:%M:%S'); $doLog_maintenance_statistics->insert(); } else { return false; } } } // Log the report to the "user log" $this->_setMaintenanceStatisticsRunReport($this->oController->report); return true; }
/** * A method to test the _getDate() method. * * Test 1: Test with no date in the OA_ServiceLocator, and ensure that the * current date/time is returned. * Test 2: Test with a date in the OA_ServiceLocator, and ensure that the * correct date/time is returned. * Test 3: Test with a date passed in as a parameter, and ensure that the * correct date/time is returned. */ function test_getDate() { $oGetRequiredAdImpressionsLifetime =& $this->_getCurrentTask(); // Test 1 $oServiceLocator =& OA_ServiceLocator::instance(); $oServiceLocator->remove('now'); $oDate1 = $oGetRequiredAdImpressionsLifetime->_getDate(); $oDate2 = $oServiceLocator->get('now'); $this->assertTrue(is_a($oDate1, 'Date')); $this->assertTrue(is_a($oDate2, 'Date')); $this->assertTrue($oDate1->equals($oDate2)); // Test 2 $oDate1 = new Date(); $oServiceLocator->register('now', $oDate1); $oDate2 = $oGetRequiredAdImpressionsLifetime->_getDate(); $this->assertTrue(is_a($oDate2, 'Date')); $this->assertTrue($oDate1->equals($oDate2)); // Test 3 $oDate1 = new Date('2005-12-08 13:55:00'); $oDate2 = $oGetRequiredAdImpressionsLifetime->_getDate($oDate1->format('%Y-%m-%d %H:%M:%S')); $this->assertTrue(is_a($oDate2, 'Date')); $this->assertTrue($oDate1->equals($oDate2)); }
function isValidDate($date) { if (is_null($date)) { return false; } $nullDate = new Date('0000-01-01'); if ($nullDate->equals($date)) { return false; } return true; }
public function test_equals() { $date1 = new Date(DATE_YEAR_MONTH_DAY, Timezone::SERVER_TIMEZONE, 2009, 10, 17); $date2 = new Date(DATE_YEAR_MONTH_DAY, Timezone::SERVER_TIMEZONE, 2009, 10, 18); self::assertEquals(false, $date2->equals($date1)); self::assertEquals(true, $date1->equals($date1)); }
/** * Compares to dates. * * Returns: * - 0 if dates are equal * - 1 if left Date > right Date * - -1 if left Date < right Date * * @return int 0 if dates are eq; "1" if left Date > right Date; "-1" if left Date < right Date */ static function compare(Date $left, Date $right) { if ($left->equals($right)) { return CompareResult::EQUALS; } else { return $left->int > $right->int ? CompareResult::GREATER_THAN : CompareResult::LESS_THAN; } }
<h4>Display micro-time:</h4> <?php $date->setSecond(3.201282); echo_code($date->format('%d/%m/%Y %I.%M.%s')); echo_code($date->format2('DD/MM/YYYY HH12.MI.SS.FFFFFF')); ?> <h4>Convert to Unix time:</h4> <?php echo_code($hn_unixtime = $date->format2('U')); ?> <h4>Convert Unix time back to Date object:</h4> <?php $date2 = new Date($hn_unixtime); echo_code($date2->format2("DD/MM/YYYY HH.MI.SSTZO")); ?> <h4>Compare two times for equality:</h4> <?php if ($date2->before($date)) { echo "second date is earlier (because Unix time ignores the part-second)<br />\n"; } $date->trunc(DATE_PRECISION_SECOND); if ($date2->equals($date)) { echo "dates are now the same<br />\n"; } ?> <br /> <br /> <br /> <br /> </body> </html>