示例#1
0
 function setDate($date, $format = DATE_FORMAT_ISO)
 {
     if (is_numeric($date)) {
         $this->setDate(gmdate("Y-m-d H:i:s", $date));
     } else {
         parent::setDate($date, $format);
     }
 }
示例#2
0
 public function testFromString()
 {
     $expected = new Date();
     $expected->setDate(2009, 11, 4);
     $expected->setTime(01, 02, 03);
     $this->assertEquals($expected->format('U'), Date::create('2009-11-04 01:02:03')->format('U'));
     $this->assertEquals($expected->format('U'), Date::create('1257274923')->format('U'));
     $this->assertEquals($expected->format('U'), Date::create(Date::create('1257274923'))->format('U'));
     $this->assertEquals($expected->format('U'), Date::create(new DateTime('2009-11-04 01:02:03'))->format('U'));
     $this->assertEquals($expected->format('U'), Date::create(new Date('2009-11-04 01:02:03'))->format('U'));
     $expected->setTime(0, 0, 0);
     $this->assertEquals($expected->format('U'), Date::create('2009-11-04 00:00:00')->format('U'));
     $this->assertEquals($expected->format('U'), Date::create('2009-11-04')->format('U'));
     $this->assertEquals($expected->format('U'), Date::create('1257271200')->format('U'));
     $this->assertEquals($expected->format('U'), Date::create(Date::create('1257271200'))->format('U'));
     $this->assertEquals($expected->format('U'), Date::create(new DateTime('2009-11-04'))->format('U'));
     $this->assertEquals($expected->format('U'), Date::create(new Date('2009-11-04'))->format('U'));
 }
示例#3
0
 /**
  * A method to activate/deactivate campaigns, based on the date and/or the inventory
  * requirements (impressions, clicks and/or conversions). Also sends email reports
  * for any campaigns that are activated/deactivated, as well as sending email reports
  * for any campaigns that are likely to expire in the near future.
  *
  * @param Date $oDate The current date/time.
  * @return string Report on the campaigns activated/deactivated.
  */
 function manageCampaigns($oDate)
 {
     $aConf = $GLOBALS['_MAX']['CONF'];
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oEmail =& $oServiceLocator->get('OA_Email');
     if ($oEmail === false) {
         $oEmail = new OA_Email();
         $oServiceLocator->register('OA_Email', $oEmail);
     }
     $report = "\n";
     // Select all campaigns in the system, where:
     //    The campaign is ACTIVE and:
     //    - The end date stored for the campaign is not null; or
     //    - The campaign has a lifetime impression, click or conversion
     //      target set.
     //
     //    That is:
     //    - It is possible for the active campaign to be automatically
     //      stopped, as it has a valid end date. (No limitations are
     //      applied to those campaigns tested, as the ME may not have
     //      run for a while, and if so, even campaigns with an end date
     //      of many, many weeks ago should be tested to ensure they are
     //      [belatedly] halted.)
     //    - It is possible for the active campaign to be automatically
     //      stopped, as it has at leaast one lifetime target that could
     //      have been reached.
     //
     //    The campaign is INACTIVE and:
     //    - The start date stored for the campaign is not null; and
     //    - The weight is greater than zero; and
     //    - The end date stored for the campaign is either null, or is
     //      greater than "today" less one day.
     //
     //    That is:
     //    - It is possible for the inactive campaign to be automatically
     //      started, as it has a valid start date. (No limitations are
     //      applied to those campaigns tested, as the ME may not have run
     //      for a while, and if so, even campaigns with an activation date
     //      of many, many weeks ago should be tested to ensure they are
     //      [belatedy] enabled.)
     //    - The campaign is not in a permanently inactive state, as a
     //      result of the weight being less then one, which means that
     //      it cannot be activated.
     //    - The test to start the campaign is unlikely to fail on account
     //      of the end date. (Inactive campaigns with start dates may have
     //      passed the start date, but they may also have passed the end
     //      date - unfortunately, because the dates are not stored in UTC,
     //      it's not possible to know exactly which campaigns have passed
     //      the end date or not, until the values are converted to UTC based
     //      on the Advertiser Account timezone preference - so it's necessary
     //      to get some campaigns that might be passed the end date, and do
     //      the converstion to UTC and test to check.)
     $prefix = $this->getTablePrefix();
     $oYesterdayDate = new Date();
     $oYesterdayDate->copy($oDate);
     $oYesterdayDate->subtractSeconds(SECONDS_PER_DAY);
     $query = "\n            SELECT\n                cl.clientid AS advertiser_id,\n                cl.account_id AS advertiser_account_id,\n                cl.agencyid AS agency_id,\n                cl.contact AS contact,\n                cl.email AS email,\n                cl.reportdeactivate AS send_activate_deactivate_email,\n                ca.campaignid AS campaign_id,\n                ca.campaignname AS campaign_name,\n                ca.views AS targetimpressions,\n                ca.clicks AS targetclicks,\n                ca.conversions AS targetconversions,\n                ca.status AS status,\n                ca.activate AS start,\n                ca.expire AS end\n            FROM\n                {$prefix}campaigns AS ca,\n                {$prefix}clients AS cl\n            WHERE\n                ca.clientid = cl.clientid\n                AND\n                ca.status = " . $this->oDbh->quote(OA_ENTITY_STATUS_RUNNING, 'integer') . "\n                AND\n                (\n                    ca.expire " . OA_Dal::notEqualNoDateString() . "\n                    OR\n                    (\n                        ca.views > 0\n                        OR\n                        ca.clicks > 0\n                        OR\n                        ca.conversions > 0\n                    )\n                )\n            UNION ALL\n            SELECT\n                cl.clientid AS advertiser_id,\n                cl.account_id AS advertiser_account_id,\n                cl.agencyid AS agency_id,\n                cl.contact AS contact,\n                cl.email AS email,\n                cl.reportdeactivate AS send_activate_deactivate_email,\n                ca.campaignid AS campaign_id,\n                ca.campaignname AS campaign_name,\n                ca.views AS targetimpressions,\n                ca.clicks AS targetclicks,\n                ca.conversions AS targetconversions,\n                ca.status AS status,\n                ca.activate AS start,\n                ca.expire AS end\n            FROM\n                {$prefix}campaigns AS ca,\n                {$prefix}clients AS cl\n            WHERE\n                ca.clientid = cl.clientid\n                AND\n                ca.status != " . $this->oDbh->quote(OA_ENTITY_STATUS_RUNNING, 'integer') . "\n                AND\n                ca.activate " . OA_Dal::notEqualNoDateString() . "\n                AND\n                (\n                    ca.weight > 0\n                    OR\n                    ca.priority > 0\n                )\n                AND\n                (\n                    ca.expire >= " . $this->oDbh->quote($oYesterdayDate->format('%Y-%m-%d'), 'timestamp') . "\n                    OR\n                    ca.expire " . OA_Dal::equalNoDateString() . "\n                )\n            ORDER BY\n                advertiser_id";
     $rsResult = $this->oDbh->query($query);
     if (PEAR::isError($rsResult)) {
         return MAX::raiseError($rsResult, MAX_ERROR_DBFAILURE, PEAR_ERROR_DIE);
     }
     OA::debug('- Found ' . $rsResult->numRows() . ' campaigns to test for activation/deactivation', PEAR_LOG_DEBUG);
     while ($aCampaign = $rsResult->fetchRow()) {
         if ($aCampaign['status'] == OA_ENTITY_STATUS_RUNNING) {
             // The campaign is currently running, look at the campaign
             $disableReason = 0;
             $canExpireSoon = false;
             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
                 $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();
                 if (!is_null($valuesRow['impressions']) || !is_null($valuesRow['clicks']) || !is_null($valuesRow['conversions'])) {
                     // There were impressions, clicks and/or conversions for this
                     // campaign, so find out if campaign targets have been passed
                     if (is_null($valuesRow['impressions'])) {
                         // No impressions
                         $valuesRow['impressions'] = 0;
                     }
                     if (is_null($valuesRow['clicks'])) {
                         // No clicks
                         $valuesRow['clicks'] = 0;
                     }
                     if (is_null($valuesRow['conversions'])) {
                         // No conversions
                         $valuesRow['conversions'] = 0;
                     }
                     if ($aCampaign['targetimpressions'] > 0) {
                         if ($aCampaign['targetimpressions'] <= $valuesRow['impressions']) {
                             // The campaign has an impressions target, and this has been
                             // passed, so update and disable the campaign
                             $disableReason |= OX_CAMPAIGN_DISABLED_IMPRESSIONS;
                         }
                     }
                     if ($aCampaign['targetclicks'] > 0) {
                         if ($aCampaign['targetclicks'] <= $valuesRow['clicks']) {
                             // The campaign has a click target, and this has been
                             // passed, so update and disable the campaign
                             $disableReason |= OX_CAMPAIGN_DISABLED_CLICKS;
                         }
                     }
                     if ($aCampaign['targetconversions'] > 0) {
                         if ($aCampaign['targetconversions'] <= $valuesRow['conversions']) {
                             // The campaign has a target limitation, and this has been
                             // passed, so update and disable the campaign
                             $disableReason |= OX_CAMPAIGN_DISABLED_CONVERSIONS;
                         }
                     }
                     if ($disableReason) {
                         // One of the campaign targets was exceeded, so disable
                         $message = '- Exceeded a campaign quota: Deactivating 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_EXPIRED;
                         $result = $doCampaigns->update();
                         if ($result == false) {
                             return MAX::raiseError($rows, MAX_ERROR_DBFAILURE, PEAR_ERROR_DIE);
                         }
                         phpAds_userlogSetUser(phpAds_userMaintenance);
                         phpAds_userlogAdd(phpAds_actionDeactiveCampaign, $aCampaign['campaign_id']);
                     } else {
                         // The campaign didn't have a diable reason,
                         // it *might* possibly be diabled "soon"...
                         $canExpireSoon = true;
                     }
                 }
             }
             // Does the campaign need to be disabled due to the date?
             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
                 $aAdvertiserPrefs = OA_Preferences::loadAccountPreferences($aCampaign['advertiser_account_id'], true);
                 $oTimezone = new Date_Timezone($aAdvertiserPrefs['timezone']);
                 $oEndDate = new Date();
                 $oEndDate->convertTZ($oTimezone);
                 $oEndDate->setDate($aCampaign['end'] . ' 23:59:59');
                 // Campaigns end at the end of the day
                 $oEndDate->toUTC();
                 if ($oDate->after($oEndDate)) {
                     // The end date has been passed; disable the campaign
                     $disableReason |= OX_CAMPAIGN_DISABLED_DATE;
                     $message = "- Passed campaign end time of '{$aCampaign['end']} 23:59:59 {$aAdvertiserPrefs['timezone']} (" . $oEndDate->format('%Y-%m-%d %H:%M:%S') . ' ' . $oEndDate->tz->getShortName() . ")': Deactivating 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_EXPIRED;
                     $result = $doCampaigns->update();
                     if ($result == false) {
                         return MAX::raiseError($rows, MAX_ERROR_DBFAILURE, PEAR_ERROR_DIE);
                     }
                     phpAds_userlogSetUser(phpAds_userMaintenance);
                     phpAds_userlogAdd(phpAds_actionDeactiveCampaign, $aCampaign['campaign_id']);
                 } else {
                     // The campaign wasn't disabled based on the end
                     // date, to it *might* possibly be disabled "soon"...
                     $canExpireSoon = true;
                 }
             }
             if ($disableReason) {
                 // The campaign was disabled, so send the appropriate
                 // message to the campaign's contact
                 $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'], $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']);
                         }
                     }
                 }
             }
         }
     }
 }
    // Reset period
    $period_preset = '';
    // Always refresh howLong and hour
    $howLong = MAX_getValue('howLong', 'd');
    $hour = MAX_getValue('hour');
} else {
    $period_preset = MAX_getStoredValue('period_preset', 'today');
    $period_start = MAX_getStoredValue('period_start', date('Y-m-d'));
    $period_end = MAX_getStoredValue('period_end', date('Y-m-d'));
}
if (!empty($period_preset)) {
    $aDates = MAX_getDatesByPeriod($period_preset, $period_start, $period_end);
} else {
    $aDates = array();
    $oDayDate = new Date();
    $oDayDate->setDate($day, DATE_FORMAT_TIMESTAMP);
    if (!empty($hour)) {
        // If hour is set build day date including hour
        $aDates['day_hour'] = $oDayDate->format('%Y-%m-%d') . ' ' . $hour;
    } else {
        // Build month, day, day_begin and day_end dependends on $howLong
        switch ($howLong) {
            case 'm':
                $aDates['month'] = $oDayDate->format('%Y-%m');
                break;
            case 'w':
                $aDates['day_begin'] = $oDayDate->format('%Y-%m-%d');
                $oDayDate->addSeconds(60 * 60 * 24 * 7);
                // Add 7 days
                $aDates['day_end'] = $oDayDate->format('%Y-%m-%d');
                break;
示例#5
0
function DaysNameofMonth($Month, $Year)
{
    $date = new Date();
    $Date_Calc = new Date_Calc();
    $date->setYear($Year);
    $date->setMonth($Month);
    $NodaysMonth = $date->getDaysInMonth();
    $firstDate = $Year . "-" . $Month . "-01";
    $date->setDate($firstDate);
    $daysName = array();
    for ($i = 0; $i < $NodaysMonth; $i++) {
        $daysName[$i] = $date->getDayName(True, 3);
        $getNextday = $date->getNextDay();
        $date->setDate($getNextday);
    }
    return $daysName;
}
示例#6
0
 /**
  * A method to set the value of the field using the input querystring fields passed in from the HTML.
  *
  * @param array $aQuerystring The querystring of this field.
  */
 function setValueFromArray($aFieldValues)
 {
     $fieldSelectionName = $aFieldValues[$this->_name . '_preset'];
     if (!empty($fieldSelectionName)) {
         if ($fieldSelectionName == 'specific') {
             $oDaySpan = new OA_Admin_DaySpan();
             $sStartDate = $aFieldValues[$this->_name . '_start'];
             $oStartDate = new Date();
             if ($sStartDate == '') {
                 $sStartDate = '1995-01-01';
             }
             $oStartDate->setDate($sStartDate);
             $sEndDate = $aFieldValues[$this->_name . '_end'];
             $oEndDate = new Date();
             if ($sEndDate != '') {
                 $oEndDate->setDate($sEndDate);
             }
             $oDaySpan->setSpanDays($oStartDate, $oEndDate);
         } elseif ($fieldSelectionName == 'all_stats') {
             $oDaySpan = null;
         } else {
             $oDaySpan = new OA_Admin_DaySpan($fieldSelectionName);
         }
         $this->_value = $oDaySpan;
         $this->_fieldSelectionValue = $fieldSelectionName;
     }
 }
示例#7
0
 public function nextDay()
 {
     $timestamp = $this->getTimestamp() + 86400;
     $nextDay = new Date();
     $nextDay->setDate(date("Y", $timestamp), date("m", $timestamp), date("d", $timestamp));
     $nextDay->setTime(date("G", $timestamp), date("i", $timestamp), date("s", $timestamp));
     return $nextDay;
 }
示例#8
0
文件: Date.php 项目: mickdane/zidisha
 /**
  * Get a Date object for the weekday before this one
  *
  * Get a Date object for the weekday before this one.
  * The time of the returned Date object is the same as this time.
  *
  * @access public
  * @return object Date Date representing the previous weekday
  */
 function getPrevWeekday()
 {
     $day = Date_Calc::prevWeekday($this->day, $this->month, $this->year, "%Y-%m-%d");
     $date = sprintf("%s %02d:%02d:%02d", $day, $this->hour, $this->minute, $this->second);
     $newDate = new Date();
     $newDate->setDate($date);
     return $newDate;
 }
示例#9
0
$datetest->addSeconds(1043539200, true);
compare("26/07/2005 05.29.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1043539200");
$datetest = new Date($date);
$datetest->addSeconds(1075161600, true);
compare("27/07/2006 05.29.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1075161600");
// 23rd leap second in Dec 2005
$datetest = new Date($date);
$datetest->addSeconds(1106784000, true);
compare("28/07/2007 05.29.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1106784000");
$datetest = new Date($date);
$datetest->addSeconds(1138406400, true);
compare("28/07/2008 05.29.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1138406400");
$datetest = new Date($date);
$datetest->addSeconds(1170028800, true);
compare("29/07/2009 05.29.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1170028800");
$date->setDate("2006-01-01 05:30:05.987654");
$datetest = new Date($date);
$datetest->addSeconds(-1, true);
compare("01/01/2006 05.30.04.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1");
$datetest = new Date($date);
$datetest->addSeconds(-2, true);
compare("01/01/2006 05.30.03.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-2");
$datetest = new Date($date);
$datetest->addSeconds(-3, true);
compare("01/01/2006 05.30.02.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-3");
$datetest = new Date($date);
$datetest->addSeconds(-4, true);
compare("01/01/2006 05.30.01.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-4");
$datetest = new Date($date);
$datetest->addSeconds(-5, true);
compare("01/01/2006 05.30.00.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-5");
示例#10
0
function getTemplateArrayCalendar($o_minDay, $s_date, $period)
{
    // today
    $today = new Date(getDateFromTimestamp(time()));
    $tsToday = $today->getTimestamp();
    // date asked for statistics
    $dateAsked = new Date($s_date);
    // used for going througt the month
    $date = new Date($s_date);
    $month = $date->getMonth();
    $year = $date->getYear();
    $prefixDay = $year . "-" . $month . "-";
    $date->setDate($prefixDay . '01');
    $week = $date->getWeek();
    $day = 1;
    $ts = $date->getTimestamp();
    while ($date->getMonth() == $month) {
        // day exists in stats, isn't it too old or in the future ?
        if ($date->getTimestamp() >= $o_minDay->getTimestamp() && $date->getTimestamp() <= $tsToday) {
            $exists = 1;
        } else {
            $exists = 0;
        }
        // day selected for stats view ?
        if ($period == DB_ARCHIVES_PERIOD_DAY && $date->getDay() == $dateAsked->getDay() || $period == DB_ARCHIVES_PERIOD_WEEK && $date->getWeek() == $dateAsked->getWeek() || $period == DB_ARCHIVES_PERIOD_MONTH || $period == DB_ARCHIVES_PERIOD_YEAR) {
            $selected = 1;
        } else {
            $selected = 0;
        }
        $weekNo = $date->getWeek() - $week;
        if (defined('MONDAY_FIRST') && MONDAY_FIRST == 'no' && date("w", $ts) == 0) {
            $weekNo += 1;
        }
        $dayOfWeek = (int) (!defined('MONDAY_FIRST') || MONDAY_FIRST == 'yes' ? date("w", $ts) == 0 ? 6 : date("w", $ts) - 1 : date("w", $ts));
        $return[$weekNo][$dayOfWeek] = array('day' => substr($date->getDay(), 0, 1) === '0' ? substr($date->getDay(), 1, 2) : $date->getDay(), 'date' => $date->get(), 'exists' => $exists, 'selected' => $selected);
        $date->addDays(1);
        //these 2 lines useless? to check
        $ts = $date->getTimeStamp();
        $date->setTimestamp($ts);
    }
    foreach ($return as $key => $r) {
        $row =& $return[$key];
        for ($i = 0; $i < 7; $i++) {
            if (!isset($row[$i])) {
                $row[$i] = "-";
            }
        }
        ksort($row);
    }
    return $return;
}
示例#11
0
 /**
  * set EOV
  *
  * @access public
  * @param int eov of verification
  * 
  */
 public function setEOV($a_eov)
 {
     include_once 'Date.php';
     $date = new Date();
     $date->setDate($a_eov, DATE_FORMAT_UNIXTIME);
     $this->eov = $date->getDate() . '+01:00';
 }
示例#12
0
文件: NDate.php 项目: anas/feedstore
 function setDate($date, $format = DATE_FORMAT_ISO)
 {
     if (is_array($date)) {
         $this->setDateArray($date);
         return;
     }
     if (is_int($format) && $format < 100) {
         parent::setDate($date, $format);
         return;
     }
     if ($this->getDate() == "0-01-01 00:00:00") {
         // TODO:  Make relative to (optional) date specified second argument
         $date = strtotime($date);
         parent::setDate($date);
     }
 }
 /**
  * get end as unix time
  *
  * @access public
  * 
  */
 public function getUTEnd()
 {
     include_once 'Date.php';
     $date = new Date();
     $date->setDate($this->end);
     return $date->getDate(DATE_FORMAT_UNIXTIME);
 }
示例#14
0
文件: DateTest.php 项目: MagnusA/Date
 function testDateUnixtime4()
 {
     $temp = new Date();
     $temp->setTZbyID("Europe/London");
     $temp->setDate(strtotime("2003-10-04 14:03:24Z"));
     // Summer time in London
     $temp->setTZbyID("UTC");
     $this->assertEquals('2003-10-04 15:03:24', sprintf('%04d-%02d-%02d %02d:%02d:%02d', $temp->year, $temp->month, $temp->day, $temp->hour, $temp->minute, $temp->second));
 }
示例#15
0
 /**
  * Returns the data used by the weekly report.
  *
  * @access  public
  * @param   string $usr_id The ID of the user this report is for.
  * @param   string The start date of this report.
  * @param   string The end date of this report.
  * @param   boolean If closed issues should be separated from other issues.
  * @return  array An array of data containing all the elements of the weekly report.
  */
 function getWeeklyReport($usr_id, $start, $end, $separate_closed = false)
 {
     $usr_id = Misc::escapeInteger($usr_id);
     // figure out timezone
     $user_prefs = Prefs::get($usr_id);
     $tz = @$user_prefs["timezone"];
     $start_dt = new Date();
     $end_dt = new Date();
     // set timezone to that of user.
     $start_dt->setTZById($tz);
     $end_dt->setTZById($tz);
     // set the dates in the users time zone
     $start_dt->setDate($start . " 00:00:00");
     $end_dt->setDate($end . " 23:59:59");
     // convert time to GMT
     $start_dt->toUTC();
     $end_dt->toUTC();
     $start_ts = $start_dt->getDate();
     $end_ts = $end_dt->getDate();
     $time_tracking = Time_Tracking::getSummaryByUser($usr_id, $start_ts, $end_ts);
     // replace spaces in index with _ and calculate total time
     $total_time = 0;
     foreach ($time_tracking as $category => $data) {
         unset($time_tracking[$category]);
         $time_tracking[str_replace(" ", "_", $category)] = $data;
         $total_time += $data["total_time"];
     }
     // get count of issues assigned in week of report.
     $stmt = "SELECT\n                    COUNT(*)\n                 FROM\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user,\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status\n                 WHERE\n                    iss_id = isu_iss_id AND\n                    iss_sta_id = sta_id AND\n                    isu_usr_id = {$usr_id} AND\n                    isu_assigned_date BETWEEN '{$start_ts}' AND '{$end_ts}'";
     $newly_assigned = $GLOBALS["db_api"]->dbh->getOne($stmt);
     if (PEAR::isError($newly_assigned)) {
         Error_Handler::logError(array($newly_assigned->getMessage(), $newly_assigned->getDebugInfo()), __FILE__, __LINE__);
     }
     $email_count = array("associated" => Support::getSentEmailCountByUser($usr_id, $start_ts, $end_ts, true), "other" => Support::getSentEmailCountByUser($usr_id, $start_ts, $end_ts, false));
     $data = array("start" => str_replace('-', '.', $start), "end" => str_replace('-', '.', $end), "user" => User::getDetails($usr_id), "group_name" => Group::getName(User::getGroupID($usr_id)), "issues" => History::getTouchedIssuesByUser($usr_id, $start_ts, $end_ts, $separate_closed), "status_counts" => History::getTouchedIssueCountByStatus($usr_id, $start_ts, $end_ts), "new_assigned_count" => $newly_assigned, "time_tracking" => $time_tracking, "email_count" => $email_count, "phone_count" => Phone_Support::getCountByUser($usr_id, $start_ts, $end_ts), "note_count" => Note::getCountByUser($usr_id, $start_ts, $end_ts), "total_time" => Misc::getFormattedTime($total_time, false));
     return $data;
 }
 /**
  * A method to test the activation of campaigns does NOT occur in the
  * event that the campaigns have previously been deactivated within
  * the manageCampaigns() method.
  */
 function testManageCampaignsNoRestart()
 {
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oServiceLocator->register('now', new Date('2005-12-07 10:01:00'));
     $oFactory = new OX_Dal_Maintenance_Statistics_Factory();
     $oDalMaintenanceStatistics = $oFactory->factory();
     // Create the required accounts & set the various ID values
     $aValues = $this->_createAccounts();
     $adminAccountId = $aValues['adminAccount'];
     $managerAccountId = $aValues['managerAccount'];
     $advertiserClientId = $aValues['advertiserClient'];
     /******************************************************************************/
     /* Prepare Campaign and Banner Data for Test                                  */
     /******************************************************************************/
     // Campaign 1:
     // - Owned by Advertiser 1
     // - Lifetime target of 10 impressions
     // - Start date of 2005-12-07
     // - End date of 2005-12-09
     // - Campaign currently running, will be expired after we insert stats
     $aData = array('campaignname' => 'Test Campaign 1', 'clientid' => $advertiserClientId, 'views' => 10, 'clicks' => -1, 'conversions' => -1, 'activate_time' => '2005-12-06 14:00:00', 'expire_time' => '2005-12-09 13:59:59', 'status' => OA_ENTITY_STATUS_RUNNING);
     $idCampaign1 = $this->_insertPlacement($aData);
     // Banner 1
     // - In Campaign 1
     $aData = array('campaignid' => $idCampaign1);
     $idBanner1 = $this->_insertAd($aData);
     // 100 Impressions for Banner 1 occuring after the
     // start date of Campaign 1, and before the end date
     // of Campaign 1, when the campaign start/end dates
     // are converted into UTC
     $aData = array('operation_interval_id' => 25, 'interval_start' => '2005-12-07 10:00:00', 'interval_end' => '2005-12-07 10:59:59', 'hour' => 10, 'ad_id' => $idBanner1, 'impressions' => 100, 'clicks' => 1, 'conversions' => 0);
     $idDIA1 = $this->_insertDataIntermediateAd($aData);
     // Make sure that campaign 1 is expired
     $doCampaigns = OA_Dal::staticGetDO('campaigns', $idCampaign1);
     $doCampaigns->status = OA_ENTITY_STATUS_RUNNING;
     $doCampaigns->update();
     /******************************************************************************/
     // Test 1: Prepare a date for the manageCampaigns() method to run at in UTC;
     //         2005-12-07 11:01:00 UTC is 2005-12-07 22:01:00 Australia/Sydney
     $oDate = new Date();
     $oDate->toUTC();
     $oDate->setDate('2005-12-07 11:01:00');
     $oServiceLocator->register('now', $oDate);
     // Test 1: Run the method, and ensure that, although the date in UTC
     //         is after the start date of Campaign 1 and before the end
     //         date of Campaign 1, the campaign is NOT enabled, due to
     //         past expiration of the campaign
     $report = $oDalMaintenanceStatistics->manageCampaigns($oDate);
     $this->_testCampaignByCampaignId($idCampaign1, 10, -1, -1, '2005-12-06 14:00:00', '2005-12-09 13:59:59', OA_ENTITY_STATUS_EXPIRED);
     /******************************************************************************/
     DataGenerator::cleanUp();
 }
示例#17
0
 /** DEPRECIADA, UTILIZAR FUNCION DATE EN SU LUGAR */
 public static function isDate($string)
 {
     $date = new Date();
     $year = $month = $day = 0;
     $string_set = '';
     $string = str_replace('/', '-', $string);
     // por si viene en formato con barritas
     $string = explode(' ', $string);
     // por si es ISO con HHMMSS
     $array_date = explode('-', $string[0]);
     if (count($array_date) != 3) {
         return false;
     }
     // ISO (solo fecha)
     if (strlen($array_date[0]) == 4) {
         $year = $array_date[0];
         $month = $array_date[1];
         $day = $array_date[2];
     } else {
         $year = $array_date[2];
         //DDMMAAAA
         if ($array_date[0] > 12) {
             $month = $array_date[1];
             $day = $array_date[0];
         }
         if ($array_date[1] > 12) {
             $month = $array_date[0];
             $day = $array_date[1];
         }
     }
     if ($month > 0 && $day > 0) {
         $string_set = $year . '-' . $month . '-' . $day . ' 00:00:00';
     } else {
         //MMDDAAAA
         if (checkdate($array_date[0], $array_date[1], $array_date[2])) {
             $string_set = $array_date[2] . '-' . $array_date[0] . '-' . $array_date[1] . ' 00:00:00';
         }
         //DDMMAAAA (tiene mas importancia)
         if (checkdate($array_date[1], $array_date[0], $array_date[2])) {
             $string_set = $array_date[2] . '-' . $array_date[1] . '-' . $array_date[0] . ' 00:00:00';
         }
     }
     if ($string_set == '') {
         return false;
     }
     $date->setDate($string_set);
     return self::isValidDate($date);
 }
示例#18
0
$datetest->addSeconds(1043539200, true);
compare("26/07/2005 01.59.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1043539200");
$datetest = new Date($date);
$datetest->addSeconds(1075161600, true);
compare("27/07/2006 01.59.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1075161600");
// 23rd leap second in Dec 2005
$datetest = new Date($date);
$datetest->addSeconds(1106784000, true);
compare("28/07/2007 01.59.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1106784000");
$datetest = new Date($date);
$datetest->addSeconds(1138406400, true);
compare("28/07/2008 01.59.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1138406400");
$datetest = new Date($date);
$datetest->addSeconds(1170028800, true);
compare("29/07/2009 01.59.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1170028800");
$date->setDate("2006-01-01 01:00:05.987654");
$datetest = new Date($date);
$datetest->addSeconds(-1, true);
compare("01/01/2006 01.00.04.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1");
$datetest = new Date($date);
$datetest->addSeconds(-2, true);
compare("01/01/2006 01.00.03.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-2");
$datetest = new Date($date);
$datetest->addSeconds(-3, true);
compare("01/01/2006 01.00.02.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-3");
$datetest = new Date($date);
$datetest->addSeconds(-4, true);
compare("01/01/2006 01.00.01.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-4");
$datetest = new Date($date);
$datetest->addSeconds(-5, true);
compare("01/01/2006 01.00.00.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-5");
示例#19
0
文件: example.php 项目: MagnusA/Date
require_once "Date.php";
function echo_code($ps_date)
{
    echo '<span class="code">' . $ps_date . "</span><br />\n";
}
$date = new Date();
?>
<h4>Object is set to currrent time and local time zone by default:</h4>
<?php 
echo_code($date->format('%d/%m/%Y %H.%M.%S%O (%Z)'));
echo_code($date->format2('DD/MM/YYYY HH.MI.SSTZO (TZC - TZN)'));
echo_code($date->getDate(DATE_FORMAT_ISO));
?>
<h4>Set date to 1st February, 1991:</h4>
<?php 
$date->setDate("1991-02-01 01:02:03");
echo_code($date->format('%d/%m/%Y %H.%M.%S'));
echo_code($date->format2('DD/MM/YYYY HH.MI.SS'));
// Display day, month spelled out:
//
echo_code($date->format('%A, %e %B %Y, %H.%M.%S'));
echo_code($date->format2('NPDay, NPDDth Month YYYY, HH.MI.SS'));
?>
<h4>Time without padding (i.e. leading noughts), and with short year:</h4>
<?php 
echo_code($date->format('%e/%m/%y %h.%M.%S'));
echo_code($date->format2('NPDD/NPMM/YY NPHH.MI.SS'));
?>
<h4>Conversion to another time zone:</h4>
<?php 
$date->convertTZbyID("Asia/Calcutta");