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


PHP JDate::diff方法代码示例

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


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

示例1: getCountDay

 public static function getCountDay($start, $end)
 {
     //$start = strtotime($start);
     $start = new JDate($start);
     $end = new JDate($end);
     //$end = strtotime($end);
     //$days_between = ceil(abs($end - $start) / 86400);
     $days = $start->diff($end);
     return $days->days;
     //return $days_between;
 }
开发者ID:hixbotay,项目名称:executivetransport,代码行数:11,代码来源:date.php

示例2: index

 public function index()
 {
     $model = $this->getModel($this->default_view);
     $start = new JDate('now');
     if ($success = $model->index()) {
         $msg = JText::_("Index successful");
     } else {
         error_log('failed to index');
         $msg = JText::_($model->getError());
     }
     $end = new JDate('now');
     $time = $start->diff($end);
     $msg = $msg . " (execution time: " . $time->format("%H:%M:%S") . ")";
     echo json_encode(array("success" => $success, "message" => $msg));
 }
开发者ID:bellodox,项目名称:jsolr,代码行数:15,代码来源:controller.php

示例3: isValid

 /**
  * Validate project owner.
  *
  * <code>
  * $startDate = "2015-01-01";
  * $endDate = "2015-01-30";
  * $minDays = "10";
  * $maxDays = "30";
  *
  * $period = new Crowdfunding\Validator\Project\Period($startDate, $endDate, $minDays, $maxDays);
  * if(!$period->isValid()) {
  * ......
  * }
  * </code>
  *
  * @return bool
  */
 public function isValid()
 {
     // Get interval between starting and ending date.
     $fundingStartDate = new \JDate($this->startDate);
     $fundingEndDate = new \JDate($this->endDate);
     $interval = $fundingStartDate->diff($fundingEndDate);
     $days = (int) $interval->format('%r%a');
     // Validate minimum dates
     if ($days < $this->minDays) {
         return false;
     }
     if ($this->maxDays > 0 and $days > $this->maxDays) {
         return false;
     }
     return true;
 }
开发者ID:bellodox,项目名称:CrowdFunding,代码行数:33,代码来源:Period.php

示例4: isValidPeriod

 /**
  * Validate funding period.
  *
  * <code>
  * $fundingEndDate = "04-02-2014";
  * $minDays = 15;
  * $maxDays = 30;
  *
  * $dateValidator = new CrowdFundingDate($item->funding_start);
  * if (!$dateValidator->isValidPeriod($fundingEndDate, $minDays, $maxDays)) {
  * ...
  * }
  * </code>
  *
  * @param string $fundingEnd
  * @param int $minDays
  * @param int $maxDays
  *
  * @return bool
  */
 public function isValidPeriod($fundingEnd, $minDays, $maxDays)
 {
     // Funding start date
     $date = clone $this;
     $fundingStart = $date->format("Y-m-d");
     // Funding end date
     $date = new JDate($fundingEnd);
     $fundingEnd = $date->format("Y-m-d");
     // Get interval between starting and ending date
     $startingDate = new JDate($fundingStart);
     $endingDate = new JDate($fundingEnd);
     $interval = $startingDate->diff($endingDate);
     $days = $interval->format("%r%a");
     // Validate minimum dates
     if ($days < $minDays) {
         return false;
     }
     if (!empty($maxDays) and $days > $maxDays) {
         return false;
     }
     return true;
 }
开发者ID:phpsource,项目名称:CrowdFunding,代码行数:42,代码来源:date.php

示例5: foreach

    //echo "</pre>";
    $staysuggesteds[$resStay->BookingType] = $currstaysuggested;
    return $arr;
}
$hasResourceStay = false;
if (isset($this->resstays)) {
    $hasResourceStay = true;
    foreach ($this->resstays as $rst) {
        $allStaysToView = pushStay($allStaysToView, $resource->ResourceId, $rst, $resource, $allstaysuggested);
    }
}
$this->allstaysuggested = $allstaysuggested;
//foreach($this->allstays as $rst) {
//	$allStaysToView = pushStay($allStaysToView, $rst->ResourceId, $rst);
//}
$duration = $checkin->diff($checkout);
$showQuote = $DiscountedPrice > 0 && $stayAvailability > 0;
$selPriceTypeObj = null;
if (isset($completestay->CalculatedPricesDetails)) {
    $calPrices = $completestay->CalculatedPricesDetails;
}
if (!empty($completestay)) {
    $selPriceType = $completestay->RatePlanId;
    $selPriceTags = $completestay->Tags;
}
if (empty($priceTypes)) {
    $priceTypes = [];
}
$priceTypes = array_filter($priceTypes, function ($priceType) use($selPriceTags) {
    return $priceType->Tags == $selPriceTags;
});
开发者ID:Bookingfor,项目名称:joomla-extension-v-2,代码行数:31,代码来源:form.php

示例6: save

    /**
     * Save subject.
     *
     * @param boolean $apply
     *        	true state on edit page, false return to browse list
     */
    function save($apply = false)
    {
        $mainframe = JFactory::getApplication();
        $db = JFactory::getDbo();
        $input = JFactory::getApplication()->input;
        $jform = $input->get('jform', array(), 'array');
        $frate = $input->get('frate', array(), 'array');
        //quote all value to push db
        foreach ($frate as &$rate) {
            foreach ($rate as $i => $v) {
                $rate[$i] = $db->quote($v);
            }
        }
        $rate = reset($frate);
        $key = array_keys($rate);
        $weekdays = $input->get('weekday', null, 'array');
        $state = $input->getInt('state');
        $jform['startdate'] = DateHelper::createFromFormatYmd($jform['startdate']);
        $jform['enddate'] = DateHelper::createFromFormatYmd($jform['enddate']);
        $startdate = new JDate($jform['startdate']);
        $enddate = new JDate($jform['enddate']);
        $starttoend = $startdate->diff($enddate)->days;
        // delete old record
        $tour_id = $jform['tour_id'];
        try {
            $db->transactionStart();
            // Delete all existing rate in this duration and fligh route
            $query = $db->getQuery(true);
            $query->delete('#__bookpro_tourrate')->where('(tour_id=' . $tour_id . ' 
					AND date BETWEEN ' . $db->quote($startdate) . ' 
					AND ' . $db->quote($enddate) . ' 
					AND DATE_FORMAT(date,"%w") IN (' . implode(',', $weekdays) . '))
					OR (date < ' . $db->quote(JFactory::getDate('- 10DAYS')->format('Y-m-d') . ' AND tour_id=' . $tour_id) . ')');
            $db->setQuery($query);
            $db->execute();
            $query = $db->getQuery(true);
            $query->insert('#__bookpro_tourrate');
            $query->columns('tour_id,date,' . implode(',', $key) . ',state');
            $values = array();
            for ($i = 0; $i <= $starttoend; $i++) {
                $dw = (int) $startdate->format('w');
                if (in_array("{$dw}", $weekdays)) {
                    foreach ($frate as $rate) {
                        $temp = array($jform['tour_id'], $db->quote($startdate->toSql()));
                        $temp = array_merge($temp, $rate);
                        $temp[] = $state;
                        $values[] = implode(',', $temp);
                    }
                }
                $startdate = $startdate->add(new DateInterval('P1D'));
            }
            // Save rate
            $query->values($values);
            $db->setQuery($query);
            $db->execute();
            $this->saveLog($frate, $weekdays, $jform);
            $db->transactionCommit();
            $mainframe->enqueueMessage('Saved successful');
        } catch (Exception $e) {
            $db->transactionRollback();
            JErrorPage::render($e);
            $mainframe->enqueueMessage($e->getMessage());
        }
        // 		if($apply)
        $this->setRedirect(JRoute::_('index.php?option=com_bookpro&view=tourrate&tour_id=' . $tour_id, false));
        // 		else
        // 			$this->setRedirect ( JRoute::_('index.php?option=com_bookpro&view=tours',false) );
    }
开发者ID:hixbotay,项目名称:executivetransport,代码行数:74,代码来源:tourrate.php

示例7: delete

 function delete()
 {
     $mainframe = JFactory::getApplication();
     $input = JFactory::getApplication()->input;
     $weekdays = $input->get('weekday', null, 'array');
     $data = $input->get('jform', array(), 'array');
     $startdate = new JDate($data['startdate']);
     $startclone = clone $startdate;
     $enddate = new JDate($data['enddate']);
     $starttoend = $startdate->diff($enddate)->days;
     // delete old record
     $transport_id = $data['transport_id'];
     $db = JFactory::getDbo();
     try {
         $db->transactionStart();
         $datearr = array();
         for ($i = 0; $i <= $starttoend; $i++) {
             $dw = (int) $startdate->format('N');
             if (in_array("{$dw}", $weekdays)) {
                 $datearr[] = 'DATE_FORMAT(`date`,"%Y-%m-%d")=' . $db->q($startdate->format('Y-m-d'));
             }
             $startdate = $startdate->add(new DateInterval('P1D'));
         }
         if (count($datearr) > 0) {
             $str = implode(' OR ', $datearr);
             $query = $db->getQuery(true);
             $query->delete('#__bookpro_transport_rate')->where('transport_id=' . $transport_id);
             $query->where('(' . $str . ')');
             //var_dump($query->dump());die;
             $db->setQuery($query);
             $db->execute();
         }
         $db->transactionCommit();
         $mainframe->enqueueMessage('Saved successful');
     } catch (Exception $e) {
         $db->transactionRollback();
         JErrorPage::render($e);
         $mainframe->enqueueMessage($e->getMessage());
     }
     $this->setRedirect('index.php?option=com_bookpro&view=packagerate&transport_id=' . $transport_id);
 }
开发者ID:hixbotay,项目名称:executivetransport,代码行数:41,代码来源:transportrate.php

示例8: harvest

 private function harvest()
 {
     $GLOBALS['application'] = $this;
     JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . '/tables');
     JModelLegacy::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . '/models', 'JHarvestModel');
     $harvests = JModelLegacy::getInstance('Harvests', 'JHarvestModel');
     $start = new JDate('now');
     JHarvestHelper::log("started " . (string) $start);
     $dispatcher = JEventDispatcher::getInstance();
     JPluginHelper::importPlugin('harvest');
     JPluginHelper::importPlugin('ingest');
     foreach ($harvests->getItems() as $harvest) {
         try {
             $now = new JDate('now');
             $table = JTable::getInstance('Harvest', 'JHarvestTable');
             $table->load($harvest->id);
             $table->now = $now;
             $dispatcher->trigger('onJHarvestRetrieve', array($table));
             $dispatcher->trigger('onJHarvestIngest', array($table));
             $query = JFactory::getDbo()->getQuery(true);
             $query->select('count(id)')->from('#__jharvest_cache');
             $total = (int) JFactory::getDbo()->setQuery($query)->loadResult();
             // only record last successful harvest which had records.
             if ($total > 0) {
                 $table->harvested = $now->toSql();
             }
             $table->runs++;
             if ((bool) $table->run_once === true) {
                 $table->state = 2;
             }
             $table->store();
         } catch (Exception $e) {
             JHarvestHelper::log($e->getMessage() . "\n");
             JHarvestHelper::log($e->getTraceAsString() . "\n");
         }
         // clear the cache, even if there is an error.
         JHarvestHelper::clearCache();
     }
     $end = new JDate('now');
     JHarvestHelper::log('ended ' . (string) $end);
     JHarvestHelper::log($start->diff($end)->format("%H:%I:%S"));
 }
开发者ID:knowledgearcdotorg,项目名称:jharvest,代码行数:42,代码来源:jharvest.php

示例9: index

 protected function index()
 {
     $indexingParams = array();
     if ($this->input->getString('u') || $this->input->getString('update')) {
         $lastModified = $this->input->getString('u', $this->input->getString('update'));
         $d = JDate::createFromFormat("Y-m-d\\TH:i:sP", $lastModified, new DateTimeZone(JFactory::getConfig()->get('offset')));
         $valid = false;
         if ($d) {
             if ($d->getTimezone()) {
                 $format = "Y-m-d\\TH:i:s" . ($d->getTimezone()->getName() == 'Z' ? '\\Z' : 'P');
                 if ($d->format($format) == $lastModified) {
                     $valid = true;
                 }
             }
         }
         if ($valid) {
             $indexingParams['lastModified'] = $lastModified;
         } else {
             $client = \JSolr\Index\Factory::getService();
             if ($client->ping()) {
                 $response = $client->luke();
                 $indexingParams['lastModified'] = $response->index->lastModified;
             }
         }
     }
     $start = new JDate('now');
     $this->out("crawl start " . $start->format("c"));
     $this->_fireEvent('onIndex', array(get_class($this), $this->_isVerbose(), $indexingParams), $this->_getPlugin());
     $end = new JDate('now');
     $this->out("crawl end " . $end->format("c"));
     $time = $start->diff($end);
     $this->out("execution time: " . $time->format("%H:%I:%S"));
 }
开发者ID:bellodox,项目名称:jsolr,代码行数:33,代码来源:jsolr_crawler.php


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