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


PHP Utils\DateTime类代码示例

本文整理汇总了PHP中Nette\Utils\DateTime的典型用法代码示例。如果您正苦于以下问题:PHP DateTime类的具体用法?PHP DateTime怎么用?PHP DateTime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: generate

 /**
  * Generate table
  */
 protected function generate()
 {
     $days = $this->getSpecificDays();
     $table = new Table\Sheet();
     $line = new Table\Line();
     $lastTimeFrom = NULL;
     $lastTimeTo = NULL;
     $lastDay = NULL;
     $lastTags = NULL;
     $now = new DateTime();
     foreach ($days as $day) {
         $timeFrom = (new FilterTime\Def($day->openTime))->output;
         $timeTo = (new FilterTime\Def($day->closeTime))->output;
         if ($lastTimeFrom === $timeFrom && $lastTimeTo === $timeTo && $this->tagsAreSame($lastTags, $day->tags) && $lastDay !== NULL && (int) $lastDay->day->diff($day->day)->format('%r%a') === 1) {
             $line->dateTo = $day->day;
         } else {
             $lastTimeTo !== NULL && $table->addLine($line);
             $line = new Table\Line();
             $line->dateFrom = $day->day;
             $line->dateTo = $day->day;
             $line->tags = $day->tags;
             $this->lineAddTime($line, $timeFrom, $timeTo);
         }
         if ($day->day->format('Y-m-d') === $now->format('Y-m-d')) {
             $line->setActive();
         }
         $lastTags = $day->tags;
         $lastTimeFrom = $timeFrom;
         $lastTimeTo = $timeTo;
         $lastDay = $day;
     }
     $lastTimeTo !== NULL && $table->addLine($line);
     $this->generatedTable = $table;
 }
开发者ID:cothema,项目名称:opening-hours,代码行数:37,代码来源:SpecificDays.php

示例2: generate

 /**
  * Generate table
  */
 protected function generate()
 {
     $openingHours = $this->openingHours;
     $days = $this->getRelativeDays();
     $table = new Table\Sheet();
     foreach ($days as $day) {
         $line = new Table\Line();
         if ($day === 0) {
             $line->setActive();
         }
         $now = new DateTime();
         $dayOpeningHours = $openingHours->getDay($day === 0 ? $now : $now->modifyClone(($day > 0 ? '+' : '-') . $day . ' days'));
         $timeFrom = (new FilterTime\Def($dayOpeningHours->getOpenTime()))->getOutput();
         $timeTo = (new FilterTime\Def($dayOpeningHours->getCloseTime()))->getOutput();
         foreach ($this->timeFilters as $filter) {
             $timeFromFormatted = (new $filter($timeFrom))->getOutput();
             $timeToFormatted = (new $filter($timeTo))->getOutput();
         }
         $line->setTitle($day);
         $line->setTimeFrom($timeFrom);
         $line->setTimeFromFormatted($timeFromFormatted);
         $line->setTimeTo($timeTo);
         $line->setTimeToFormatted($timeToFormatted);
         $line->tags = $dayOpeningHours->tags;
         if ($dayOpeningHours instanceof \Cothema\OpeningHours\Model\SpecificDay) {
             $line->specific = TRUE;
         }
         $table->addLine($line);
     }
     $this->generatedTable = $table;
 }
开发者ID:cothema,项目名称:opening-hours,代码行数:34,代码来源:RelativeDays.php

示例3: isOk

 public function isOk()
 {
     $now = new DateTime();
     if ($this->active && intval($this->getExpiration()->format("U")) > intval($now->format("U"))) {
         return TRUE;
     }
     return FALSE;
 }
开发者ID:pogodi,项目名称:Scud,代码行数:8,代码来源:AccessToken.php

示例4: update

 public function update(Items\Base $item, $data)
 {
     if (preg_match('~^\\d{1,2}[/.]{1}[ ]{0,1}\\d{1,2}[/.]{1}[ ]{0,1}\\d{4}$~', $data, $arr)) {
         $dateArr = preg_split('/[.\\/]{1}[ ]{0,1}/s', $arr[0]);
         $date = new Nette\Utils\DateTime($dateArr[2] . '-' . $dateArr[1] . '-' . $dateArr[0]);
         $data = $date->format('Y-m-d');
     }
     return $data;
 }
开发者ID:trejjam,项目名称:contents,代码行数:9,代码来源:DateSubType.php

示例5: renderEmail

 public function renderEmail()
 {
     $person = $this->userManager->get($this->user->getId());
     $this->template->person = $person;
     $now = new DateTime();
     $diff = $now->diff($person->change_email_requested);
     if ($diff->h < 1 && $diff->days == 0) {
         $this->template->openStepTwo = TRUE;
     }
 }
开发者ID:aprila,项目名称:app-knowledge-base,代码行数:10,代码来源:UserSettingsPresenter.php

示例6: initializePayment

 /**
  * Set specific payment properties
  *
  * @param Payment $payment
  * @return void
  */
 public function initializePayment(Payment $payment)
 {
     $payment->setMerchantReference('12345678');
     $payment->setPaymentAmount(10000);
     $today = new DateTime();
     $shipDate = $today->modifyClone('+ 10 days');
     $payment->setShipBeforeDate($shipDate);
     $sessionValidity = $today->modifyClone('+ 30 minutes');
     $payment->setSessionValidity($sessionValidity);
 }
开发者ID:metisfw,项目名称:adyen,代码行数:16,代码来源:DummyPaymentOperation.php

示例7: getOpeningAtWarning

 /**
  * 
  * @return string|boolean
  */
 public function getOpeningAtWarning()
 {
     $timeModified = new DateTime($this->time);
     $timeModified->modify($this->warningOpeningDiff);
     $status = $this->getStatus();
     if ($status instanceof StatusModel\Closed && $this->isOpenedByTime($timeModified)) {
         return $this->openingAtByWeekDay($timeModified->format('w'));
     }
     return FALSE;
 }
开发者ID:cothema,项目名称:opening-hours,代码行数:14,代码来源:Status.php

示例8: distributionPlanIsCreated

 public function distributionPlanIsCreated()
 {
     $date = new DateTime();
     $from = '"' . $date->format('Y.m.d') . ' 00:00:00"';
     $to = '"' . $date->format('Y.m.d') . ' 23:59:00"';
     $data = $this->db->select('*')->from($this->table)->where('date>' . $from . ' AND date<' . $to)->fetchAll();
     if (isset($data[0])) {
         return true;
     }
     return false;
 }
开发者ID:ludik1,项目名称:transport_company,代码行数:11,代码来源:OrdersModel.php

示例9: createFromFormat

 /**
  * Convert string to DateTime
  *
  * @param string $value
  * @param bool $midnight
  * @return DateTime
  */
 public static function createFromFormat($value, $format, $midnight = TRUE)
 {
     if ($value === null) {
         $now = new \DateTime();
         //because of php 5.3 I have to split it to two lines.
         $dt = $now->setTimestamp(0);
         //oldest date
     } else {
         $dt = date_create_from_format($format, $value);
     }
     if ($midnight) {
         $dt->setTime(0, 0, 0);
     }
     return $dt;
 }
开发者ID:brabijan,项目名称:fio,代码行数:22,代码来源:String.php

示例10: createTemplate

 /**
  * @return Template
  */
 public function createTemplate(UI\Control $control = NULL)
 {
     $latte = $this->latteFactory->create();
     $template = new Template($latte);
     $presenter = $control ? $control->getPresenter(FALSE) : NULL;
     if ($control instanceof UI\Presenter) {
         $latte->setLoader(new Loader($control));
     }
     if ($latte->onCompile instanceof \Traversable) {
         $latte->onCompile = iterator_to_array($latte->onCompile);
     }
     array_unshift($latte->onCompile, function ($latte) use($control, $template) {
         $latte->getCompiler()->addMacro('cache', new Nette\Bridges\CacheLatte\CacheMacro($latte->getCompiler()));
         UIMacros::install($latte->getCompiler());
         if (class_exists(Nette\Bridges\FormsLatte\FormMacros::class)) {
             Nette\Bridges\FormsLatte\FormMacros::install($latte->getCompiler());
         }
         if ($control) {
             $control->templatePrepareFilters($template);
         }
     });
     $latte->addFilter('url', 'rawurlencode');
     // back compatiblity
     foreach (['normalize', 'toAscii', 'webalize', 'padLeft', 'padRight', 'reverse'] as $name) {
         $latte->addFilter($name, 'Nette\\Utils\\Strings::' . $name);
     }
     $latte->addFilter('null', function () {
     });
     $latte->addFilter('modifyDate', function ($time, $delta, $unit = NULL) {
         return $time == NULL ? NULL : Nette\Utils\DateTime::from($time)->modify($delta . $unit);
         // intentionally ==
     });
     if (!isset($latte->getFilters()['translate'])) {
         $latte->addFilter('translate', function (Latte\Runtime\FilterInfo $fi) {
             throw new Nette\InvalidStateException('Translator has not been set. Set translator using $template->setTranslator().');
         });
     }
     // default parameters
     $template->user = $this->user;
     $template->baseUri = $template->baseUrl = $this->httpRequest ? rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/') : NULL;
     $template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUrl);
     $template->flashes = [];
     if ($control) {
         $template->control = $control;
         $template->presenter = $presenter;
         $latte->addProvider('uiControl', $control);
         $latte->addProvider('uiPresenter', $presenter);
         $latte->addProvider('snippetBridge', new Nette\Bridges\ApplicationLatte\SnippetBridge($control));
     }
     $latte->addProvider('cacheStorage', $this->cacheStorage);
     // back compatibility
     $template->_control = $control;
     $template->_presenter = $presenter;
     $template->netteCacheStorage = $this->cacheStorage;
     if ($presenter instanceof UI\Presenter && $presenter->hasFlashSession()) {
         $id = $control->getParameterId('flash');
         $template->flashes = (array) $presenter->getFlashSession()->{$id};
     }
     return $template;
 }
开发者ID:hrach,项目名称:nette-application,代码行数:63,代码来源:TemplateFactory.php

示例11: formSucceeded

 public function formSucceeded(Form $form)
 {
     try {
         $p = $this->getPresenter();
         $values = $form->getValues();
         $latest = $this->wikiDraftRepository->getLatestByWiki($this->item);
         $start = DateTime::from($values->startTime);
         if ($latest && $start < $latest->createdAt) {
             throw new Exceptions\WikiDraftConflictException($this->translator->translate('locale.error.newer_draft_created_meanwhile'));
         }
         unset($values->name);
         unset($values->startTime);
         $this->wikiDraftRepository->create($values, $this->user, $this->item, new Entities\WikiDraftEntity());
         $ent = $this->item;
         $p->flashMessage($this->translator->translate('locale.item.updated'));
     } catch (Exceptions\WikiDraftConflictException $e) {
         $this->newerDraftExists = true;
         $this->addFormError($form, $e);
     } catch (Exceptions\MissingTagException $e) {
         $this->addFormError($form, $e);
     } catch (PossibleUniqueKeyDuplicationException $e) {
         $this->addFormError($form, $e);
     } catch (\Exception $e) {
         $this->addFormError($form, $e, $this->translator->translate('locale.error.occurred'));
     }
     if (!empty($ent)) {
         $p->redirect('this');
     }
 }
开发者ID:CSHH,项目名称:website,代码行数:29,代码来源:WikiDraftForm.php

示例12: getValue

 /**
  * @return Nette\Utils\DateTime|NULL
  */
 public function getValue()
 {
     if ($this->value instanceof DateTime) {
         // clone
         return Nette\Utils\DateTime::from($this->value);
     } elseif (is_int($this->value)) {
         // timestamp
         return Nette\Utils\DateTime::from($this->value);
     } elseif (empty($this->value)) {
         return NULL;
     } elseif (is_string($this->value)) {
         $parsers = $this->parsers;
         $parsers[] = $this->getDefaultParser();
         foreach ($parsers as $parser) {
             $value = $parser($this->value);
             if ($value instanceof DateTime) {
                 return $value;
             }
         }
         try {
             // DateTime constructor throws Exception when invalid input given
             return Nette\Utils\DateTime::from($this->value);
         } catch (\Exception $e) {
             return NULL;
         }
     }
     return NULL;
 }
开发者ID:pavelkouril,项目名称:nextras-forms,代码行数:31,代码来源:DateTimePickerPrototype.php

示例13: sinceDate

 public function sinceDate($placeId, $date = null, $count = 7)
 {
     $files = array();
     $dir = dir($this->resolveDir($placeId));
     if ($dir === false) {
         return array();
     }
     while (false != ($entry = $dir->read())) {
         if (strrpos($entry, '.') != 10 || strrchr($entry, '.') != '.tmp') {
             continue;
         }
         // add filename without ext
         $files[] = strstr($entry, '.', true);
     }
     sort($files);
     $datePlain = is_int($date) ? date('Y-m-d', $date) : $date;
     $pos = 0;
     self::binarySearch($datePlain, $files, 'strcmp', $pos);
     $selection = array_slice($files, $pos, $count);
     $result = array();
     foreach ($selection as $item) {
         $itemDate = DateTime::createFromFormat('Y-m-d', $item)->getTimestamp();
         $result[$itemDate] = $this->forDate($placeId, $item);
     }
     return $result;
 }
开发者ID:arcao,项目名称:menza-nette,代码行数:26,代码来源:MealMenu.php

示例14: getValue

 /**
  * Returns date
  *
  * @return mixed
  */
 public function getValue()
 {
     if (strlen($this->value) > 0) {
         return DateTime::createFromFormat($this->format, $this->value);
     }
     return $this->value;
 }
开发者ID:bombush,项目名称:NatsuCon,代码行数:12,代码来源:TbDatePicker.php

示例15: handleUpdateDate

 public function handleUpdateDate($firstName, $surName, $mail, $date, $type, $spz, $tel, $carMakes, $carModel, $additionalInfo)
 {
     if ($this->isAjax()) {
         $this->defaults = array('firstName' => $firstName, 'surName' => $surName, 'mail' => $mail, 'date' => $date, 'type' => $type, 'spz' => $spz, 'telNumber' => $tel, 'carMakes' => $carMakes, 'carModel' => $carModel, 'additionalInfo' => $additionalInfo);
         $day = date('N', strtotime(str_replace(' ', '', $date)));
         $multiplier = 0;
         switch ($type) {
             case 5:
                 $multiplier = 1;
                 break;
             case 6:
                 $multiplier = 3;
                 break;
             case 7:
                 $multiplier = 3;
                 break;
         }
         if ($day != 7) {
             $this->timeIntervals = $this->reservationManager->getIntervalsForDay(Nette\Utils\DateTime::createFromFormat('d. m. Y', $date), $multiplier);
         } else {
             $this->timeIntervals = array(Model\ExceptionMessages::NOT_DEFINED => 'Zavřeno');
         }
         $this->redrawControl('addReservationSnippet');
     }
 }
开发者ID:hondem,项目名称:mcpneu,代码行数:25,代码来源:ReservationPresenter.php


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