本文整理汇总了PHP中Date::compare方法的典型用法代码示例。如果您正苦于以下问题:PHP Date::compare方法的具体用法?PHP Date::compare怎么用?PHP Date::compare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Date
的用法示例。
在下文中一共展示了Date::compare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDateComparsion
public function testDateComparsion()
{
$date1 = Date::create(mktime(0, 0, 0, 1, 1, 2009));
$date2 = Date::create(mktime(1, 0, 0, 1, 1, 2009));
$this->assertEquals($date1, $date2);
$this->assertEquals(Date::compare($date1, $date2), 0);
return $this;
}
示例2: 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)
{
$account->setTargetFutureCalcDate($endDate);
$account->setOrder(array(array('key' => 'valutaDate', 'dir' => 'asc')));
$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();
//foreach transaction
while ($currentTransaction = $account->getNextTransaction()) {
if ($currentDate->after($endDate)) {
//we reached $endDAte
break;
}
//fill all dates between last and this transaction with the old amount
while (is_null($tmp = $currentTransaction->getValutaDate()) ? false : $currentDate->before($tmp)) {
$result[$currentDate->getDate()] = new Amount($currentAmount);
$currentDate->addSeconds(24 * 60 * 60);
if ($currentDate->after($endDate)) {
//we reached $endDAte
break;
}
}
$currentAmount->add($currentTransaction->getAmount());
}
//fill all dates after the last transaction with the newest amount
while (Date::compare($currentDate, $endDate) <= 0) {
$result[$currentDate->getDate()] = new Amount($currentAmount);
$currentDate->addSeconds(24 * 60 * 60);
}
return $result;
}
示例3: deliveryBlocked
/**
* A method to determine if the delivery limitation stored will prevent an
* ad from delivering or not, given a time/date.
*
* @abstract
* @param object $oDate PEAR:Date, represeting the time/date to test if the ACL would
* block delivery at that point in time.
* @return mixed A boolean (true if the ad is BLOCKED (i.e. will NOT deliver), false
* if the ad is NOT BLOCKED (i.e. WILL deliver), or a PEAR::Error.
*/
function deliveryBlocked($oDate)
{
if (!is_a($oDate, 'Date')) {
return MAX::raiseError('Parameter passed to OA_Maintenance_Priority_DeliveryLimitation_Date is not a PEAR::Date object', MAX_ERROR_INVALIDARGS);
}
// Clone the date
$oCloneDate = new Date();
$oCloneDate->copy($oDate);
// Reset time part of date
$oCloneDate->setHour(0);
$oCloneDate->setMinute(0);
$oCloneDate->setSecond(0);
// 0 if the dates are equal;
// -1 if $oCloneDate is before $this->date;
// 1 if $oCloneDate is after $this->date
$val = Date::compare($oCloneDate, $this->date);
switch ($this->comparison) {
case '==':
return $val == 0;
break;
case '!=':
return $val != 0;
break;
case '<=':
return $val == -1 || $val == 0;
break;
case '>=':
return $val == 1 || $val == 0;
break;
case '<':
return $val == -1;
break;
case '>':
return $val == 1;
break;
}
return 0;
}
示例4: compareMarrDate
/**
* Static helper function to sort an array of families by marriage date
*
* @param Family $x
* @param Family $y
*
* @return int
*/
public static function compareMarrDate(Family $x, Family $y)
{
return Date::compare($x->getMarriageDate(), $y->getMarriageDate());
}
示例5: getNextAssignee
/**
* Retrieves the next assignee in the given project's round robin queue.
*
* @access public
* @param integer $prj_id The project ID
* @return integer The assignee's user ID
*/
function getNextAssignee($prj_id)
{
// get the full list of users for the given project
list($blackout_start, $blackout_end, $users) = Round_Robin::getUsersByProject($prj_id);
if (count($users) == 0) {
return 0;
} else {
$user_ids = array_keys($users);
$next_usr_id = 0;
foreach ($users as $usr_id => $details) {
if ($details['is_next']) {
$next_usr_id = $usr_id;
break;
}
}
// if no user is currently set as the 'next' assignee,
// then just get the first one in the list
if (empty($next_usr_id)) {
$next_usr_id = $user_ids[0];
}
// counter to keep the number of times we found an invalid user
$ignored_users = 0;
// check the blackout hours
do {
$user = new Date(Date_API::getCurrentUnixTimestampGMT());
$user->convertTZById($users[$next_usr_id]['timezone']);
list($today, $tomorrow) = Round_Robin::getBlackoutDates(&$user, $blackout_start, $blackout_end);
$first = new Date($today . ' ' . $blackout_start);
$first->setTZById($users[$next_usr_id]['timezone']);
$second = new Date($tomorrow . ' ' . $blackout_end);
$second->setTZById($users[$next_usr_id]['timezone']);
if (Date::compare($first, $user) == -1 && Date::compare($user, $second) == -1) {
$ignored_users++;
$current_index = array_search($next_usr_id, $user_ids);
// if we reached the end of the list of users and none of them
// was a valid one, then just select the first one
// however, we want to complete at least one full iteration over the list of users
// that is, if we didn't start checking the users in the beginning of the list,
// then do another run over the users just in case
if ($ignored_users >= count($user_ids) && $current_index == count($user_ids) - 1) {
$assignee = $user_ids[0];
break;
}
// if we reached the end of the list, and we still didn't find an user,
// then go back to the beginning of the list one last time
if ($current_index == count($user_ids) - 1) {
$current_index = 0;
$next_usr_id = $user_ids[++$current_index];
$found = 0;
continue;
}
$next_usr_id = $user_ids[++$current_index];
$found = 0;
} else {
$assignee = $next_usr_id;
$found = 1;
}
} while (!$found);
// mark the next user in the list as the 'next' assignment
$assignee_index = array_search($assignee, $user_ids);
if ($assignee_index == count($user_ids) - 1) {
$next_assignee = $user_ids[0];
} else {
$next_assignee = $user_ids[++$assignee_index];
}
Round_Robin::markNextAssignee($prj_id, $next_assignee);
return $assignee;
}
}
示例6: getTaskLinks
/**
* Sub-function to collect tasks within a period
*
* @param Date the starting date of the period
* @param Date the ending date of the period
* @param array by-ref an array of links to append new items to
* @param int the length to truncate entries by
* @param int the company id to filter by
* @author Andrew Eddie <eddieajau@users.sourceforge.net>
*/
function getTaskLinks($startPeriod, $endPeriod, &$links, $strMaxLen, $company_id = 0)
{
global $a, $AppUI, $dPconfig;
$tasks = CTask::getTasksForPeriod($startPeriod, $endPeriod, $company_id, $AppUI->user_id, true);
$durnTypes = dPgetSysVal('TaskDurationType');
$link = array();
$sid = 3600 * 24;
// assemble the links for the tasks
foreach ($tasks as $row) {
// the link
$link['href'] = "?m=tasks&a=view&task_id=" . $row['task_id'];
$link['alt'] = $row['project_name'] . ":\n" . $row['task_name'];
// the link text
if (strlen($row['task_name']) > $strMaxLen) {
$row['task_name'] = substr($row['task_name'], 0, $strMaxLen) . '...';
}
$link['text'] = '<span style="color:' . bestColor($row['color']) . ';background-color:#' . $row['color'] . '">' . $row['task_name'] . '</span>';
// determine which day(s) to display the task
$start = new CDate($row['task_start_date']);
$end = $row['task_end_date'] ? new CDate($row['task_end_date']) : null;
$durn = $row['task_duration'];
$durnType = $row['task_duration_type'];
if (($start->after($startPeriod) || $start->equals($startPeriod)) && ($start->before($endPeriod) || $start->equals($endPeriod))) {
$temp = $link;
$temp['alt'] = "START [" . $row['task_duration'] . ' ' . $AppUI->_($durnTypes[$row['task_duration_type']]) . "]\n" . $link['alt'];
if ($a != 'day_view') {
$temp['text'] = dPshowImage(dPfindImage('block-start-16.png')) . $temp['text'];
}
$links[$start->format(FMT_TIMESTAMP_DATE)][] = $temp;
}
if ($end && $end->after($startPeriod) && $end->before($endPeriod) && $start->before($end)) {
$temp = $link;
$temp['alt'] = "FINISH\n" . $link['alt'];
if ($a != 'day_view') {
$temp['text'] .= dPshowImage(dPfindImage('block-end-16.png'));
}
$links[$end->format(FMT_TIMESTAMP_DATE)][] = $temp;
}
// convert duration to days
if ($durnType < 24.0) {
if ($durn > $dPconfig['daily_working_hours']) {
$durn /= $dPconfig['daily_working_hours'];
} else {
$durn = 0.0;
}
} else {
$durn *= $durnType / 24.0;
}
// fill in between start and finish based on duration
// notes:
// start date is not in a future month, must be this or past month
// start date is counted as one days work
// business days are not taken into account
$target = $start;
$target->addSeconds($durn * $sid);
if (Date::compare($target, $startPeriod) < 0) {
continue;
}
if (Date::compare($start, $startPeriod) > 0) {
$temp = $start;
$temp->addSeconds($sid);
} else {
$temp = $startPeriod;
}
// Optimised for speed, AJD.
while (Date::compare($endPeriod, $temp) > 0 && Date::compare($target, $temp) > 0 && ($end == null || $temp->before($end))) {
$links[$temp->format(FMT_TIMESTAMP_DATE)][] = $link;
$temp->addSeconds($sid);
}
}
}
示例7: getDaysLeftString
//.........这里部分代码省略.........
$oNow = new Date($now);
$oNow->setHour(0);
$oNow->setMinute(0);
$oNow->setSecond(0);
$oDate = new Date($aCampaignData['expire_time']);
$oDate->setTZbyID('UTC');
$oDate->convertTZ($oNow->tz);
$oDate->setHour(0);
$oDate->setMinute(0);
$oDate->setSecond(0);
$oSpan = new Date_Span();
$oSpan->setFromDateDiff($oNow, $oDate);
$aCampaignData['expire_f'] = $oDate->format($date_format);
$aCampaignData['days_left'] = $oSpan->toDays() * ($oDate->before($oNow) ? -1 : 1);
}
$oDbh = OA_DB::singleton();
$tableB = $oDbh->quoteIdentifier($prefix . 'banners', true);
$tableD = $oDbh->quoteIdentifier($prefix . 'data_intermediate_ad', true);
// Define array to return the expiration dates (if they exist)
$aReturn = array('estimatedExpiration' => '', 'campaignExpiration' => '');
// Does the campaign have lifetime impression targets?
// If yes, try to get a stimated expiration date
if ($aCampaignData['impressions'] > 0) {
$query = "\n \t SELECT\n \t SUM(dia.impressions) AS delivered,\n \t DATE_FORMAT(MIN(dia.date_time), '%Y-%m-%d') AS day_of_first\n \t FROM\n \t {$tableD} AS dia,\n \t {$tableB} AS b\n \t WHERE\n \t dia.ad_id = b.bannerid\n \t AND\n \t b.campaignid = " . DBC::makeLiteral($campaignId);
$rsImpressions = DBC::FindRecord($query);
if ($rsImpressions) {
$aImpressions = $rsImpressions->toArray();
// Get the number of days until the campaign will end
// based on the impression target delivery data
$aExpiration = $this->_calculateRemainingDays($aImpressions, $aCampaignData['impressions']);
}
} elseif ($aCampaignData['clicks'] > 0) {
$query = "\n \t SELECT\n \t SUM(dia.clicks) AS delivered,\n \t DATE_FORMAT(MIN(dia.date_time), '%Y-%m-%d') AS day_of_first\n \t FROM\n \t {$tableD} AS dia,\n \t {$tableB} AS b\n \t WHERE\n \t dia.ad_id = b.bannerid\n \t AND\n \t b.campaignid = " . DBC::makeLiteral($campaignId);
$rsClicks = DBC::FindRecord($query);
if ($rsClicks) {
$aClicks = $rsClicks->toArray();
// Get the number of days until the campaign will end
// based on the click target delivery data
$aExpiration = $this->_calculateRemainingDays($aClicks, $aCampaignData['clicks']);
}
} elseif ($aCampaignData['conversions'] > 0) {
$query = "\n \t SELECT\n \t SUM(dia.conversions) AS delivered,\n \t DATE_FORMAT(MIN(dia.date_time), '%Y-%m-%d') AS day_of_first\n \t FROM\n \t {$tableD} AS dia,\n \t {$tableB} AS b\n \t WHERE\n \t dia.ad_id = b.bannerid\n \t AND\n \t b.campaignid = " . DBC::makeLiteral($campaignId);
$rsConversions = DBC::FindRecord($query);
if ($rsConversions) {
$aConversions = $rsConversions->toArray();
// Get the number of days until the campaign will end
// based on the conversion target delivery data
$aExpiration = $this->_calculateRemainingDays($aConversions, $aCampaignData['conversions']);
}
}
// flags to control if the campaign expiration date and
// the estimated expiration date are going to be showed
$existExpirationDate = false;
$showEtimatedDate = false;
// is there a expiration date?
if (!empty($aCampaignData['expire_time'])) {
$existExpirationDate = true;
}
if ($existExpirationDate) {
// has the expiration date been reached?
if ((int) $aCampaignData['days_left'] < 0) {
$aReturn['campaignExpiration'] = $strCampaignStop . ": " . $aCampaignData['expire_f'];
$aReturn['campaignExpiration'] = $aReturn['campaignExpiration'] . " (" . abs((int) round($aCampaignData['days_left'])) . " {$strDaysAgo})";
} else {
$aReturn['campaignExpiration'] = $strExpirationDate . ": " . $aCampaignData['expire_f'];
$aReturn['campaignExpiration'] = $aReturn['campaignExpiration'] . " (" . $strDaysLeft . ": " . round($aCampaignData['days_left']) . ")";
}
} else {
$aReturn['campaignExpiration'] = $strNoExpiration;
}
// There is a estimated expiration date?
// If yes, check if the campaign expiration date is set up and compare
// both expiration dates to show only relevant estimated expiration dates
if (!empty($aExpiration)) {
if ($existExpirationDate == true) {
if (round($aCampaignData['days_left']) >= 0) {
$campaignExpirationDate = new Date($aCampaignData['expire_time']);
$aExpiration['date']->hour = 0;
$aExpiration['date']->minute = 0;
$aExpiration['date']->second = 0;
$aExpiration['date']->partsecond = 0;
$compareDate = Date::compare($aExpiration['date'], $campaignExpirationDate);
// the estimated expiration date is previous or equal to the
// campaign expiration date and hasn't the expiration date been reached?
if ($compareDate <= 0 && (int) $aCampaignData['days_left'] >= 0) {
$showEtimatedDate = true;
}
}
} else {
$showEtimatedDate = true;
}
} elseif ($existExpirationDate && round($aCampaignData['days_left']) >= 0 || !$existExpirationDate) {
$aReturn['estimatedExpiration'] = $strEstimated . ": " . $strNoExpirationEstimation;
}
if ($showEtimatedDate) {
$aExpiration['daysLeft'] = phpAds_formatNumber($aExpiration['daysLeft']);
$aReturn['estimatedExpiration'] = $strEstimated . ": " . $aExpiration['date_f'] . " (" . $strDaysLeft . ": " . $aExpiration['daysLeft'] . ")";
}
return $aReturn;
}
示例8: create_conference
function create_conference() {
global $log, $spUser,$_POST,$data;
$msgs = array();
// check the title
if (!$_POST[conference_name] ) {
$msgs[] = "Conference must have a title";
return $msgs ;
}
// validate the date ...
if (($conference_uts = strtotime($_POST[conference_date]))===false ) {
$msgs[] = "Conference date is an Invalid date.";
return $msgs ;
}
list ($m,$d,$y) = split('-',$_POST[conference_date]);
// Make date objects...
$confDate = new Date();
$confDate->setMonth($m);
$confDate->setYear($y);
$confDate->setDay($d);
$confDate->setHour(0);
$confDate->setMinute(0);
$confDate->setSecond(0);
$beginTime = $confDate;
$endTime = $confDate;
list ($beginHour,$beginMinute) = split(':', $_POST[begin_time] );
list ($endHour,$endMinute) = split(':', $_POST[end_time] );
$beginTime->setHour($beginHour);
$beginTime->setMinute($beginMinute);
$endTime->setHour($endHour);
$endTime->setMinute($endMinute);
// see if it's the past
if ($endTime->isPast() ){
$msgs[] = "Conference date is in the Past.";
return $msgs ;
}
// Make sure the end time is not less than the begin time
if (Date::compare($endTime, $beginTime) != 1 ){
$msgs[] = "Start time must be before end time.";
return $msgs ;
}
// create a new Conference object
$conference = new Conference($data->db, $spUser->username,$spUser->domain);
// get the user's company Id and load the companies constraints
$conference->getCompanyId();
$conference->loadConstraints() ;
// set the date objects.
$conference->conferenceDate = $confDate;
$conference->beginTime = $beginTime;
$conference->endTime = $endTime;
$conference->conferenceName = $_POST[conference_name] ;
// Is the conference too long
if (!$conference->isMaxTime()) {
$msgs[] = "Your conference exceeds the maximum amount of minutes.";
return $msgs ;
}
// Are there other conferences scheduled for this time.
if (!$conference->isMaxConcurrent()) {
$msgs[] = "Your company has other conferences scheduled for this time.";
return $msgs ;
}
$error = "nay!";
if ($conference->create($error) ) {
$msgs[] = "Conference created id = " . $conference->conferenceId;
Header("Location: conference.php?msg=Conference created ") ;
} else {
$msgs[] = "Failed to create conference. ";
$msgs[] = "$error";
}
$owner = new Invitee($data->db, $conference->conferenceId);
$owner->domain = $spUser->domain;
$owner->username = $spUser->username;
$owner->companyId = $conference->companyId;
$owner->inviteeEmail = $spUser->dbFields[email_address] ;
$owner->ownerFlag = 1;
$owner->inviteeName = $spUser->dbFields[first_name] . " " . $spUser->dbFields[last_name] ;
// genereate that unique code
$owner->generateInviteeCode();
$owner->create();
$owner->sendNotify();
return $msgs ;
}
示例9: getGPC
require_once BADGER_ROOT . '/includes/fileHeaderBackEnd.inc.php';
require_once BADGER_ROOT . '/modules/account/accountCommon.php';
//include charts.php to access the InsertChart function
require_once BADGER_ROOT . "/includes/charts/charts.php";
header('Content-Type: text/xml');
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
# validate if date is in future
$selectedDate = getGPC($_POST, 'endDate', 'DateFormatted');
$today = new Date();
$noFutureDates = NULL;
$noLowerLimit = NULL;
$noUpperLimit = NULL;
$noGraphChosen = NULL;
$insertChart = NULL;
//to avoid a date in the past or the same date as today
if ($today->compare($today, $selectedDate) != 1) {
$selectedSavingTarget = getGPC($_POST, 'savingTarget', 'AmountFormatted');
$savingTarget = $selectedSavingTarget->get();
$endDate = $selectedDate->getDate();
$account = getGPC($_POST, 'selectedAccount', 'int');
//save selected account as standard account
$us->setProperty('forecastStandardAccount', $account);
$selectedPocketMoney1 = getGPC($_POST, 'pocketmoney1', 'AmountFormatted');
$pocketMoney1 = $selectedPocketMoney1->get();
$viewPocketMoney1 = $selectedPocketMoney1->getFormatted();
$selectedPocketMoney2 = getGPC($_POST, 'pocketmoney2', 'AmountFormatted');
$pocketMoney2 = $selectedPocketMoney2->get();
$viewPocketMoney2 = $selectedPocketMoney2->getFormatted();
$dailyPocketMoneyLabel = NULL;
$dailyPocketMoneyValue = NULL;
$dailyPocketMoneyToolTip = NULL;
示例10: isActive
/**
* Takes a user's session identifier and session expiry
* timestamp and checks to see if they represent a currently
* active session. Note: This method does not verify that
* $session_id is a valid session identifier, but rather
* expects these values to have come from a database source
* and hence be validated prior to this method being called.
* If the $session_id value is empty however, it will return
* false. Compares $expires against the current time to
* determine if the session has expired or not.
*
* @access public
* @param string $session_id
* @param integer $expires
* @return boolean
*
*/
function isActive($session_id, $expires)
{
if (empty($session_id)) {
return false;
}
global $loader;
$loader->import('saf.Date');
if (Date::compare($expires, Date::toUnix()) >= 0) {
return false;
}
return true;
}
示例11: _compareGivenDateAndCurrentDate
/**
* Compares the given date and the current date.
*
* @return integer
* @link http://www.php.net/manual/en/function.mktime.php
*/
function _compareGivenDateAndCurrentDate()
{
$givenDate = new Date();
$givenDate->setYear($this->_year);
$givenDate->setMonth($this->_month);
$givenDate->setDay($this->_day);
$givenDate->setHour(0);
$givenDate->setMinute(0);
$givenDate->setSecond(0);
$currentDate = new Date();
$currentDate->setHour(0);
$currentDate->setMinute(0);
$currentDate->setSecond(0);
return @Date::compare($givenDate, $currentDate);
}
示例12: Date
static function date_greater_than_now($date)
{
$now = new Date(date('Y-m-d'), 'Ymd', 'Y-m-d');
$date = new Date($date, 'dmY', 'Y-m-d');
return $date->compare($now) > -1;
}
示例13: test
function test()
{
$d = new Date("hjsgdf");
echo "Invalid date:<br>";
echo "<pre>" . print_r($d, TRUE) . "</pre>";
$d = new Date();
echo "Default date:<br>";
echo "<pre>" . print_r($d, TRUE) . "</pre>";
$d = new Date("now");
echo "Current date:<br>";
echo "<pre>" . print_r($d, TRUE) . "</pre>";
$d = new Date('1960-02-10 01:02:03');
echo "From string - '1960-02-10 01:02:03':<br>";
echo "<pre>" . print_r($d, TRUE) . "</pre>";
$d = new Date('Wed, 01/16/2008 07:20');
echo "From string - 'Wed, 01/16/2008 07:20':<br>";
echo "<pre>" . print_r($d, TRUE) . "</pre>";
$d = new Date(1907, 1);
echo "From 2 separate parameters:<br>";
echo "<pre>" . print_r($d, TRUE) . "</pre>";
$d = new Date(1907, 1, 15);
echo "From 3 separate parameters:<br>";
echo "<pre>" . print_r($d, TRUE) . "</pre>";
$d = new Date(1907, 1, 15, 1);
echo "From 4 separate parameters:<br>";
echo "<pre>" . print_r($d, TRUE) . "</pre>";
$d = new Date(1907, 1, 15, 1, 2);
echo "From 5 separate parameters:<br>";
echo "<pre>" . print_r($d, TRUE) . "</pre>";
$d = new Date(1907, 1, 15, 1, 2, 3);
echo "From 6 separate parameters:<br>";
echo "<pre>" . print_r($d, TRUE) . "</pre>";
$d = new Date(array("year" => 1, "month" => 2, "day" => 3, "hour" => 4, "minute" => 5, "second" => 6));
echo "From array of 6:<br>";
echo "<pre>" . print_r($d, TRUE) . "</pre>";
$d = new Date(array("year" => 1, "month" => 2, "day" => 3, "hour" => 4, "minute" => 5));
echo "From array of 5:<br>";
echo "<pre>" . print_r($d, TRUE) . "</pre>";
$d = new Date(array("year" => 1, "month" => 2, "day" => 3, "hour" => 4));
echo "From array of 4:<br>";
echo "<pre>" . print_r($d, TRUE) . "</pre>";
$d = new Date(array("year" => 1, "month" => 2, "day" => 3));
echo "From array of 3:<br>";
echo "<pre>" . print_r($d, TRUE) . "</pre>";
echo "<h3>Comparision test:</h3><br>";
$d1 = new Date('1907-6-15 12:30:30');
$d11 = new Date('1907-6-15 12:30:30');
$d2 = new Date('1907-6-16 12:30:30');
$d3 = new Date('1907-6-17 12:30:30');
echo "{$d1}=={$d11}: " . ($d1->compare('==', $d11) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}!={$d11}: " . (!$d1->compare('!=', $d11) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}<{$d11}: " . (!$d1->compare('<', $d11) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}>{$d11}: " . (!$d1->compare('>', $d11) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}<={$d11}: " . ($d1->compare('<=', $d11) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}>={$d11}: " . ($d1->compare('>=', $d11) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}=={$d2}: " . (!$d1->compare('==', $d2) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}!={$d2}: " . ($d1->compare('!=', $d2) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}<{$d2}: " . ($d1->compare('<', $d2) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}>{$d2}: " . (!$d1->compare('>', $d2) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}<={$d2}: " . ($d1->compare('<=', $d2) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}>={$d2}: " . (!$d1->compare('>=', $d2) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}<{$d2}<{$d3}: " . ($d2->isBetween($d1, $d3) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}<={$d11}<{$d3}: " . ($d11->isBetween($d1, $d3, '<=>') ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}<{$d2}: " . ($d1->isBefore($d2) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d3}>{$d2}: " . ($d3->isAfter($d2) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}=={$d2}(day): " . (!$d1->compare('==', $d2, Date_Day) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}!={$d2}(day): " . ($d1->compare('!=', $d2, Date_Day) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}<{$d2}(day): " . ($d1->compare('<', $d2, Date_Day) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}>{$d2}(day): " . (!$d1->compare('>', $d2, Date_Day) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}<={$d2}(day): " . ($d1->compare('<=', $d2, Date_Day) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}>={$d2}(day): " . (!$d1->compare('>=', $d2, Date_Day) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}=={$d2}(month): " . ($d1->compare('==', $d2, Date_Month) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}=={$d2}(year): " . ($d1->compare('==', $d2, Date_Year) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "{$d1}=={$d2}(hour): " . (!$d1->compare('==', $d2, Date_Hour) ? 'ok' : '<font color=red>NOK</font>') . "<br>";
echo "<h3>Diff test:</h3><br>";
$d1 = new Date('1907-6-15 12:30:30');
$d2 = new Date('1907-6-17 12:30:30');
$d3 = new Date('1907-6-15 13:32:33');
echo "Diff of {$d1} and {$d2}:<br>";
echo "<pre>" . print_r($d1->getFullDiff($d2), TRUE) . "</pre>";
echo "Diff of {$d1} and {$d3}:<br>";
echo "<pre>" . print_r($d1->getFullDiff($d3), TRUE) . "</pre>";
echo "Diff of {$d2} and {$d3}:<br>";
echo "<pre>" . print_r($d2->getFullDiff($d3), TRUE) . "</pre>";
echo "Diff of {$d1} and {$d1}:<br>";
echo "<pre>" . print_r($d1->getFullDiff($d1), TRUE) . "</pre>";
echo "Diff of {$d1} and {$d2}:<br>";
echo "<pre>" . $d1->getHoursMinutesDiff($d2) . "</pre>";
echo "Diff of {$d1} and {$d3}:<br>";
echo "<pre>" . $d1->getHoursMinutesDiff($d3) . "</pre>";
echo "Diff of {$d2} and {$d3}:<br>";
echo "<pre>" . $d2->getHoursMinutesDiff($d3) . "</pre>";
echo "Diff of {$d1} and {$d1}:<br>";
echo "<pre>" . $d1->getHoursMinutesDiff($d1) . "</pre>";
echo "firstSecondOfDay {$d1}:<br>";
echo "<pre>" . $d1->firstSecondOfDay() . "</pre>";
echo "firstSecondOfDay {$d1}:<br>";
echo "<pre>" . Date::firstSecondOfDay($d1) . "</pre>";
echo "firstSecondOfDay today:<br>";
echo "<pre>" . Date::firstSecondOfDay() . "</pre>";
//.........这里部分代码省略.........
示例14: run
/**
* The implementation of the OA_Task::run() method that performs
* the required task of determining what operation intervals
* and/or hours, if any, need to be updated during the MSE run.
*/
function run()
{
$aConf = $GLOBALS['_MAX']['CONF'];
$oServiceLocator =& OA_ServiceLocator::instance();
$oNowDate =& $oServiceLocator->get('now');
if (!$oNowDate) {
$oNowDate = new Date();
}
$this->oController->report = "Maintenance Statistics Report\n";
$this->oController->report .= "=====================================\n\n";
$message = '- Maintenance start run time is ' . $oNowDate->format('%Y-%m-%d %H:%M:%S') . ' ' . $oNowDate->tz->getShortName();
$this->oController->report .= $message . "\n";
OA::debug($message, PEAR_LOG_DEBUG);
// Don't update unless the time is right!
$this->oController->updateIntermediate = false;
$this->oController->updateFinal = false;
// Test to see if a date for when the statistics were last updated
// has been set in the service locator (for re-generation of stats)
$oLastUpdatedDate =& $oServiceLocator->get('lastUpdatedDate');
// Determine when the last intermediate table update happened
if (is_a($oLastUpdatedDate, 'Date')) {
$this->oController->oLastDateIntermediate = $oLastUpdatedDate;
} else {
$this->oController->oLastDateIntermediate = $this->_getMaintenanceStatisticsLastRunInfo(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI, $oNowDate);
if (is_null($this->oController->oLastDateIntermediate)) {
// The MSE has never run, look to see if delivery data exists
$this->oController->oLastDateIntermediate = $this->_getEarliestLoggedDeliveryData(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI);
}
}
if (is_null($this->oController->oLastDateIntermediate)) {
// Could not find a last update date, so don't run MSE
$message = '- Maintenance statistics has never been run before, and no logged delivery data was located in ';
$this->oController->report .= $message . "\n";
OA::debug($message, PEAR_LOG_DEBUG);
$message = ' the database, so maintenance statistics will not be run for the intermediate tables';
$this->oController->report .= $message . "\n\n";
OA::debug($message, PEAR_LOG_DEBUG);
} else {
// Found a last update date
$message = '- Maintenance statistics last updated intermediate table statistics to ' . $this->oController->oLastDateIntermediate->format('%Y-%m-%d %H:%M:%S') . ' ' . $this->oController->oLastDateIntermediate->tz->getShortName();
$this->oController->report .= $message . ".\n";
OA::debug($message, PEAR_LOG_DEBUG);
// Does the last update date found occur on the end of an operation interval?
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($this->oController->oLastDateIntermediate);
if (Date::compare($this->oController->oLastDateIntermediate, $aDates['end']) != 0) {
$message = '- Last intermediate table updated to date of ' . $this->oController->oLastDateIntermediate->format('%Y-%m-%d %H:%M:%S') . ' ' . $this->oController->oLastDateIntermediate->tz->getShortName() . ' is not on the current operation interval boundary';
$this->oController->report .= $message . "\n";
OA::debug($message, PEAR_LOG_DEBUG);
$message = '- OPERATION INTERVAL LENGTH CHANGE SINCE LAST RUN';
$this->oController->report .= $message . "\n";
OA::debug($message, PEAR_LOG_DEBUG);
$message = '- Extending the time until next update';
$this->oController->report .= $message . "\n";
OA::debug($message, PEAR_LOG_DEBUG);
$this->oController->sameOI = false;
}
// Calculate the date after which the next operation interval-based update can happen
$oRequiredDate = new Date();
if ($this->oController->sameOI) {
$oRequiredDate->copy($this->oController->oLastDateIntermediate);
$oRequiredDate->addSeconds($aConf['maintenance']['operationInterval'] * 60);
} else {
$oRequiredDate->copy($aDates['end']);
}
$message = '- Current time must be after ' . $oRequiredDate->format('%Y-%m-%d %H:%M:%S') . ' ' . $oRequiredDate->tz->getShortName() . ' for the next intermediate table update to happen';
$this->oController->report .= $message . "\n";
OA::debug($message, PEAR_LOG_DEBUG);
if (Date::compare($oNowDate, $oRequiredDate) > 0) {
$this->oController->updateIntermediate = true;
// Update intermediate tables to the end of the previous (not current) operation interval
$aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oNowDate);
$this->oController->oUpdateIntermediateToDate = new Date();
$this->oController->oUpdateIntermediateToDate->copy($aDates['start']);
$this->oController->oUpdateIntermediateToDate->subtractSeconds(1);
} else {
// An operation interval hasn't passed, so don't update
$message = "- At least {$aConf['maintenance']['operationInterval']} minutes have " . 'not passed since the last operation interval update';
$this->oController->report .= $message . "\n";
OA::debug($message, PEAR_LOG_DEBUG);
}
}
// Determine when the last final table update happened
if ($oLastUpdatedDate !== false) {
$this->oController->oLastDateFinal = $oLastUpdatedDate;
} else {
$this->oController->oLastDateFinal = $this->_getMaintenanceStatisticsLastRunInfo(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR, $oNowDate);
if (is_null($this->oController->oLastDateFinal)) {
// The MSE has never run, look to see if delivery data exists
$this->oController->oLastDateFinal = $this->_getEarliestLoggedDeliveryData(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR);
}
}
if (is_null($this->oController->oLastDateFinal)) {
// Could not find a last update date, so don't run MSE
$message = '- Maintenance statistics has never been run before, and no logged delivery data was located in ';
$this->oController->report .= $message . "\n" . OA::debug($message, PEAR_LOG_DEBUG);
//.........这里部分代码省略.........
示例15: manageCampaigns
//.........这里部分代码省略.........
while ($advertisementRow = $rsResultAdvertisement->fetchRow()) {
$advertisements[$advertisementRow['advertisement_id']] = array($advertisementRow['description'], $advertisementRow['alt'], $advertisementRow['url']);
}
if ($aCampaign['send_activate_deactivate_email'] == 't') {
$oEmail->sendCampaignActivatedDeactivatedEmail($aCampaign['campaign_id'], $disableReason);
}
} else {
if ($canExpireSoon) {
// The campaign has NOT been deactivated - test to see if it will
// be deactivated "soon", and send email(s) warning of this as required
$oEmail->sendCampaignImpendingExpiryEmail($oDate, $aCampaign['campaign_id']);
}
}
} else {
// The campaign is not active - does it need to be enabled,
// based on the campaign starting date?
if ($aCampaign['start'] != OA_Dal::noDateValue()) {
// The campaign has a valid start date, stored in the timezone of the advertiser;
// create an end date in the advertiser's timezone, set the time, and then
// convert to UTC so that it can be compared with the MSE run time, which is
// in UTC
$aAdvertiserPrefs = OA_Preferences::loadAccountPreferences($aCampaign['advertiser_account_id'], true);
$oTimezone = new Date_Timezone($aAdvertiserPrefs['timezone']);
$oStartDate = new Date();
$oStartDate->convertTZ($oTimezone);
$oStartDate->setDate($aCampaign['start'] . ' 00:00:00');
// Campaigns start at the start of the day
$oStartDate->toUTC();
if ($aCampaign['end'] != OA_Dal::noDateValue()) {
// The campaign has a valid end date, stored in the timezone of the advertiser;
// create an end date in the advertiser's timezone, set the time, and then
// convert to UTC so that it can be compared with the MSE run time, which is
// in UTC
$oEndDate = new Date();
$oEndDate->convertTZ($oTimezone);
$oEndDate->setDate($aCampaign['end'] . ' 23:59:59');
// Campaign end at the end of the day
$oEndDate->toUTC();
} else {
$oEndDate = null;
}
if ($oDate->after($oStartDate)) {
// The start date has been passed; find out if there are any impression, click
// or conversion targets for the campaign (i.e. if the target values are > 0)
$remainingImpressions = 0;
$remainingClicks = 0;
$remainingConversions = 0;
if ($aCampaign['targetimpressions'] > 0 || $aCampaign['targetclicks'] > 0 || $aCampaign['targetconversions'] > 0) {
// The campaign has an impression, click and/or conversion target,
// so get the sum total statistics for the campaign so far
$query = "\n SELECT\n SUM(dia.impressions) AS impressions,\n SUM(dia.clicks) AS clicks,\n SUM(dia.conversions) AS conversions\n FROM\n " . $this->oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['data_intermediate_ad'], true) . " AS dia,\n " . $this->oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['banners'], true) . " AS b\n WHERE\n dia.ad_id = b.bannerid\n AND b.campaignid = {$aCampaign['campaign_id']}";
$rsResultInner = $this->oDbh->query($query);
$valuesRow = $rsResultInner->fetchRow();
// Set the remaining impressions, clicks and conversions for the campaign
$remainingImpressions = $aCampaign['targetimpressions'] - $valuesRow['impressions'];
$remainingClicks = $aCampaign['targetclicks'] - $valuesRow['clicks'];
$remainingConversions = $aCampaign['targetconversions'] - $valuesRow['conversions'];
}
// In order for the campaign to be activated, need to test:
// 1) That there is no impression target (<= 0), or, if there is an impression target (> 0),
// then there must be remaining impressions to deliver (> 0); and
// 2) That there is no click target (<= 0), or, if there is a click target (> 0),
// then there must be remaining clicks to deliver (> 0); and
// 3) That there is no conversion target (<= 0), or, if there is a conversion target (> 0),
// then there must be remaining conversions to deliver (> 0); and
// 4) Either there is no end date, or the end date has not been passed
if (($aCampaign['targetimpressions'] <= 0 || $aCampaign['targetimpressions'] > 0 && $remainingImpressions > 0) && ($aCampaign['targetclicks'] <= 0 || $aCampaign['targetclicks'] > 0 && $remainingClicks > 0) && ($aCampaign['targetconversions'] <= 0 || $aCampaign['targetconversions'] > 0 && $remainingConversions > 0) && (is_null($oEndDate) || $oEndDate->format('%Y-%m-%d') != OA_Dal::noDateValue() && Date::compare($oDate, $oEndDate) < 0)) {
$message = "- Passed campaign start time of '{$aCampaign['start']} 00:00:00 {$aAdvertiserPrefs['timezone']} (" . $oStartDate->format('%Y-%m-%d %H:%M:%S') . ' ' . $oStartDate->tz->getShortName() . ")': Activating campaign ID {$aCampaign['campaign_id']}: {$aCampaign['campaign_name']}";
OA::debug($message, PEAR_LOG_INFO);
$report .= $message . "\n";
$doCampaigns = OA_Dal::factoryDO('campaigns');
$doCampaigns->campaignid = $aCampaign['campaign_id'];
$doCampaigns->find();
$doCampaigns->fetch();
$doCampaigns->status = OA_ENTITY_STATUS_RUNNING;
$result = $doCampaigns->update();
if ($result == false) {
return MAX::raiseError($rows, MAX_ERROR_DBFAILURE, PEAR_ERROR_DIE);
}
phpAds_userlogSetUser(phpAds_userMaintenance);
phpAds_userlogAdd(phpAds_actionActiveCampaign, $aCampaign['campaign_id']);
// Get the advertisements associated with the campaign
$query = "\n SELECT\n bannerid AS advertisement_id,\n description AS description,\n alt AS alt,\n url AS url\n FROM\n " . $this->oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['banners'], true) . "\n WHERE\n campaignid = {$aCampaign['campaign_id']}";
OA::debug("- Getting the advertisements for campaign ID {$aCampaign['campaign_id']}", PEAR_LOG_DEBUG);
$rsResultAdvertisement = $this->oDbh->query($query);
if (PEAR::isError($rsResultAdvertisement)) {
return MAX::raiseError($rsResultAdvertisement, MAX_ERROR_DBFAILURE, PEAR_ERROR_DIE);
}
while ($advertisementRow = $rsResultAdvertisement->fetchRow()) {
$advertisements[$advertisementRow['advertisement_id']] = array($advertisementRow['description'], $advertisementRow['alt'], $advertisementRow['url']);
}
if ($aCampaign['send_activate_deactivate_email'] == 't') {
$oEmail->sendCampaignActivatedDeactivatedEmail($aCampaign['campaign_id']);
}
}
}
}
}
}
}