当前位置: 首页>>代码示例>>PHP>>正文


PHP Date::before方法代码示例

本文整理汇总了PHP中Date::before方法的典型用法代码示例。如果您正苦于以下问题:PHP Date::before方法的具体用法?PHP Date::before怎么用?PHP Date::before使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Date的用法示例。


在下文中一共展示了Date::before方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct($oStart, $oEnd, $aEntityParams)
 {
     $oNow = new Date();
     $this->oStart = $oNow->before($oStart) ? $oNow : $oStart;
     $this->oEnd = $oNow->before($oEnd) ? $oNow : $oEnd;
     $this->parseEntityParams($aEntityParams);
 }
开发者ID:SamWinchester,项目名称:revive-adserver,代码行数:7,代码来源:apGraph.php

示例2: testGetPlacementFirstStatsDate

 /**
  * A method to test the getPlacementFirstStatsDate() method.
  *
  * Requirements:
  * Test 1: Test with an invalid placement ID, and ensure null is returned.
  * Test 2: Test with no data in the database, and ensure current date is returned.
  * Test 3: Test with single row in the database, and ensure correct date is
  *         returned.
  * Test 4: Test with multi rows in the database, and ensure correct date is
  *         returned.
  */
 function testGetPlacementFirstStatsDate()
 {
     $conf =& $GLOBALS['_MAX']['CONF'];
     $oDbh =& OA_DB::singleton();
     $oDalStatistics = new MAX_Dal_Statistics();
     // Test 1
     $placementId = 'foo';
     $oResult = $oDalStatistics->getPlacementFirstStatsDate($placementId);
     $this->assertNull($oResult);
     // Test 2
     $placementId = 1;
     $oBeforeDate = new Date();
     sleep(1);
     $oResult = $oDalStatistics->getPlacementFirstStatsDate($placementId);
     sleep(1);
     $oAfterDate = new Date();
     $this->assertTrue(is_a($oResult, 'Date'));
     $this->assertTrue($oBeforeDate->before($oResult));
     $this->assertTrue($oAfterDate->after($oResult));
     // Test 3
     $oNow = new Date();
     $aData = array('campaignid' => $placementId, 'active' => 't', 'updated' => $oNow->format('%Y-%m-%d %H:%M:%S'), 'acls_updated' => $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idBanner1 = $this->_insertBanner($aData);
     $aData = array('day' => '2006-10-30', 'hour' => 12, 'ad_id' => $idBanner1, 'updated' => $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDSAH1 = $this->_insertDataSummaryAdHourly($aData);
     $oResult = $oDalStatistics->getPlacementFirstStatsDate($placementId);
     $oExpectedDate = new Date('2006-10-30 12:00:00');
     $this->assertEqual($oResult, $oExpectedDate);
     // Test 4
     $aData = array('campaignid' => $placementId, 'active' => 't', 'updated' => $oNow->format('%Y-%m-%d %H:%M:%S'), 'acls_updated' => $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idBanner2 = $this->_insertBanner($aData);
     $aData = array('campaignid' => 999, 'active' => 't', 'updated' => $oNow->format('%Y-%m-%d %H:%M:%S'), 'acls_updated' => $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idBanner3 = $this->_insertBanner($aData);
     $aData = array('day' => '2006-10-29', 'hour' => 12, 'ad_id' => $idBanner2, 'updated' => $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDSAH1 = $this->_insertDataSummaryAdHourly($aData);
     $aData = array('day' => '2006-10-28', 'hour' => 12, 'ad_id' => $idBanner2, 'updated' => $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDSAH2 = $this->_insertDataSummaryAdHourly($aData);
     $aData = array('day' => '2006-10-27', 'hour' => 12, 'ad_id' => $idBanner2, 'updated' => $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDSAH3 = $this->_insertDataSummaryAdHourly($aData);
     $aData = array('day' => '2006-10-26', 'hour' => 12, 'ad_id' => 999, 'updated' => $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDSAH4 = $this->_insertDataSummaryAdHourly($aData);
     $oResult = $oDalStatistics->getPlacementFirstStatsDate($placementId);
     $oExpectedDate = new Date('2006-10-27 12:00:00');
     $this->assertEqual($oResult, $oExpectedDate);
     DataGenerator::cleanUp();
 }
开发者ID:hostinger,项目名称:revive-adserver,代码行数:57,代码来源:DalStatistics.dal.test.php

示例3: Date

 /**
  * A method to check if the campaign is awaiting activation
  *
  * @return bool
  */
 function _isAwaiting()
 {
     static $oServiceLocator;
     // MySQL null date hardcoded for optimisation
     if (!empty($this->activate) && $this->activate != '0000-00-00') {
         if (!isset($oServiceLocator)) {
             $oServiceLocator =& OA_ServiceLocator::instance();
         }
         if (!($oNow = $oServiceLocator->get('now'))) {
             $oNow = new Date();
         }
         $oActivate = new Date($this->activate);
         if (!empty($this->clientid)) {
             // Set timezone
             $aAccounts = $this->getOwningAccountIds();
             $aPrefs = OA_Preferences::loadAccountPreferences($aAccounts[OA_ACCOUNT_ADVERTISER], true);
             if (isset($aPrefs['timezone'])) {
                 $oActivate->setTZbyID($aPrefs['timezone']);
             }
         }
         if ($oNow->before($oActivate)) {
             return true;
         }
     }
     return false;
 }
开发者ID:villos,项目名称:tree_admin,代码行数:31,代码来源:Campaigns.php

示例4: getDatesArray

 /**
  * A method to calculate the range of dates that a statistics screen needs to display.
  *
  * Returns an array of values where:
  *
  *  - If "week" or "day" is the breakdown, array is of days, indexed by "YYYY-MM-DD",
  *    and formatted using the user's local format for days.
  *
  *  - If "month" is the breakdown, array is of months, indexed by "YYYY-MM",
  *    and formatted using the user's local format for months and days.
  *
  *  - If "dow" is the breakdown, array is of days of the week, indexed by the integers
  *    0 to 6, and formatted with the user's local weekday names.
  *
  *  - If "hour" is the breakdown, array is of hours of the day, indexed by the integers
  *    0 to 23, and formatted in the format "00:00 - 00:59", "01:00 01:59", etc.
  *
  * @param array      $aDates          An array of the start and end dates in use by the day
  *                                    span selector element, if set.
  * @param string     $breakdown       The breakdown type in use. One of "week", "day", "month",
  *                                    "dow" or "hour".
  * @param PEAR::Date $oStatsStartDate A date object representing the first day of statistics
  *                                    that are available.
  * @return array The array, as described above.
  */
 function getDatesArray($aDates, $breakdown, $oStatsStartDate)
 {
     // Does the day span selector element have dates set?
     if ($aDates['day_begin'] && $aDates['day_end'] || $aDates['period_start'] && $aDates['period_end']) {
         if ($aDates['day_begin'] && $aDates['day_end']) {
             // Use the dates given by the day span selector element
             $oStartDate = new Date($aDates['day_begin']);
             $oEndDate = new Date($aDates['day_end']);
         } else {
             // Use the dates given by the period_start and period_end
             $oStartDate = new Date($aDates['period_start']);
             $oEndDate = new Date($aDates['period_end']);
         }
         // Adjust end date to be now, if it's in the future
         if ($oEndDate->isFuture()) {
             $oEndDate = new Date();
             $aDates['day_end'] = new Date();
             $aDates['day_end'] = $aDates['day_end']->format('%Y-%m-%d');
         }
     } else {
         // Use the dates given by the statistics date limitation
         // and now
         $oStartDate = new Date();
         $oStartDate->copy($oStatsStartDate);
         $oEndDate = new Date();
     }
     // Prepare the return array
     $aDatesResult = array();
     switch ($breakdown) {
         case 'week':
         case 'day':
             $oOneDaySpan = new Date_Span('1', '%d');
             $oEndDate->addSpan($oOneDaySpan);
             $oDate = new Date();
             $oDate->copy($oStartDate);
             while ($oDate->before($oEndDate)) {
                 $aDatesResult[$oDate->format('%Y-%m-%d')] = $oDate->format($GLOBALS['date_format']);
                 $oDate->addSpan($oOneDaySpan);
             }
             break;
         case 'month':
             $oOneMonthSpan = new Date_Span((string) ($oEndDate->getDaysInMonth() - $oEndDate->getDay() + 1), '%d');
             $oEndDate->addSpan($oOneMonthSpan);
             $oDate = new Date();
             $oDate->copy($oStartDate);
             while ($oDate->before($oEndDate)) {
                 $aDatesResult[$oDate->format('%Y-%m')] = $oDate->format($GLOBALS['month_format']);
                 $oOneMonthSpan = new Date_Span((string) ($oDate->getDaysInMonth() - $oDate->getDay() + 1), '%d');
                 $oDate->addSpan($oOneMonthSpan);
             }
             break;
         case 'dow':
             for ($dow = 0; $dow < 7; $dow++) {
                 $aDatesResult[$dow] = $GLOBALS['strDayFullNames'][$dow];
             }
             break;
         case 'hour':
             for ($hour = 0; $hour < 24; $hour++) {
                 $aDatesResult[$hour] = sprintf('%02d:00 - %02d:59', $hour, $hour);
             }
             break;
     }
     return $aDatesResult;
 }
开发者ID:Apeplazas,项目名称:plazadelatecnologia,代码行数:89,代码来源:History.php

示例5: getDailyTargetingStatistics

 /**
  * A method for obtaining the targeting statistics of an ad or placement
  * for a single day, where the data is summarised by operation interval.
  *
  * @param integer    $id    The ad or placement ID.
  * @param string     $type  Either "ad" or "placement".
  * @param PEAR::Date $oDate A date representing the day required.
  *
  * @return mixed Returns false in the event of incorrect input, or in the case
  *               of being unable to connect to the database, otherwise, returns
  *               an array of arrays:
  *
  *
  * array(
  *     [$operationIntervalId] => array(
  *                                  ['interval_start']             => PEAR::Date
  *                                  ['interval_end']               => PEAR::Date
  *                                  ['ad_required_impressions']    => integer
  *                                  ['ad_requested_impressions']   => integer
  *                                  ['ad_actual_impressions']      => integer
  *                                  ['zones_forecast_impressions'] => integer
  *                                  ['zones_actual_impressions']   => integer
  *                                  ['average']                    => integer
  *                               )
  *      .
  *      .
  *      .
  * )
  *
  * or:
  *
  * array(
  *     [$operationIntervalId] => array(
  *                                  ['interval_start']                  => PEAR::Date
  *                                  ['interval_end']                    => PEAR::Date
  *                                  ['placement_required_impressions']  => integer
  *                                  ['placement_requested_impressions'] => integer
  *                                  ['placement_actual_impressions']    => integer
  *                                  ['zones_forecast_impressions']      => integer
  *                                  ['zones_actual_impressions']        => integer
  *                                  ['average']                         => integer
  *                               )
  *      .
  *      .
  *      .
  * )
  *
  * For the ad or placement and day specified, returns an array for each
  * operation interval in the day, consisting of the operation interval start
  * and end dates, and the total number of impressions requested by the ad, or
  * all ads in the placement (for all zones the ads are linked to), as well as
  * the total number of impressions actually delivered by the ad, or all ads
  * in the placement (for all zones the ads are linked to).
  *
  * The individual ad/zone impressions requested values may need to be
  * calculated as an "averge" value, in the event that there are multiple,
  * differing values for an ad in a zone for an operation interval -- in
  * much the same way as is done in
  * OA_Dal_Maintenance_Priority::getPreviousAdDeliveryInfo() -- before
  * the total impressions requested value can be calculated.
  */
 function getDailyTargetingStatistics($id, $type, $oDate)
 {
     if (!$this->_testGetTargetingStatisticsDayParameters($id, $type, $oDate)) {
         return false;
     }
     // Ensure that, if a placement, the placement has advertisements
     $aAdIds = $this->_testGetTargetingStatisticsSpanPlacement($id, $type);
     if ($aAdIds === false) {
         return false;
     }
     // Prepare the results array
     $aResult = array();
     // Get a date for the start of the day
     $oStartDate = new Date();
     $oStartDate->copy($oDate);
     $oStartDate->setHour(0);
     $oStartDate->setMinute(0);
     $oStartDate->setSecond(0);
     // Get a date for the end of the day
     $oEndOfDayDate = new Date();
     $oEndOfDayDate->copy($oDate);
     $oEndOfDayDate->setHour(23);
     $oEndOfDayDate->setMinute(59);
     $oEndOfDayDate->setSecond(59);
     // Get the first operation interval of the day
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oStartDate);
     // Get dates to be used in date comparisons
     $oCompareDate = new Date();
     $oCompareDate->copy($aDates['start']);
     $oCompareEndDate = new Date();
     $oCompareEndDate->copy($oEndOfDayDate);
     while ($oCompareDate->before($oEndOfDayDate)) {
         // Get the operation interval ID
         $operationIntervalId = OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']);
         // Get the results for this operation interval
         $aResult[$operationIntervalId] = $this->getOperationIntervalTargetingStatistics($aAdIds, $type, $aDates['start'], $aDates['end']);
         if ($aResult[$operationIntervalId] === false) {
             return false;
         }
//.........这里部分代码省略.........
开发者ID:villos,项目名称:tree_admin,代码行数:101,代码来源:Targeting.php

示例6: array

 /**
  * A method to get the most recent details of contract campaign creative delivery
  * for a given list of creative/zone pairs set to deliver in the current
  * operation interval. Normally, the data will be retrieved from the previous
  * operation interval, but if no data exists for that creative/zone pair, then the
  * next previous operation interval will be tried, and so on, up to a limit
  * of MAX_PREVIOUS_AD_DELIVERY_INFO_LIMIT minutes (default is one week).
  *
  * - Requires that a current day/time (as a Date object) be registered
  *   with the OA_ServiceLocator (as "now").
  *
  * - Ignores creative ID 0 and zone ID 0 items, as these are reserved for
  *   direct selection, which is considered to be outside the process of
  *   priority compensation calculations (even though priority values for
  *   all contract campaign creatives are calculated and stored for the
  *   zone ID 0).
  *
  * Note: The logic of this method seems a little convoluted, and it is.
  * However, it needs to be. The reason being:
  *
  *  - If a contract campaign creative delivered in the previous operation interval,
  *    then it should have had a priority set in ad_zone_assoc (that's how OpenX
  *    knows to deliver contract campiang creatives, natch!). This should be the most
  *    recent entry in data_summary_ad_zone_assoc. So, the first step is to get the
  *    data for all contract campiang creatives that have delivered in the previous
  *    OI, and the associated prioritisation data.
  *  - If a contract campaign creative did not deliver, the prioritisation data set
  *    in the previous OI is still needed anyway (as it might have been *supposed*
  *    to deliver), so the second step is to get those creatives that had
  *    prioiritisation data set in the previous OI, but did not deliver.
  *  - Finally, as some creatives are limited by hour (for example), we want to
  *    to be able to get past prioritisation data for creatives that were
  *    disabled in the last OI, so, we need to look for creative/zone pairs
  *    that have not yet been found, and get BOTH the prioritisation AND the
  *    delivery data from the last OI when the creatives were active in the
  *    zones.
  *
  * This is why the method uses a complex, 3 step process!
  *
  * @access public
  * @param array $aCurrentZones An array of Zones, indexed by Zone ID, with each
  *                             Zone containing the Advert objects that are linked
  *                             to deliver in the zone, in the current operation
  *                             interval.
  * @return mixed An array of arrays of arrays, each one representing a set of
  *               ad/zone delivery information, indexed by ad ID and zone ID.
  *               Each sub-sub array, if present, has the format:
  *               array (
  *                  'ad_id'                         => integer
  *                  'zone_id'                       => integer
  *                  'required_impressions'          => integer
  *                  'requested_impressions'         => integer
  *                  'priority_factor'               => double
  *                  'past_zone_traffic_fraction'    => double
  *                  'impressions'                   => integer
  *               )
  *               Returns false when the current date/time is not set in the
  *               OA_ServiceLocator.
  */
 function &getPreviousAdDeliveryInfo($aCurrentZones)
 {
     OA::debug("  - Getting details of previous creative/zone delivery", PEAR_LOG_DEBUG);
     $aConf = $GLOBALS['_MAX']['CONF'];
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oDate =& $oServiceLocator->get('now');
     if (!$oDate) {
         return false;
     }
     $aAds = array();
     $aZones = array();
     $aZonesAds = array();
     $aPastDeliveryResult = array();
     $aPastPriorityResult = array();
     $aNonDeliveringPastPriorityResult = array();
     $aFinalResult = array();
     // Obtain the earliest existing interval_start date found in the
     // data_summary_ad_zone_assoc table
     $table = $this->_getTablename('data_summary_ad_zone_assoc');
     $query = "\n            SELECT\n                interval_start AS interval_start\n            FROM\n            {$table}\n            ORDER BY\n                interval_start\n            LIMIT\n                1";
     $rc = $this->oDbh->query($query);
     if (!PEAR::isError($rc) && $rc->numRows() == 1) {
         $aRow = $rc->fetchRow();
         $oEarliestPastPriorityRecordDate = new Date($aRow['interval_start']);
         // Create a new date that is the limit number of minutes ago
         $oLimitDate = new Date();
         $oLimitDate->copy($oDate);
         $oLimitDate->subtractSeconds(MAX_PREVIOUS_AD_DELIVERY_INFO_LIMIT * 60);
         // Is the earliest date before this date?
         if ($oEarliestPastPriorityRecordDate->before($oLimitDate)) {
             // Use the limit date instead
             $oEarliestPastPriorityRecordDate = new Date();
             $oEarliestPastPriorityRecordDate->copy($oLimitDate);
         }
     }
     // Obtain the operation interval ID, and the start and end dates of the previous
     // operation interval
     $currentOperationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($currentOperationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     // Obtain the ad ID, zone ID and number of impressions delivered for every ad/zone
//.........这里部分代码省略.........
开发者ID:ballistiq,项目名称:revive-adserver,代码行数:101,代码来源:Priority.php

示例7: Date

 /**
  * ???
  *
  * @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;
 }
开发者ID:Apeplazas,项目名称:plazadelatecnologia,代码行数:62,代码来源:Admin_DA.php

示例8: Date

<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>
开发者ID:MagnusA,项目名称:Date,代码行数:31,代码来源:example.php

示例9: array

 /**
  * A private method to convert the ZIF update type from _getUpdateTypeRequired() into
  * a range of operation intervals where all zones require their ZIF values to be updated.
  *
  * @access private
  * @param mixed $type The update type required. Possible values are the same as
  *                    those returned from the
  *                    {@link OA_Maintenance_Priority_AdServer_Task_ForecastZoneImpressions::getUpdateTypeRequired()}
  *                    method.
  * @return array An array of hashes where keys are operation interval IDs, and
  *               values are PEAR Dates. One element in the array indicates a
  *               contiguous range, two elements indicate a non-contiguous range.
  */
 function _getOperationIntervalRanges($type)
 {
     // Initialise result array
     $aResult = array();
     switch (true) {
         case is_bool($type) && $type === false:
             // Update none, return an empty array
             return $aResult;
         case is_bool($type) && $type === true:
             // Update all - need one week's worth of operation intervals up until the end
             // of the operation interval *after* the one that statistics have been updated
             // to, as we need to predict one interval ahead of now
             $oStatsDates = OX_OperationInterval::convertDateToNextOperationIntervalStartAndEndDates($this->oDateNow);
             $oStartDate = new Date();
             $oStartDate->copy($oStatsDates['start']);
             $oStartDate->subtractSeconds(SECONDS_PER_WEEK);
             $startId = OX_OperationInterval::convertDateToOperationIntervalID($oStartDate);
             $totalIntervals = OX_OperationInterval::operationIntervalsPerWeek();
             break;
         case is_array($type) && $type[0] < $type[1]:
             // A contiguous (ie. inter-week) range, where the first operation interval
             // ID is the lower bound, and the second operation interval ID is the upper
             // The start operation interval ID is the operation interval ID right after
             // the operation interval ID that priority was updated to (ie. $type[0])
             $aDates = OX_OperationInterval::convertDateToNextOperationIntervalStartAndEndDates($this->oPriorityUpdatedToDate);
             $oStartDate = $aDates['start'];
             $startId = OX_OperationInterval::nextOperationIntervalID($type[0], 1);
             $totalIntervals = $type[1] - $type[0];
             break;
         case is_array($type) && $type[0] > $type[1]:
             // A non-contiguous range, so calculate as above, but use the first operation
             // interval ID as the upper bound, and the second operation interval ID as the
             // lower bound in the proceeding week
             // The start operation interval ID is the operation interval ID right after
             // the operation interval ID that priority was updated to (ie. $type[0])
             $aDates = OX_OperationInterval::convertDateToNextOperationIntervalStartAndEndDates($this->oPriorityUpdatedToDate);
             $oStartDate = $aDates['start'];
             $startId = OX_OperationInterval::nextOperationIntervalID($type[0], 1);
             $totalIntervals = OX_OperationInterval::operationIntervalsPerWeek() - $type[0] + $type[1];
             break;
         default:
             OA::debug('OA_Maintenance_Priority_AdServer_Task_ForecastZoneImpressions::getOperationIntRangeByType() called with unexpected type, exiting', PEAR_LOG_CRIT);
             exit;
     }
     // Build the update range array
     $aRange = array();
     $totalIntervalPerWeek = OX_OperationInterval::operationIntervalsPerWeek();
     for ($x = $startId, $y = 0; $y < $totalIntervals; $x++, $y++) {
         if ($x == $totalIntervalPerWeek) {
             $x = 0;
         }
         $aDates = array();
         $aDates['start'] = new Date($oStartDate);
         //->format('%Y-%m-%d %H:%M:%S');
         $oEndDate = new Date();
         $oEndDate->copy($oStartDate);
         $oEndDate->addSeconds(OX_OperationInterval::secondsPerOperationInterval() - 1);
         $aDates['end'] = $oEndDate;
         //->format('%Y-%m-%d %H:%M:%S');
         unset($oEndDate);
         $aRange[$x] = $aDates;
         $oStartDate->addSeconds(OX_OperationInterval::secondsPerOperationInterval());
     }
     // Is the update range array a contiguous (inter-weeek) range?
     if (array_key_exists($totalIntervalPerWeek - 1, $aRange) && array_key_exists(0, $aRange)) {
         // The range contains the first and the last operation interval IDs, is the
         // last date before the first date?
         $oFirstIntervalStartDate = new Date($aRange[0]['start']);
         $oLastIntervalStartDate = new Date($aRange[$totalIntervalPerWeek - 1]['start']);
         if ($oLastIntervalStartDate->before($oFirstIntervalStartDate)) {
             // It's a non-contiguous range, so split into two ranges
             $aRange1 = array();
             $aRange2 = array();
             for ($x = $startId; $x < $totalIntervalPerWeek; $x++) {
                 $aRange1[$x] = $aRange[$x];
             }
             for ($x = 0; $x < $startId; $x++) {
                 if (isset($aRange[$x])) {
                     $aRange2[$x] = $aRange[$x];
                 }
             }
             $aResult[] = $aRange1;
             $aResult[] = $aRange2;
             return $aResult;
         }
     }
     $aResult[] = $aRange;
//.........这里部分代码省略.........
开发者ID:villos,项目名称:tree_admin,代码行数:101,代码来源:ForecastZoneImpressions.php

示例10: Date

    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();
开发者ID:akirsch,项目名称:revive-adserver,代码行数:31,代码来源:republish.php

示例11: updateExpandedDates

 private function updateExpandedDates($start, $end, $updateTransferal = true)
 {
     if ($this->beginDate->equals($this->originalBeginDate)) {
         return;
     }
     $accountManager = new AccountManager($this->badgerDb);
     $compareAccount = $accountManager->getAccountById($this->account->getId());
     $compareAccount->setFilter(array(array('key' => 'plannedTransactionId', 'op' => 'eq', 'val' => $this->id), array('key' => 'valutaDate', 'op' => 'ge', 'val' => new Date($start)), array('key' => 'valutaDate', 'op' => 'le', 'val' => new Date($end))));
     $compareAccount->setOrder(array(array('key' => 'valutaDate', 'dir' => 'asc')));
     $date = new Date($this->beginDate);
     $originalDate = new Date($this->originalBeginDate);
     $windowStart = $this->previousOccurence(new Date($originalDate), $this->originalBeginDate);
     $windowEnd = $this->nextOccurence(new Date($originalDate), $this->originalBeginDate);
     while (!$date->after($windowStart)) {
         $date = $this->nextOccurence($date);
     }
     while ($currentCompareTransaction = $compareAccount->getNextTransaction()) {
         while ($originalDate->before($currentCompareTransaction->getValutaDate())) {
             $originalDate = $this->nextOccurence($originalDate, $this->originalBeginDate);
             $date = $this->nextOccurence($date);
         }
         if ($originalDate->equals($currentCompareTransaction->getValutaDate())) {
             $currentCompareTransaction->setValutaDate(new Date($date));
         }
     }
     //while compareTransactions
     if ($updateTransferal && $this->transferalTransaction) {
         $this->transferalTransaction->updateExpandedDates($start, $end, false);
     }
 }
开发者ID:BackupTheBerlios,项目名称:badger-svn,代码行数:30,代码来源:PlannedTransaction.class.php

示例12: transferFormerFinishedTransactions

function transferFormerFinishedTransactions($account)
{
    global $us;
    if ($us->getProperty('autoExpandPlannedTransactions') == false) {
        return;
    }
    $now = new Date();
    $now->setHour(0);
    $now->setMinute(0);
    $now->setSecond(0);
    $account->setType('planned');
    $account->setFilter(array(array('key' => 'beginDate', 'op' => 'le', 'val' => $now)));
    try {
        $lastInsertDate = $us->getProperty('Account_' . $account->getId() . '_LastTransferFormerFinishedTransactions');
    } catch (BadgerException $ex) {
        $lastInsertDate = new Date('1000-01-01');
    }
    $us->setProperty('Account_' . $account->getId() . '_LastTransferFormerFinishedTransactions', $now);
    if (!$lastInsertDate->before($now)) {
        return;
    }
    while ($currentTransaction = $account->getNextPlannedTransaction()) {
        transferFinishedTransactions($account, $currentTransaction, $lastInsertDate);
    }
}
开发者ID:BackupTheBerlios,项目名称:badger-svn,代码行数:25,代码来源:accountCommon.php

示例13: transferFormerFinishedTransactions

function transferFormerFinishedTransactions($account)
{
    global $us;
    if ($us->getProperty('autoExpandPlannedTransactions') == false) {
        return;
    }
    $now = new Date();
    $now->setHour(0);
    $now->setMinute(0);
    $now->setSecond(0);
    $account->setType('planned');
    $account->setFilter(array(array('key' => 'beginDate', 'op' => 'le', 'val' => $now)));
    try {
        $lastInsertDate = $us->getProperty('Account_' . $account->getId() . '_LastTransferFormerFinishedTransactions');
    } catch (BadgerException $ex) {
        $lastInsertDate = new Date('1000-01-01');
    }
    $us->setProperty('Account_' . $account->getId() . '_LastTransferFormerFinishedTransactions', $now);
    if (!$lastInsertDate->before($now)) {
        return;
    }
    while ($currentTransaction = $account->getNextPlannedTransaction()) {
        $date = new Date($currentTransaction->getBeginDate());
        $dayOfMonth = $date->getDay();
        //While we are before now and the end date of this transaction
        while (!$date->after($now) && !$date->after(is_null($tmp = $currentTransaction->getEndDate()) ? new Date('9999-12-31') : $tmp)) {
            if ($date->after($lastInsertDate)) {
                $account->addFinishedTransaction($currentTransaction->getAmount(), $currentTransaction->getTitle(), $currentTransaction->getDescription(), new Date($date), $currentTransaction->getTransactionPartner(), $currentTransaction->getCategory(), $currentTransaction->getOutsideCapital(), false, true);
            }
            //do the date calculation
            switch ($currentTransaction->getRepeatUnit()) {
                case 'day':
                    $date->addSeconds($currentTransaction->getRepeatFrequency() * 24 * 60 * 60);
                    break;
                case 'week':
                    $date->addSeconds($currentTransaction->getRepeatFrequency() * 7 * 24 * 60 * 60);
                    break;
                case 'month':
                    //Set the month
                    $date = new Date(Date_Calc::endOfMonthBySpan($currentTransaction->getRepeatFrequency(), $date->getMonth(), $date->getYear(), '%Y-%m-%d'));
                    //And count back as far as the last valid day of this month
                    while ($date->getDay() > $dayOfMonth) {
                        $date->subtractSeconds(24 * 60 * 60);
                    }
                    break;
                case 'year':
                    $newYear = $date->getYear() + $currentTransaction->getRepeatFrequency();
                    if ($dayOfMonth == 29 && $date->getMonth() == 2 && !Date_Calc::isLeapYear($newYear)) {
                        $date->setDay(28);
                    } else {
                        $date->setDay($dayOfMonth);
                    }
                    $date->setYear($newYear);
                    break;
                default:
                    throw new BadgerException('Account', 'IllegalRepeatUnit', $currentTransaction->getRepeatUnit());
                    exit;
            }
        }
    }
}
开发者ID:BackupTheBerlios,项目名称:badger-svn,代码行数:61,代码来源:accountCommon.php

示例14: getDailyAmount

/**
 * Returns the Account balance for $account at the end of each day between $startDate and $endDate.
 * 
 * Considers the planned transactions of $account.
 * 
 * @param object $account The Account object for which the balance should be calculated. 
 * It should be 'fresh', i. e. no transactions of any type should have been fetched from it.
 * @param object $startDate The first date the balance should be calculated for as Date object.
 * @param object $endDate The last date the balance should be calculated for as Date object.
 * @return array Array of Amount objects corresponding to the balance of $account at each day between
 * $startDate and $endDate. The array keys are the dates as ISO-String (yyyy-mm-dd). 
 */
function getDailyAmount($account, $startDate, $endDate, $isoDates = true, $startWithBalance = false, $includePlannedTransactions = false)
{
    global $badgerDb;
    $account->setTargetFutureCalcDate($endDate);
    $account->setOrder(array(array('key' => 'valutaDate', 'dir' => 'asc')));
    if (!$includePlannedTransactions) {
        $account->setType('finished');
    }
    $result = array();
    $startDate->setHour(0);
    $startDate->setMinute(0);
    $startDate->setSecond(0);
    $endDate->setHour(0);
    $endDate->setMinute(0);
    $endDate->setSecond(0);
    $currentDate = new Date($startDate);
    $currentAmount = new Amount();
    $firstRun = true;
    //foreach transaction
    while ($currentTransaction = $account->getNextTransaction()) {
        if ($currentDate->after($endDate)) {
            //we reached $endDAte
            break;
        }
        if ($firstRun && $startWithBalance) {
            $currentAmount = new Amount($currentTransaction->getBalance());
            $currentAmount->sub($currentTransaction->getAmount());
            $firstRun = false;
        }
        //fill all dates between last and this transaction with the old amount
        while (is_null($tmp = $currentTransaction->getValutaDate()) ? false : $currentDate->before($tmp)) {
            if ($isoDates) {
                $key = $currentDate->getDate();
            } else {
                $key = $currentDate->getTime();
            }
            $result[$key] = new Amount($currentAmount);
            $currentDate->addSeconds(24 * 60 * 60);
            if ($currentDate->after($endDate)) {
                //we reached $endDAte
                break;
            }
        }
        $currentAmount->add($currentTransaction->getAmount());
    }
    if ($firstRun && $startWithBalance) {
        $newAccountManager = new AccountManager($badgerDb);
        $newAccount = $newAccountManager->getAccountById($account->getId());
        $newAccount->setOrder(array(array('key' => 'valutaDate', 'dir' => 'asc')));
        while ($newTransaction = $newAccount->getNextTransaction()) {
            $currentDate = $newTransaction->getValutaDate();
            if ($currentDate->after($startDate)) {
                //we reached $endDAte
                break;
            }
            $currentAmount = new Amount($newTransaction->getBalance());
        }
        $currentDate = new Date($startDate);
        if ($isoDates) {
            $key = $currentDate->getDate();
        } else {
            $key = $currentDate->getTime();
        }
        $result[$key] = new Amount($currentAmount);
    }
    //fill all dates after the last transaction with the newest amount
    while (Date::compare($currentDate, $endDate) <= 0) {
        if ($isoDates) {
            $key = $currentDate->getDate();
        } else {
            $key = $currentDate->getTime();
        }
        $result[$key] = new Amount($currentAmount);
        $currentDate->addSeconds(24 * 60 * 60);
    }
    return $result;
}
开发者ID:BackupTheBerlios,项目名称:badger-svn,代码行数:89,代码来源:accountCommon.php

示例15: array

 /**
  * A method to get the most recent details of advertisement delivery for
  * a given list of advertisement/zone pairs set to deliver in the current
  * operation interval. Normally, the data will be retrieved from the previous
  * operation interval, but if no data exists for that ad/zone pair, then the
  * next previous operation interval will be tried, and so on, up to a limit
  * of MAX_PREVIOUS_AD_DELIVERY_INFO_LIMIT minutes. (The default is one week.)
  *
  * Requires that a current day/time (as a Date object) be registered
  * with the OA_ServiceLocator (as "now").
  *
  * Note: The logic of this method seems a little convoluted, and it is.
  * However, it needs to be. The reason being:
  *  - If an ad delivered in the previous operation interval, it should
  *    have a priority set in ad_zone_assoc. This should be the most
  *    recent entry in data_summary_ad_zone_assoc. So, the first step is
  *    to get the data for all ads that have delivered in the previous
  *    OI, and the associated prioritisation data.
  *  - If an ad did not deliver, the prioritisation data set in the
  *    previous OI is still needed, so the second step is to get those
  *    ads that had prioiritisation data set in the previous OI, but did
  *    not deliver.
  *  - Finally, as some ads are limited by hour (for example), we want to
  *    to be able to get past prioritisation data for ads that were
  *    disabled in the last OI, so, we need to look for ad/zone pairs
  *    that have not yet been found, and get BOTH the prioritisation and
  *    delivery data from the last OI when the ads were active in the
  *    zones.
  * This is why the method uses a complex, 3 step process!
  *
  * @access public
  * @param array $aCurrentZones An array of Zones, indexed by Zone ID, with each
  *                             Zone containing the Advert objects that are linked
  *                             to deliver in the zone, in the current operation
  *                             interval.
  * @return mixed An array of arrays of arrays, each one representing a set of
  *               ad/zone delivery information, indexed by ad ID and zone ID.
  *               Each sub-sub array, if present, has the format:
  *               array (
  *                  'ad_id'                         => integer
  *                  'zone_id'                       => integer
  *                  'required_impressions'          => integer
  *                  'requested_impressions'         => integer
  *                  'priority_factor'               => double
  *                  'past_zone_traffic_fraction'    => double
  *                  'impressions'                   => integer
  *               )
  *               Returns false when the current date/time is not set in the
  *               OA_ServiceLocator.
  */
 function &getPreviousAdDeliveryInfo($aCurrentZones)
 {
     OA::debug("  - Getting details of previous ad/zone delivery", PEAR_LOG_DEBUG);
     $aConf = $GLOBALS['_MAX']['CONF'];
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oDate =& $oServiceLocator->get('now');
     if (!$oDate) {
         return false;
     }
     $aAds = array();
     $aZones = array();
     $aZonesAds = array();
     $aPastDeliveryResult = array();
     $aPastPriorityResult = array();
     $aNonDeliveringPastPriorityResult = array();
     $aFinalResult = array();
     // Obtain the earliest existing interval_start date found in the
     // data_summary_ad_zone_assoc table
     $table = $this->_getTablename('data_summary_ad_zone_assoc');
     $query = "\n            SELECT\n                interval_start AS interval_start\n            FROM\n                {$table}\n            ORDER BY\n                interval_start\n            LIMIT\n                1";
     $rc = $this->oDbh->query($query);
     if (!PEAR::isError($rc) && $rc->numRows() == 1) {
         $aRow = $rc->fetchRow();
         $oEarliestPastPriorityRecordDate = new Date($aRow['interval_start']);
         // Create a new date that is the limit number of minutes ago
         $oLimitDate = new Date();
         $oLimitDate->copy($oDate);
         $oLimitDate->subtractSeconds(MAX_PREVIOUS_AD_DELIVERY_INFO_LIMIT * 60);
         // Is the earliest date before this date?
         if ($oEarliestPastPriorityRecordDate->before($oLimitDate)) {
             // Use the limit date instead
             $oEarliestPastPriorityRecordDate = new Date();
             $oEarliestPastPriorityRecordDate->copy($oLimitDate);
         }
     }
     // Obtain the operation interval ID, and the start and end dates of the previous
     // operation interval
     $currentOperationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($currentOperationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     // Obtain the ad ID, zone ID and number of impressions delivered for every ad/zone
     // combination that delivered impressions in the previous operation interval
     OA::debug("  - Getting details of ad/zone pairs that delivered last OI", PEAR_LOG_DEBUG);
     $table = $this->_getTablename('data_intermediate_ad');
     $query = "\n            SELECT\n                ad_id AS ad_id,\n                zone_id AS zone_id,\n                SUM(impressions) AS impressions\n            FROM\n                {$table}\n            WHERE\n                operation_interval = {$aConf['maintenance']['operationInterval']}\n                AND operation_interval_id = {$previousOperationIntervalID}\n                AND interval_start = '" . $aDates['start']->format('%Y-%m-%d %H:%M:%S') . "'\n                AND interval_end = '" . $aDates['end']->format('%Y-%m-%d %H:%M:%S') . "'\n                AND ad_id != 0\n                AND zone_id != 0\n            GROUP BY\n                ad_id,\n                zone_id\n            ORDER BY\n                ad_id,\n                zone_id";
     $rc = $this->oDbh->query($query);
     while ($aRow = $rc->fetchRow()) {
         // Store the ad ID as being one that has delivered
         $aAds[$aRow['ad_id']] = $aRow['ad_id'];
         // Store the zone ID as one that had impressions in it
//.........这里部分代码省略.........
开发者ID:villos,项目名称:tree_admin,代码行数:101,代码来源:Priority.php


注:本文中的Date::before方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。