本文整理汇总了PHP中Nette\Utils\DateTime类的典型用法代码示例。如果您正苦于以下问题:PHP DateTime类的具体用法?PHP DateTime怎么用?PHP DateTime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DateTime类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: createComponentFaktura
protected function createComponentFaktura()
{
$dateNow = new DateTime();
$variableSymbol = 123;
$supplierBuilder = new ParticipantBuilder("company", "Street", '', "City", "Postcode");
$supplier = $supplierBuilder->setIn(1111)->setTin("CZ1111")->setAccountNumber("123/0800")->build();
$nazev = "Customer Name";
$customerBuilder = new ParticipantBuilder($nazev, "Customer street", '', "Customer city", "Postcode");
$customer = $customerBuilder->build();
$items = array(new ItemImpl('Sample item', 1, 1111, TaxImpl::fromPercent(22), false));
$dataBuilder = new DataBuilder(999, 'Faktura', $supplier, $customer, $dateNow->modifyClone("+14 days"), $dateNow, $items);
$dataBuilder->setVariableSymbol($variableSymbol)->setDateOfVatRevenueRecognition($dateNow->modifyClone("+15 days"));
$data = $dataBuilder->build();
$env = new Eciovni($data);
$env->setTemplatePath(__DIR__ . "/templates/faktura.latte");
return $env;
}
开发者ID:chapcz,项目名称:sandbox,代码行数:17,代码来源:HomepagePresenter.php
示例17: validityCheck
public function validityCheck($form)
{
$values = $form->getValues();
if ($values->password != $values->password2) {
$form->addError('Obě varianty hesla musí být stejné.');
}
$bdate = new \Nette\Utils\DateTime($values->birthdate);
$diff = $bdate->diff(new \Nette\Utils\DateTime());
$diff = $diff->format('%d');
if ($diff < 7) {
$form->addError('Uživatelé by měli být starší než jeden týden. ' . $diff . ' dní je příliš málo.');
}
$data = $this->model->getSelection()->where(array("email" => $values->email))->fetch();
if ($data) {
$form->addError('Email ' . $values->email . ' je již používán.');
}
}
开发者ID:rawac,项目名称:agenda,代码行数:17,代码来源:RegistrationForm.php
示例18: createFromArray
/**
* @param array $data
* @return Address
*/
public static function createFromArray(array $data)
{
$data['first_seen'] = DateTime::createFromFormat(DateTime::ATOM, $data['first_seen']);
$data['last_seen'] = DateTime::createFromFormat(DateTime::ATOM, $data['last_seen']);
$address = new Address();
$address->data = $data;
return $address;
}
开发者ID:brosland,项目名称:blocktrail,代码行数:12,代码来源:Address.php
示例19: createFromArray
/**
* @param array $data
* @return Block
*/
public static function createFromArray(array $data)
{
$data['block_time'] = DateTime::createFromFormat(DateTime::ATOM, $data['block_time']);
$data['arrival_time'] = DateTime::createFromFormat(DateTime::ATOM, $data['arrival_time']);
$block = new Block();
$block->data = $data;
return $block;
}
开发者ID:brosland,项目名称:blocktrail,代码行数:12,代码来源:Block.php
示例20: getDefaultParser
protected function getDefaultParser()
{
return function ($value) {
if (!preg_match('#^(?P<dd>\\d{1,2})[. -] *(?P<mm>\\d{1,2})([. -] *(?P<yyyy>\\d{4})?)?$#', $value, $matches)) {
return NULL;
}
$dd = $matches['dd'];
$mm = $matches['mm'];
$yyyy = isset($matches['yyyy']) ? $matches['yyyy'] : date('Y');
if (!checkdate($mm, $dd, $yyyy)) {
return NULL;
}
$value = new Nette\Utils\DateTime();
$value->setDate($yyyy, $mm, $dd);
$value->setTime(0, 0, 0);
return $value;
};
}
开发者ID:pavelkouril,项目名称:nextras-forms,代码行数:18,代码来源:DatePicker.php
注:本文中的Nette\Utils\DateTime类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论