本文整理汇总了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;
}
示例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);
}
示例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));
}
示例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;
}
示例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);
}
示例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);
}
示例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";
示例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);
}