本文整理汇总了PHP中Zend_Date::sub方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Date::sub方法的具体用法?PHP Zend_Date::sub怎么用?PHP Zend_Date::sub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Date
的用法示例。
在下文中一共展示了Zend_Date::sub方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: relativeDateTime
public function relativeDateTime(Zend_Date $date = null)
{
if (null === $date) {
return $this;
}
$todayDate = new Zend_Date();
$diff = $todayDate->sub($date);
$mt = new Zend_Measure_Time($diff);
$units = $mt->getConversionList();
$chunks = array(Zend_Measure_Time::YEAR, Zend_Measure_Time::MONTH, Zend_Measure_Time::WEEK, Zend_Measure_Time::DAY, Zend_Measure_Time::HOUR, Zend_Measure_Time::MINUTE, Zend_Measure_Time::SECOND);
for ($i = 0, $count = count($chunks); $i < $count; ++$i) {
$seconds = $units[$chunks[$i]][0];
$unitKey = $chunks[$i];
if (0.0 !== ($result = floor($diff->get(Zend_Date::TIMESTAMP) / $seconds))) {
break;
}
}
$translateHelper = new Zend_View_Helper_Translate();
if ($result === (double) 1) {
$formatedString = $translateHelper->translate($this->getUnitTemplate($unitKey));
} else {
$formatedString = $translateHelper->translate($this->getUnitTemplate($unitKey . 'S'));
}
$formatedString = str_replace('%value%', (string) $result, $formatedString);
return $formatedString;
}
示例2: getLog
/**
* this method returns the access for the last
* 2 weeks. it automatically cleans itself (drops any records older than
* 2 weeks.)
*
*/
public function getLog()
{
$date = new Zend_Date();
$date->sub('2', Zend_Date::WEEK);
$this->delete('date_time < ' . $date->get(Zend_Date::TIMESTAMP));
return $this->fetchAll(null, 'date_time DESC');
}
示例3: andamento
public function andamento($projeto_id)
{
$porcentagem = 0;
$trabalhados = 0;
$horas_projeto = 0;
$horas_trabalhadas = 0;
// dados do projeto
$modelProjeto = new Model_DbTable_Projeto();
$projeto = $modelProjeto->getById($projeto_id);
$horas_projeto = $projeto->projeto_horas;
$modelControleHoras = new Model_DbTable_ControleHoras();
$horas = $modelControleHoras->fetchAll("projeto_id = {$projeto_id}");
foreach ($horas as $hora) {
$zendDateInicio = new Zend_Date($hora->controle_horas_data_inicio);
$zendDateFim = new Zend_Date($hora->controle_horas_data_fim);
$trabalhados += $zendDateFim->sub($zendDateInicio)->get(Zend_Date::TIMESTAMP);
}
// converte horas trabalhadas para horas
$horas_trabalhadas = $trabalhados / 3600;
if ($horas_trabalhadas < 1) {
return 0;
}
if ($horas_projeto == 0) {
return 100;
}
$porcentagem = number_format($horas_trabalhadas * 100 / $horas_projeto, 2, '.', '');
return $porcentagem;
}
示例4: pruneOldBackups
public function pruneOldBackups()
{
$current_bucket = Mage::getStoreConfig('system/cloudbackup/bucket_name');
if (!$current_bucket) {
$this->log("No bucket is set, we cannot prune old backups.");
return;
}
$s3 = Mage::helper('cloudbackup')->getS3Client();
try {
$bucket_contents = $s3->getBucket($current_bucket);
$cutoff_date = new Zend_Date();
$cutoff_date->sub($this->NUM_MONTHS, Zend_Date::MONTH);
foreach ($bucket_contents as $key) {
$bucket_date = new Zend_Date($key['time'], Zend_Date::TIMESTAMP);
if ($bucket_date->compare($cutoff_date) == -1) {
$this->log($key['name'] . " was created on {$bucket_date} and is older than " . $this->NUM_MONTHS . " months, deleting.");
$s3->deleteObject($current_bucket, $key['name']);
}
}
} catch (Exception $e) {
Mage::logException($e);
$this->log("Failed to while pruning old backups - please see exception.log for details.");
return;
}
}
示例5: isValid
public function isValid($data)
{
$isValid = parent::isValid($data);
if (empty($data['phone_number']) && empty($data['sms_id']) && (empty($data['date_until']) || empty($data['date_from']))) {
$this->addErrorMessage('"Data do" i "Data od" sa wymagane jeżeli nie podasz "SMS ID" lub Numeru telefonu');
return false;
}
if (empty($data['sms_id']) && empty($data['phone_number'])) {
try {
$dateCheck = new Zend_Date($data['date_from']);
if (!$dateCheck->isEarlier($data['date_until']) and 0 != strcmp($data['date_from'], $data['date_until'])) {
$isValid = false;
$this->addErrorMessage('"Data do" nie może być wcześniejsza niż "Data od"!');
}
$dateSub = new Zend_Date($data['date_until']);
$config = Zend_Registry::get('config');
if ($dateSub->sub($dateCheck)->toValue('DD') > $config['search']['mail']['filter']['interval']) {
$isValid = false;
$this->addErrorMessage('Maksymalny okres z jakiego można wyszukiwać dane to ' . $config['search']['sms']['filter']['interval'] . ' dni');
}
} catch (Exception $ex) {
$this->addErrorMessage($ex->getMessage());
$isValid = false;
}
}
return $isValid;
}
示例6: FilteredBlogEntries
/**
* Determine selected BlogEntry items to show on this page
*
* @param int $limit
* @return PaginatedList
*/
public function FilteredBlogEntries($limit = null)
{
require_once 'Zend/Date.php';
if ($limit === null) {
$limit = BlogTree::$default_entries_limit;
}
// only use freshness if no action is present (might be displaying tags or rss)
if ($this->owner->LandingPageFreshness && !$this->owner->request->param('Action')) {
$d = new Zend_Date(SS_Datetime::now()->getValue());
$d->sub($this->owner->LandingPageFreshness, Zend_Date::MONTH);
$date = $d->toString('YYYY-MM-dd');
$filter = "\"BlogEntry\".\"Date\" > '{$date}'";
} else {
$filter = '';
}
// allow filtering by author field and some blogs have an authorID field which
// may allow filtering by id
if (isset($_GET['author']) && isset($_GET['authorID'])) {
$author = Convert::raw2sql($_GET['author']);
$id = Convert::raw2sql($_GET['authorID']);
$filter .= " \"BlogEntry\".\"Author\" LIKE '" . $author . "' OR \"BlogEntry\".\"AuthorID\" = '" . $id . "'";
} else {
if (isset($_GET['author'])) {
$filter .= " \"BlogEntry\".\"Author\" LIKE '" . Convert::raw2sql($_GET['author']) . "'";
} else {
if (isset($_GET['authorID'])) {
$filter .= " \"BlogEntry\".\"AuthorID\" = '" . Convert::raw2sql($_GET['authorID']) . "'";
}
}
}
$date = $this->owner->SelectedDate();
return $this->owner->Entries($limit, $this->owner->SelectedTag(), $date ? $date : '', array(get_class($this), 'FilterByDate'), $filter);
}
开发者ID:helpfulrobot,项目名称:zirak-blog-post-publication-period,代码行数:39,代码来源:AdminPublicationPostDate.php
示例7: indexAction
public function indexAction()
{
/**
* Total de clientes
*/
$modelClientes = new Model_DbTable_Cliente();
$this->view->clientes = $modelClientes->fetchAll();
/**
* Total de propostas
*/
$modelProposta = new Model_DbTable_Proposta();
$propostas = $modelProposta->fetchAll();
$this->view->propostas = $propostas;
$total_horas_propostas = 0;
$total_valor_propostas = 0;
foreach ($propostas as $proposta) {
$total_horas_propostas += $proposta->proposta_horas;
$total_valor_propostas += $proposta->proposta_valor;
}
$this->view->total_horas_proposta = $total_horas_propostas;
$this->view->total_valor_proposta = $total_valor_propostas;
/**
* Total de Projetos
*/
$modelProjeto = new Model_DbTable_Projeto();
$projetos = $modelProjeto->fetchAll();
$this->view->projetos = $projetos;
/**
* Total Faturamento
*/
$modelFaturamento = new Model_DbTable_Faturamento();
$faturamentos = $modelFaturamento->fetchAll();
$faturamento_total = 0;
$receber = 0;
$recebido = 0;
foreach ($faturamentos as $faturamento) {
if ($faturamento->faturamento_status === self::STATUS_AGUARDANDO_PAGAMENTO) {
$receber += $faturamento->faturamento_valor;
}
if ($faturamento->faturamento_status === self::STATUS_PAGO) {
$recebido += $faturamento->faturamento_valor;
}
$faturamento_total += $faturamento->faturamento_valor;
}
$this->view->faturamento_total = $faturamento_total;
$this->view->receber = $receber;
$this->view->recebido = $recebido;
/**
* Total de Horas Trbalhadas
*/
$modelControleHoras = new Model_DbTable_ControleHoras();
$horas = $modelControleHoras->fetchAll();
$horas_trabalhadas = 0;
foreach ($horas as $hora) {
$zendDateInicio = new Zend_Date($hora->controle_horas_data_inicio);
$zendDateFim = new Zend_Date($hora->controle_horas_data_fim);
$horas_trabalhadas += $zendDateFim->sub($zendDateInicio)->get(Zend_Date::TIMESTAMP);
}
$this->view->horas = ceil($horas_trabalhadas / 3600);
}
示例8: collectValidatedAttributes
public function collectValidatedAttributes($productCollection)
{
$attribute = $this->getAttribute();
$arr = explode('_', $attribute);
$type = $arr[0];
$period = $arr[1];
$date = new Zend_Date();
$date->sub($period * 24 * 60 * 60);
$resource = Mage::getSingleton('core/resource');
$connection = $resource->getConnection('core_read');
switch ($type) {
case 'clicks':
$expr = new Zend_Db_Expr('SUM(clicks)');
break;
case 'orders':
$expr = new Zend_Db_Expr('SUM(orders)');
break;
case 'revenue':
$expr = new Zend_Db_Expr('SUM(revenue)');
break;
case 'cr':
$expr = new Zend_Db_Expr('SUM(orders) / SUM(clicks) * 100');
break;
}
$select = $connection->select();
$select->from(array('ta' => $resource->getTableName('feedexport/performance_aggregated')), array($expr))->where('ta.product_id = e.entity_id')->where('ta.period >= ?', $date->toString('YYYY-MM-dd'));
$select = $productCollection->getSelect()->columns(array($attribute => $select));
return $this;
}
示例9: getTotal
/**
* Calculate the difference in seconds between closed and opened
*
* @return int
*/
public function getTotal()
{
if ($this->isOpen()) {
return 0;
}
$opened = new Zend_Date($this->opened);
$closed = new Zend_Date($this->closed);
return $closed->sub($opened);
}
示例10: dateSub
/**
* This uses the zend framwork date sub function.
* Good for subtracting a number of days from a date.
*
* @param string $datestring MySQL formatted Date String Y-m-d.
* @param string number of days to be subtracted.
* @return string result date formatted as a MySQL Date Y-m-d.
*/
public function dateSub($datestring, $numberofdays = 1)
{
$dateEl = explode("-", $datestring);
$datearray = array('year' => date($dateEl[0]), 'month' => date($dateEl[1]), 'day' => date($dateEl[2]));
$rmdate = new Zend_Date($datearray);
$rmdate->sub($numberofdays, Zend_Date::DAY);
$dateVal = $rmdate->toString('Y-m-d');
return $dateVal;
}
示例11: weeklystatsAction
public function weeklystatsAction()
{
$this->disableLayout();
$this->disableViewAutoRender();
$type = $this->getParam('type');
$end = new Zend_Date();
$end->setTime('23:59:59');
$date = new Zend_Date();
$date->sub(6, Zend_Date::DAY);
$date->setTime('00:00:01');
//Build reference array
$i = 0;
//echo $end->getTimestamp(); echo "<br>";
while ($i <= 6) {
$referencearray[$date->get('dd-MM-YYYY')] = 0;
$date->add(1, Zend_Date::DAY);
$i++;
}
//Get the results array
$start = new Zend_date();
$start->sub(6, Zend_Date::DAY);
$start->setTime('00:00:01');
$stat = new \Object\Stats();
$results = $stat->getStatistics($this->selectedLocation->getId(), $start, $end);
$startoftheweek = $start->get('dd-MM-YYYY');
//echo $start->getTimestamp(); echo "<br>";exit;
foreach ($this->selectedLocation->getServings() as $serving) {
//initiate orderarray and seatsarray
$orderarray = $referencearray;
$seatsarray = $referencearray;
foreach ($results as $result) {
$datein = date("d-m-Y", $result["date_start"]);
if ($serving->getId() == $result['serving_id']) {
$servingid = $result['serving_id'];
if (array_key_exists($datein, $referencearray)) {
$orderarray[$datein] = $result["nbre"];
$seatsarray[$datein] = $result["couverts"];
}
}
}
if ($type == 'seats') {
$servingarray[$serving->getTitle()] = $seatsarray;
} else {
$servingarray[$serving->getTitle()] = $orderarray;
}
}
$reponse = new Reponse();
$reponse->data = $servingarray;
$reponse->message = "TXT_STATS_SENT";
$reponse->success = true;
$this->render($reponse);
}
示例12: isBeforeEditDeadline
/**
* Is this current time before the edit deadline?
*
* Assumes config directive core.presentation.deadline
*
* @return boolean
*/
public function isBeforeEditDeadline()
{
$config = Zend_Registry::get('config');
$tStart = $this->getTable()->getAdapter()->fetchOne("select tstart from vw_sessions left join vw_session_presentations sp" . " ON (vw_sessions.session_id = sp.session_id) where presentation_id=:presentation_id", array(':presentation_id' => $this->presentation_id));
if ($tStart) {
$now = new Zend_Date();
$tStart = new Zend_Date($tStart, Zend_Date::ISO_8601);
$deadline = $tStart->sub($config->core->presentation->deadline, Zend_Date::SECOND);
if ($now->isEarlier($deadline)) {
return true;
}
}
return false;
}
示例13: getbookdetailsAction
public function getbookdetailsAction()
{
self::createModel();
$request = $this->getRequest();
$acc_no = $request->getParam('acc_no');
$objIsbn = new Lib_Model_DbTable_Isbn();
$objIssueReturn = new Lib_Model_DbTable_IssueReturn();
$book = array();
if (isset($acc_no)) {
$bookInfo = Lib_Model_DbTable_Book::getBookInfo($acc_no);
if (isset($bookInfo['isbn_id'])) {
$book = $objIsbn->getIsbnDetails($bookInfo['isbn_id']);
$bookIssued = $objIssueReturn->getIssuedBookInfo($acc_no);
//$this->_helper->logger($bookIssued);
if ($bookIssued) {
$issueDate = new Zend_Date($bookIssued['issue_date'], Zend_Date::ISO_8601);
$book['member_id'] = $bookIssued['member_id'];
$member_limit = Lib_Model_DbTable_MembershipLimit::getMemberLimit($book['member_id'], $bookInfo['document_type_id']);
if (isset($_SESSION['dateFormat'])) {
$dateFormat = $_SESSION['dateFormat'];
} else {
$dateFormat = 'dd/MMM/yyyy';
}
$book['issue_date'] = $issueDate->toString($dateFormat);
$exp_return_date = $issueDate->addDay($member_limit['day_limit']);
$day_late = 0;
$objtoday = new Zend_Date(Zend_Date::now(), $dateFormat);
if ($exp_return_date->isToday() || $objtoday->isEarlier($exp_return_date)) {
$day_late = 0;
} else {
$objtoday->sub($exp_return_date);
$day_late = $objtoday->get(Zend_Date::DAY) - 2;
}
$book['exp_return_date'] = $exp_return_date->toString($dateFormat);
$book['day_late'] = $day_late;
$bookStatus = 1;
}
$book['bookInfo'] = $bookInfo;
$this->_helper->json($book);
//echo Zend_Json::encode($book);
} else {
$this->getResponse()->setHttpResponseCode(400);
echo 'Either the Acc No "' . $acc_no . '" or its corrosponding ISBN is invalid.';
}
} else {
$this->getResponse()->setHttpResponseCode(400);
echo 'Parameters are insufficient to process.';
}
}
示例14: processOldLogs
public function processOldLogs()
{
$Date = new Zend_Date();
Zend_Date::setOptions(array('extend_month' => true));
$Date->sub(Mage::getStoreConfig(self::XML_PATH_LOGGER_STORE_DAYS), Zend_Date::DAY);
$collection = $this->getCollection()->addOlderThanFilter($Date);
if (Mage::getStoreConfig(self::XML_PATH_ENABLE_ARCHIVATION)) {
$resourceSingleton = Mage::getResourceSingleton('aw_lib/logger');
$sql = $resourceSingleton->getPartInsertSql('aw_lib_logger', $collection->getSelect());
$resourceSingleton->createBackupFile($sql);
}
foreach ($collection as $entry) {
$entry->delete();
}
return $this;
}
示例15: fieldBirthdate
public function fieldBirthdate($subject, $field, $value)
{
$label = $this->view->locale()->toDate($value->value, array('size' => 'long', 'timezone' => false));
//$str = $this->view->date($value->value);
$parts = @explode('-', $value->value);
// Error if not filled out
if (count($parts) < 3 || count(array_filter($parts)) < 3) {
//$this->addError('Please fill in your birthday.');
return false;
}
$value = mktime(0, 0, 0, $parts[1], $parts[2], $parts[0]);
// Error if too low
$date = new Zend_Date($value);
$age = (int) (-$date->sub(time()) / 365 / 86400);
return $this->encloseInLink($subject, $field, $age, $label, true);
}