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


PHP DateTimeImmutable::sub方法代码示例

本文整理汇总了PHP中DateTimeImmutable::sub方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeImmutable::sub方法的具体用法?PHP DateTimeImmutable::sub怎么用?PHP DateTimeImmutable::sub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DateTimeImmutable的用法示例。


在下文中一共展示了DateTimeImmutable::sub方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getPreviousPeriod

 public static function getPreviousPeriod(PeriodData $period)
 {
     $previousPeriod = new \StdClass();
     $periodFrom = new \DateTimeImmutable($period->getFrom());
     $previousPeriod->from = $periodFrom->sub(new \DateInterval("P1M"))->format("Y-m-d");
     $previousPeriod->to = $periodFrom->sub(new \DateInterval("P1D"))->format("Y-m-d");
     return $previousPeriod;
 }
开发者ID:jeronimos,项目名称:php-time-manage,代码行数:8,代码来源:Periods.php

示例2: 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

示例3: testSub

 public function testSub()
 {
     $time = '2000-01-02T03:14:25';
     $immutable = new DateTimeImmutable($time);
     $control = new DateTimeImmutable($time);
     $mutable = new DateTime($time);
     $interval = new DateInterval('P1D');
     $new = $immutable->sub($interval);
     $mutable->sub($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

示例4: findPricesForInterval

 /**
  * @param \DateInterval $interval
  * @return Price[]
  */
 private function findPricesForInterval(\DateInterval $interval)
 {
     $today = new \DateTimeImmutable('today');
     $forDate = $today->sub($interval);
     $sql = sprintf('SELECT * FROM %s p WHERE p.date_time > ? AND p.date_time <= ? ORDER BY p.date_time ASC ', $this->getTableName());
     /** @var Statement $statement */
     $statement = $this->connection->prepare($sql);
     $statement->bindValue(1, $forDate, Type::DATETIME);
     $statement->bindValue(2, $today, Type::DATETIME);
     $statement->execute();
     $results = $statement->fetchAll();
     if (empty($results)) {
         return null;
     }
     $objects = [];
     foreach ($results as $result) {
         $objects[] = $this->createEntity($result);
     }
     return $objects;
 }
开发者ID:KNone,项目名称:grechkatoday,代码行数:24,代码来源:PriceRepository.php

示例5: testWillNotAddBidOnEndedAuction

 public function testWillNotAddBidOnEndedAuction()
 {
     $bidPrice = new Money(2, new Currency('EUR'));
     $now = new DateTimeImmutable();
     $startTime = $now->sub(new DateInterval("PT4H"));
     $endTime = $now->sub(new DateInterval("PT2H"));
     $auction = $this->createAuction($this->title, $this->description, $this->startPrice, $this->owner, $startTime, $endTime);
     $this->setExpectedException(LogicException::class, "You may not bid on a ended auction");
     $auction->addBid($bidPrice, $this->bidder);
 }
开发者ID:prikril,项目名称:pw-online-auction,代码行数:10,代码来源:AuctionTest.php

示例6: scheduleAtWithPassedTimeSchedulesEventImmediately

 /**
  * @test
  */
 public function scheduleAtWithPassedTimeSchedulesEventImmediately()
 {
     $eventBus = $this->createEventBus();
     $event = $this->getMockBuilder(Event::class)->getMock();
     $eventBus->expects(self::once())->method('publish')->with($event);
     // schedule for execution 1 day ago
     $now = new \DateTimeImmutable();
     $time = $now->sub(new \DateInterval('P1D'));
     $scheduler = new SimpleEventScheduler($eventBus);
     $scheduler->scheduleAt($time, $event);
     $this->wait(1);
 }
开发者ID:martyn82,项目名称:apha,代码行数:15,代码来源:SimpleEventSchedulerTest.php

示例7: 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

示例8: createByDate

 /**
  * Factory method to construct an instance which retrieves entries from
  * a default period of time ago.
  */
 public static function createByDate()
 {
     $date = new DateTimeImmutable();
     $from_date = $date->sub(new DateInterval('P' . NMONTHS . 'M'));
     $h = curl_init(ALBO_CT_URL);
     if (!$h) {
         throw new Exception("Unable to initialize cURL session");
     }
     curl_setopt($h, CURLOPT_POST, TRUE);
     curl_setopt($h, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($h, CURLOPT_POSTFIELDS, array("__Click" => 0, "%%Surrogate_gg1" => 1, "gg1" => $from_date->format('d'), "%%Surrogate_mm1" => 1, "mm1" => $from_date->format('m'), "%%Surrogate_aa1" => 1, "aa1" => $from_date->format('Y')));
     //curl_setopt($h, CURLOPT_HTTPHEADER, array("Accept-Charset: utf-8"));
     $page = curl_exec($h);
     if ($page == FALSE) {
         throw new Exception("Unable to execute POST request: " . curl_error($h));
     }
     curl_close($h);
     return new AlboComuneCTParser($page);
 }
开发者ID:aborruso,项目名称:albo-pop,代码行数:23,代码来源:AlboComuneCTParser.php


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