本文整理汇总了PHP中Nette\Utils\DateTime::modify方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTime::modify方法的具体用法?PHP DateTime::modify怎么用?PHP DateTime::modify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Utils\DateTime
的用法示例。
在下文中一共展示了DateTime::modify方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* @param array $types
* @param \App\Model\Entities\Vote $vote
* @return Form
*/
public function create($types, $vote = NULL)
{
$form = $this->baseFormFactory->create();
$form->addText('question', 'system.voteQuestion')->setRequired($form->getTranslator()->translate('system.requiredItem', ['label' => '%label']));
$form->addSelect('type', 'system.voteType')->setItems($types)->setPrompt('Zvolte typ dotazu')->setRequired($form->getTranslator()->translate('system.requiredItem', ['label' => '%label']));
$form->addText('expiration', 'system.voteExpiration')->setType('datetime-local')->setAttribute('placeholder', 'd. m. Y, H:i (den. měsíc. rok, hodina:minuta');
$options = $form->addDynamic('options', function (Container $option) {
$option->addText('option', 'system.voteOption');
$option->addSubmit('remove', 'system.delete')->addRemoveOnClick();
}, 1);
$options->addSubmit('add', 'system.new')->setValidationScope(FALSE)->addCreateOnClick();
$form->addSubmit('send', 'system.save');
$form->addHidden('id');
if ($vote) {
$defaults = $this->getDefaults($vote);
$form->setDefaults($defaults);
$options->setValues($defaults['options']);
} else {
$today = new DateTime();
$today->modify('+6 month');
$default = ['expiration' => $today->format(self::$dateMask)];
$form->setDefaults($default);
}
$form->onValidate[] = [$this, 'validateForm'];
$form->onSuccess[] = [$this, 'formSucceeded'];
return $form;
}
示例2: 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;
}
示例3: createComponentExampleOneForm
public function createComponentExampleOneForm()
{
$form = new Form();
$form->addText('name', "Name:");
$form->addPassword('password', "Password:");
$form->addTextArea('textarea', "Textarea");
$form->addSelect('select', "Select", ['Option 1', 'Option 2']);
$form->addUpload('upload', 'Upload');
$form->addCheckbox('checkbox', 'Checkbox');
$form->addRadioList('radioList', 'Radio list', ['Item A', 'Item B']);
$form->addCheckboxList('checkboxList', 'Checkbox list,', ['Item A', 'Item B']);
$form->addText('date', 'Date:')->getControlPrototype()->class('b-date-input');
$form->addText('datetime', 'Date time:')->getControlPrototype()->class('b-date-input b-date-input--datetime');
$now = new DateTime();
$now->modify('+1 day');
$now->modify('+3 hour');
$form->setDefaults(['date' => $now, 'datetime' => $now]);
$form->addSubmit('actionSend', 'Save');
$form->onSuccess[] = array($this, 'exampleOneFormSubmitted');
return $form;
}
示例4: __construct
/**
* @param string|null $key
* @param DateTime|null $date
* @param boolean|null $active
*/
public function __construct($key = NULL, DateTime $date = NULL, $active = NULL)
{
if (NULL === $key) {
$this->key = Random::generate(self::KEY_LENGHT);
} else {
$this->key = $key;
}
if (NULL === $date) {
$date = new DateTime();
$date->modify('+5 minutes');
$this->expiration = $date;
} else {
$this->expiration = $date;
}
if (NULL === $active) {
$this->active = TRUE;
} else {
$this->active = $active;
}
}
示例5: removeExpired
/**
* Auto removes email file when expired.
* @param string
* @return bool
*/
private function removeExpired($path)
{
if ($this->autoremove) {
$now = new DateTime();
$file_date = new DateTime('@' . filemtime($path));
$file_date->setTimezone($now->getTimezone());
$remove_date = $now->modify($this->autoremove);
if ($file_date < $remove_date) {
unlink($path);
return TRUE;
}
}
return FALSE;
}
示例6: getRandArticles
/**
* Vraci nahodne clanky
* @param int $count
* @param DateTime|NULL $period
* @return Entities\Article[]
*/
public function getRandArticles($count = 1, $period = NULL)
{
if ($period === NULL) {
$now = new DateTime();
$period = $now->modify("-6 month");
}
$cacheId = 'rand-' . $count;
$countAllArticles = (int) $this->countAllArticles();
$query = "SELECT a FROM \\App\\Model\\Entities\\Article a WHERE a.published = true " . "AND a.publishDate >= :date ";
$randArticles = $this->em->createQuery($query)->setParameter('date', $period)->setMaxResults($count)->setFirstResult(mt_rand(0, $countAllArticles - 1))->useResultCache(TRUE, 600, $cacheId)->getResult();
return $randArticles;
}