本文整理汇总了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;
}
示例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;
}
示例3: isOk
public function isOk()
{
$now = new DateTime();
if ($this->active && intval($this->getExpiration()->format("U")) > intval($now->format("U"))) {
return TRUE;
}
return FALSE;
}
示例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;
}
示例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;
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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');
}
}
示例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;
}
示例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;
}
示例14: getValue
/**
* Returns date
*
* @return mixed
*/
public function getValue()
{
if (strlen($this->value) > 0) {
return DateTime::createFromFormat($this->format, $this->value);
}
return $this->value;
}
示例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');
}
}