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


PHP DateTimeImmutable::add方法代码示例

本文整理汇总了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;
    }
}
开发者ID:AstroPhysicsUZH,项目名称:group_homepage,代码行数:31,代码来源:news.php

示例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"));
 }
开发者ID:prikril,项目名称:pw-online-auction,代码行数:10,代码来源:AuctionTest.php

示例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;
 }
开发者ID:mpyw,项目名称:hardbotter,代码行数:7,代码来源:CollectorTraitTest.php

示例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);
 }
开发者ID:quazardous,项目名称:eclectic-helpers,代码行数:14,代码来源:Time.php

示例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);
 }
开发者ID:wookieb,项目名称:relative-date,代码行数:11,代码来源:AbstractTest.php

示例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);
 }
开发者ID:martyn82,项目名称:apha,代码行数:15,代码来源:SimpleEventSchedulerTest.php

示例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);
 }
开发者ID:HoffmannP,项目名称:Arbeitszeitkonto,代码行数:13,代码来源:Arbeitszeitkonto.class.php

示例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));
 }
开发者ID:comsolit,项目名称:date-time-immutable,代码行数:13,代码来源:DateTimeImmutableTest.php

示例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();
 }
开发者ID:nirolph,项目名称:todo,代码行数:13,代码来源:TaskTest.php

示例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);
     }
 }
开发者ID:KNone,项目名称:grechkatoday,代码行数:17,代码来源:Importer.php

示例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;
 }
开发者ID:jeronimos,项目名称:php-time-manage,代码行数:14,代码来源:Periods.php

示例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));
 }
开发者ID:Room-11,项目名称:Jeeves,代码行数:24,代码来源:Ban.php

示例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;
 }
开发者ID:jeronimos,项目名称:php-time-manage,代码行数:13,代码来源:CalculateOccurrences.php

示例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";
开发者ID:aborruso,项目名称:albo-pop,代码行数:7,代码来源:testcut.php

示例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']}
开发者ID:AstroPhysicsUZH,项目名称:group_homepage,代码行数:30,代码来源:test_news.php


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