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


PHP DateTime::from方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: createTemplate

 /**
  * @return UI\ITemplate
  */
 protected function createTemplate()
 {
     /** @var Nette\Bridges\ApplicationLatte\Template $template */
     $template = parent::createTemplate();
     $latte = $template->getLatte();
     $latte->addFilter('texy', function ($input) {
         $texy = $this->prepareTexy();
         $html = new Nette\Utils\Html();
         return $html::el()->setHtml($texy->process($input));
     });
     $latte->addFilter('vlna', function ($string) {
         $string = preg_replace('<([^a-zA-Z0-9])([ksvzaiou])\\s([a-zA-Z0-9]{1,})>i', "\$1\$2 \$3", $string);
         //&nbsp; === \xc2\xa0
         return $string;
     });
     $latte->addFilter('dateInWords', function ($time) {
         $time = Nette\Utils\DateTime::from($time);
         $months = [1 => 'leden', 'únor', 'březen', 'duben', 'květen', 'červen', 'červenec', 'srpen', 'září', 'říjen', 'listopad', 'prosinec'];
         return $time->format('j. ') . $months[$time->format('n')] . $time->format(' Y');
     });
     $latte->addFilter('timeAgoInWords', function ($time) {
         $time = Nette\Utils\DateTime::from($time);
         $delta = round((time() - $time->getTimestamp()) / 60);
         if ($delta == 0) {
             return 'před okamžikem';
         }
         if ($delta == 1) {
             return 'před minutou';
         }
         if ($delta < 45) {
             return "před {$delta} minutami";
         }
         if ($delta < 90) {
             return 'před hodinou';
         }
         if ($delta < 1440) {
             return 'před ' . round($delta / 60) . ' hodinami';
         }
         if ($delta < 2880) {
             return 'včera';
         }
         if ($delta < 43200) {
             return 'před ' . round($delta / 1440) . ' dny';
         }
         if ($delta < 86400) {
             return 'před měsícem';
         }
         if ($delta < 525960) {
             return 'před ' . round($delta / 43200) . ' měsíci';
         }
         if ($delta < 1051920) {
             return 'před rokem';
         }
         return 'před ' . round($delta / 525960) . ' lety';
     });
     return $template;
 }
开发者ID:mrtnzlml,项目名称:zlml.cz,代码行数:60,代码来源:BasePresenter.php

示例5: fromPlainToEntity

 /**
  * @param array $data
  * @return \FlickrDownloadr\Photo\Photo
  */
 public function fromPlainToEntity(array $data, $photoSizeName)
 {
     $code = $this->photoSizeHelper->getCode($photoSizeName);
     $url = $data['url_' . $code];
     $width = $data['width_' . $code];
     $height = $data['height_' . $code];
     $date = \Nette\Utils\DateTime::from($data['datetaken']);
     return new Photo($data, $url, $width, $height, $date);
 }
开发者ID:michalsanger,项目名称:cli-flickr-downloadr,代码行数:13,代码来源:Mapper.php

示例6: getMeta

 /**
  * @param SplFileInfo $articleDirectory
  * @param string $relativePath
  * @return array
  */
 private function getMeta($articleDirectory, $relativePath)
 {
     $filePath = sprintf('%s/%s', $articleDirectory->getRealPath(), self::META_FILE_NAME);
     $data = Neon::decode(file_get_contents($filePath));
     $data['perex'] = $this->parsedown->text($data['perex']);
     $data['publishedAt'] = $data['publishedAt'] ? DateTime::from($data['publishedAt']) : null;
     $data['imagePath'] = "{$relativePath}/" . self::IMAGE_NAME;
     $data['keyIdentifier'] = $this->parseKeyIdentifier($relativePath);
     return $data;
 }
开发者ID:Achse,项目名称:petrhejna,代码行数:15,代码来源:ArticleBuilder.php

示例7: processForm

 /**
  * @param \Nette\Application\UI\Form $form
  */
 public function processForm(Form $form)
 {
     $values = $form->values;
     $event = $this->event ? $this->event : new Entity\Event($this->securityUser->getIdentity());
     $event->name = $values->name;
     $event->date = DateTime::from($values->date);
     $event->place = $values->place;
     $event->note = $values->note;
     $this->eventFacade->save($event);
 }
开发者ID:Kotys,项目名称:eventor.io,代码行数:13,代码来源:SetEventForm.php

示例8: deleteOldEmpty

    /**
     * @return void
     *
     * Results of this function are periodically deleted
     * from production database. Update with caution!
     */
    public function deleteOldEmpty()
    {
        $this->connection->query('
			DELETE FROM [video_views]
			WHERE [percent] = 0
				AND [time] = 0
				AND [furthest] = 0
				AND [events]::text = "[]"
				AND [created_at] < ?
		', DateTime::from('7 days ago'));
    }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:17,代码来源:VideoViewsMapper.php

示例9: validate

 public function validate()
 {
     if ($this->createdAt < DateTime::from('- 3 days')) {
         throw new TokenExpiredException();
     }
     if ($this->used) {
         throw new TokenAlreadyUsedException();
     }
     if (!Passwords::verify($this->unsafe, $this->hash)) {
         throw new TokenNotValidException();
     }
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:12,代码来源:Token.php

示例10: onLogin

 /**
  * @subscribe
  * @param User $user
  */
 public function onLogin(User $user)
 {
     if ($user->getBadges($this->getKey())->count() !== 0) {
         // already awarded
         return;
     }
     if ($user->createdAt < DateTime::from('-1 week')) {
         $this->awardTo($user, function (Badge $badge, User $user) {
             return new Bridges\UserOldWeek($badge, $user);
         });
     }
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:16,代码来源:UserOldWeek.php

示例11: createTemplate

	/**
	 * @return Template
	 */
	public function createTemplate(UI\Control $control)
	{
		$latte = $this->latteFactory->create();
		$template = new Template($latte);
		$presenter = $control->getPresenter(FALSE);

		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->getParser()->shortNoEscape = TRUE;
			$latte->getCompiler()->addMacro('cache', new Nette\Bridges\CacheLatte\CacheMacro($latte->getCompiler()));
			UIMacros::install($latte->getCompiler());
			if (class_exists('Nette\Bridges\FormsLatte\FormMacros')) {
				Nette\Bridges\FormsLatte\FormMacros::install($latte->getCompiler());
			}
			$control->templatePrepareFilters($template);
		});

		$latte->addFilter('url', 'rawurlencode'); // back compatiblity
		foreach (array('normalize', 'toAscii', 'webalize', 'padLeft', 'padRight', 'reverse') as $name) {
			$latte->addFilter($name, 'Nette\Utils\Strings::' . $name);
		}
		$latte->addFilter('null', function () {});
		$latte->addFilter('length', function ($var) {
			return is_string($var) ? Nette\Utils\Strings::length($var) : count($var);
		});
		$latte->addFilter('modifyDate', function ($time, $delta, $unit = NULL) {
			return $time == NULL ? NULL : Nette\Utils\DateTime::from($time)->modify($delta . $unit); // intentionally ==
		});

		// default parameters
		$template->control = $template->_control = $control;
		$template->presenter = $template->_presenter = $presenter;
		$template->user = $this->user;
		$template->netteHttpResponse = $this->httpResponse;
		$template->netteCacheStorage = $this->cacheStorage;
		$template->baseUri = $template->baseUrl = $this->httpRequest ? rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/') : NULL;
		$template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUrl);
		$template->flashes = array();

		if ($presenter instanceof UI\Presenter && $presenter->hasFlashSession()) {
			$id = $control->getParameterId('flash');
			$template->flashes = (array) $presenter->getFlashSession()->$id;
		}

		return $template;
	}
开发者ID:nakoukal,项目名称:fakturace,代码行数:56,代码来源:TemplateFactory.php

示例12: setValue

 /**
  * Sets control's value.
  *
  * @return Date
  */
 public function setValue($value)
 {
     if ($value instanceof \DateTime) {
         $this->value = $value;
     } else {
         if (is_numeric($value) || is_string($value)) {
             $this->value = Nette\Utils\DateTime::from($value);
         } else {
             $this->value = NULL;
         }
     }
 }
开发者ID:webchemistry,项目名称:forms-controls,代码行数:17,代码来源:Date.php

示例13: renderStats

 public function renderStats()
 {
     $totalDownloads = [];
     // Calculate total downloads
     if ($stats = $this->addon->github->extra->get('composer-stats')) {
         foreach ($stats['all']['labels'] as $key => $label) {
             $totalDownloads[] = ['x' => DateTime::from($label)->format('c'), 'y' => $stats['all']['values'][$key]];
         }
     }
     $this->template->totalDownloads = json_encode($totalDownloads);
     $this->template->setFile(__DIR__ . '/templates/stats.latte');
     $this->template->render();
 }
开发者ID:milo,项目名称:componette.com,代码行数:13,代码来源:AddonDetail.php

示例14: setValue

 /**
  * @param \DateTime
  * @return BaseDateTime
  */
 public function setValue($value)
 {
     try {
         if ($value instanceof DateTime || $value instanceof \DibiDateTime) {
             parent::setValue($value->format($this->format));
         } elseif ($value != '') {
             $date = DateTime::from($value);
             parent::setValue($date->format($this->format));
         }
     } catch (\Exception $e) {
         return parent::setValue(NULL);
     }
 }
开发者ID:ludik1,项目名称:transport_company,代码行数:17,代码来源:BaseDateTime.php

示例15: convertToPHPValue

 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === NULL) {
         return NULL;
     } elseif ($value instanceof \DateTime) {
         return NetteDateTime::from($value);
     }
     $val = NetteDateTime::createFromFormat($platform->getDateTimeFormatString(), $value);
     if (!$val) {
         throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
     }
     return NetteDateTime::from($val);
 }
开发者ID:ATouhou,项目名称:db-benchmark,代码行数:13,代码来源:DateTimeType.php


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