本文整理汇总了PHP中DateTimeImmutable::add方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeImmutable::add方法的具体用法?PHP DateTimeImmutable::add怎么用?PHP DateTimeImmutable::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeImmutable
的用法示例。
在下文中一共展示了DateTimeImmutable::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_news
function get_news()
{
global $NEWS;
foreach ($NEWS as $i) {
#var_dump($i);
$class = $i['isImportant'] ? 'important' : '';
$now = new DateTimeImmutable('now');
$date = new DateTimeImmutable($i['date']);
$d_start = array_key_exists('dateOn', $i) ? new DateTime($i['dateOn']) : $now;
$d_end = array_key_exists('dateOff', $i) ? new DateTime($i['dateOff']) : $date->add(new DateInterval('P14D'));
#var_dump($date);
#var_dump($d_start);
#var_dump($d_end);
if ($now < $d_start or $now > $d_end) {
continue;
}
echo <<<HTML
<li class="{$class}">
<div class="newsitem">
<strong>{$i['title']}</strong>
<br />
{$i['text']}
</div>
</li>
HTML;
}
}
示例2: setUp
public function setUp()
{
$this->title = "myAuction1";
$this->description = "Some rubbish from my garage.";
$this->owner = new User("User01", "test01@test.tt");
$this->bidder = new User("Bidder01", "bidder01@test.tt");
$this->startPrice = new Money(1, new Currency('EUR'));
$this->startTime = new DateTimeImmutable();
$this->endTime = $this->startTime->add(new DateInterval("PT2H"));
}
示例3: expired
protected static function expired($past, $interval)
{
$past = new \DateTimeImmutable($past, new \DateTimeZone('UTC'));
$future = $past->add(new \DateInterval("PT{$interval}S"));
$now = new \DateTimeImmutable('2000-10-10 12:30:00', new \DateTimeZone('UTC'));
return $future <= $now;
}
示例4: ratioIntervalString
/**
* Return the given ratio of the given interval.
* @param \DateInterval $interval
* @param number $ratio 0 to 1
* @return string
*/
public static function ratioIntervalString(\DateInterval $interval, $ratio)
{
$reference = new \DateTimeImmutable();
$endTime = $reference->add($interval);
$seconds = $endTime->getTimestamp() - $reference->getTimestamp();
$seconds = $seconds * $ratio;
return sprintf("PT%dS", $seconds);
}
示例5: createRequestForSeconds
protected function createRequestForSeconds($seconds)
{
$interval = new \DateInterval('PT' . abs($seconds) . 'S');
$date = new \DateTimeImmutable('2015-01-01 00:00:00');
if ($seconds < 0) {
$baseDate = $date->add($interval);
} else {
$baseDate = $date->sub($interval);
}
return new DateDiffRequest($date, $baseDate);
}
示例6: scheduleAtSchedulesEventAtGivenTime
/**
* @test
*/
public function scheduleAtSchedulesEventAtGivenTime()
{
$eventBus = $this->createEventBus();
$event = $this->getMockBuilder(Event::class)->getMock();
$eventBus->expects(self::once())->method('publish')->with($event);
// schedule for execution 1 second from now
$now = new \DateTimeImmutable();
$time = $now->add(new \DateInterval('PT1S'));
$scheduler = new SimpleEventScheduler($eventBus);
$scheduler->scheduleAt($time, $event);
$this->wait(2);
}
示例7: periode
public function periode($beginn, $interval_spec)
{
$anfang_der_periode = new \DateTimeImmutable($beginn);
$periode = new \DatePeriod($anfang_der_periode, new \DateInterval('P1D'), $anfang_der_periode->add(new \DateInterval($interval_spec)));
$tage = array();
foreach ($periode as $datum) {
$tmp_tag = $this->tag($datum);
if ($tmp_tag) {
$tage[] = $tmp_tag;
}
}
return new Periode($tage);
}
示例8: testAdd
public function testAdd()
{
$time = '2000-01-02T03:14:25';
$immutable = new DateTimeImmutable($time);
$control = new DateTimeImmutable($time);
$mutable = new DateTime($time);
$interval = new DateInterval('P1D');
$new = $immutable->add($interval);
$mutable->add($interval);
$this->assertNotSame($immutable, $new);
$this->assertSame($control->format(DateTime::RFC3339), $immutable->format(DateTime::RFC3339));
$this->assertSame($mutable->format(DateTime::RFC3339), $new->format(DateTime::RFC3339));
}
示例9: setUp
public function setUp()
{
$this->description = $this->getMockBuilder('\\Domain\\Context\\Task\\ValueObject\\TaskDescription')->setConstructorArgs(array('don\'t forget the milk'))->setMethods(array('value'))->getMock();
$this->description->expects($this->any())->method('value')->will($this->returnValue('don\'t forget the milk'));
$today = new \DateTimeImmutable();
$this->dueDate = $today->add(new \DateInterval('P1D'));
$this->task = new Task();
$this->task->setDueDate($this->dueDate)->setDescription($this->description);
$mockDueDateSpecification = $this->getMockBuilder('\\Domain\\Context\\Task\\Specification\\TaskFutureDueDate')->setMethods(array('isSatisfiedBy'))->getMock();
$mockDueDateSpecification->expects($this->any())->method('isSatisfiedBy')->withAnyParameters()->will($this->returnValue(true));
$this->task->addSpecification($mockDueDateSpecification);
parent::setUp();
}
示例10: importPriceFromDate
/**
* {@inheritdoc}
*/
public function importPriceFromDate(\DateTimeInterface $date)
{
$currentDate = new \DateTimeImmutable('yesterday');
$interval = new \DateInterval('P1D');
while ($currentDate >= $date) {
$nextDay = $currentDate->add($interval);
$price = $this->getPriceRepository()->findPriceByDateTime($nextDay);
if (!$price) {
$priceValue = $this->getPriceValueByDate($currentDate);
$this->savePrice($priceValue, $nextDay);
}
$currentDate = $currentDate->sub($interval);
}
}
示例11: getPeriodDays
public static function getPeriodDays(\DateTimeImmutable $dateStart, \DateTimeImmutable $dateEnd, $excludeStartDate = NULL)
{
$days = [];
if ($dateStart->format("Y-m-d") === $dateEnd->format("Y-m-d")) {
$days[] = $dateStart->format("Y-m-d");
} else {
$interval = new \DateInterval('P1D');
$dateRange = new \DatePeriod($dateStart, $interval, $dateEnd->add(new \DateInterval('P1D')), $excludeStartDate);
foreach ($dateRange as $day) {
$days[] = $day->format("Y-m-d");
}
}
return $days;
}
示例12: getExpiration
private function getExpiration(string $duration) : \DateTimeImmutable
{
$expiration = new \DateTimeImmutable();
if (!preg_match('/^((?P<days>\\d+)d)?((?P<hours>\\d+)h)?((?P<minutes>\\d+)m)?((?P<seconds>\\d+)s)?$/', $duration, $matches)) {
return $expiration;
}
$dateInterval = 'P';
$timeDelimiter = 'T';
if (!empty($matches['days'])) {
$dateInterval .= $matches['days'] . 'D';
}
if (!empty($matches['hours'])) {
$dateInterval .= $timeDelimiter . $matches['hours'] . 'H';
$timeDelimiter = '';
}
if (!empty($matches['minutes'])) {
$dateInterval .= $timeDelimiter . $matches['minutes'] . 'M';
$timeDelimiter = '';
}
if (!empty($matches['seconds'])) {
$dateInterval .= $timeDelimiter . $matches['seconds'] . 'S';
}
return $expiration->add(new \DateInterval($dateInterval));
}
示例13: findNearestWorkDate
protected function findNearestWorkDate(\DateTimeImmutable $operatingDate)
{
$result = false;
while (!$result) {
$checkingDate = $operatingDate->add(new \DateInterval("P1D"));
$dateIsWorkDay = $this->checkDateIsWorkDay($checkingDate);
$operatingDate = clone $checkingDate;
if ($dateIsWorkDay) {
$result = true;
}
}
return $checkingDate;
}
示例14: DateTimeImmutable
<?php
$date = new DateTimeImmutable();
$pd = $date->sub(new DateInterval('P2M'));
$nd = $date->add(new DateInterval('P2Y'));
echo $pd->format('Y-m-d') . "\n";
echo $nd->format('Y-m-d') . "\n";
示例15: cmp_by_date
$NEWS = [];
foreach ($newsitems as $newsitem) {
include $newsdir . '/' . $newsitem;
}
function cmp_by_date($a, $b)
{
return $a['date'] < $b['date'];
}
usort($NEWS, "cmp_by_date");
foreach ($NEWS as $i) {
#var_dump($i);
$class = $i['isImportant'] ? 'important' : '';
$now = new DateTimeImmutable('now');
$date = new DateTimeImmutable($i['date']);
$d_start = array_key_exists('dateOn', $i) ? new DateTime($i['dateOn']) : $now;
$d_end = array_key_exists('dateOff', $i) ? new DateTime($i['dateOff']) : $date->add(new DateInterval('P14D'));
#var_dump($date);
#var_dump($d_start);
#var_dump($d_end);
if ($now < $d_start or $now > $d_end) {
continue;
}
echo <<<HTML
<li class="{$class}">
<div class="newsitem">
<strong>{$i['title']}</strong>
<br />
{$i['text']}