本文整理汇总了PHP中DateTimeImmutable::diff方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeImmutable::diff方法的具体用法?PHP DateTimeImmutable::diff怎么用?PHP DateTimeImmutable::diff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeImmutable
的用法示例。
在下文中一共展示了DateTimeImmutable::diff方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
public function render($dados)
{
$this->Cell(array_sum($this->columnsWidth), 9, utf8_decode('Total de Registros: ' . count($dados)), 1, 0, 'L', 0);
$this->Ln();
$this->tableHeader();
$this->SetFont('Arial', '', 8);
$this->SetFillColor(224, 235, 255);
$x = 0;
foreach ($dados as $tratamento) {
$inclusao = \DateTime::createFromFormat('Y-m-d', $tratamento->tto_data_inicio);
$hoje = new \DateTimeImmutable();
$nascimento = \DateTime::createFromFormat('Y-m-d', $tratamento->pac_nascimento);
$idade = $hoje->diff($nascimento);
$duracao = $hoje->diff($inclusao);
$arTr = explode(' ', $tratamento->prof_nome);
$fill = $x % 2 === 0;
$this->SetLineWidth('.3');
$this->Cell($this->columnsWidth[0], $this->lineHeight, $x + 1, 1, 0, 'L', $fill);
$this->Cell($this->columnsWidth[1], $this->lineHeight, utf8_decode($tratamento->pac_nome), 1, 0, 'L', $fill);
$this->Cell($this->columnsWidth[2], $this->lineHeight, utf8_decode($tratamento->pac_cns), 1, 0, 'L', $fill);
$this->Cell($this->columnsWidth[3], $this->lineHeight, $tratamento->tto_diagnostico, 1, 0, 'L', $fill);
$this->Cell($this->columnsWidth[4], $this->lineHeight, $tratamento->pac_sexo, 1, 0, 'L', $fill);
$this->Cell($this->columnsWidth[5], $this->lineHeight, $inclusao->format('d-m-Y'), 1, 0, 'L', $fill);
$this->Cell($this->columnsWidth[6], $this->lineHeight, utf8_decode($tratamento->tto_turno), 1, 0, 'L', $fill);
$this->Cell($this->columnsWidth[7], $this->lineHeight, utf8_decode($arTr[0]), 1, 0, 'L', $fill);
$this->Cell($this->columnsWidth[8], $this->lineHeight, utf8_decode($duracao->format('%a dias')), 1, 0, 'L', $fill);
$this->Cell($this->columnsWidth[9], $this->lineHeight, utf8_decode($idade->format('%Y Anos')), 1, 0, 'L', $fill);
$this->Cell($this->columnsWidth[10], $this->lineHeight, utf8_decode(html_entity_decode($tratamento->ubs_nome)), 1, 0, 'L', $fill);
$this->Ln();
$x++;
}
$this->Cell(array_sum($this->columnsWidth), 0, '', 'T');
}
示例2: ago
/**
* @param boolean $ago Do we add 'ago' to interval.
*
* @return string
* @since 2015-08-07
*/
public function ago($ago = true)
{
$l = $this->lang;
$s = $l->seperator();
$to = $this->to;
if ($to === null) {
$to = new \DateTimeImmutable('now', $this->from->getTimezone());
}
$int = $this->from->diff($to);
$ret = $l->format($int, $ago);
return $ret;
}
示例3: testFromDateInterval
/**
* @dataProvider dateIntervalStrings
* @param string $intervalSpec
* @param array $parts
*/
public function testFromDateInterval($intervalSpec, array $parts)
{
$interval = DateInterval::fromDateInterval(new \DateInterval($intervalSpec));
self::assertInstanceOf(DateInterval::class, $interval);
self::assertEquals($parts[0], $interval->y);
self::assertEquals($parts[1], $interval->m);
self::assertEquals($parts[2], $interval->d);
self::assertEquals($parts[3], $interval->h);
self::assertEquals($parts[4], $interval->i);
self::assertEquals($parts[5], $interval->s);
// Test for extreme case when diff between winter and summer time returns interval with negative hour
$phpDate1 = new \DateTimeImmutable('2016-11-22 11:00:00');
$phpDate2 = new \DateTimeImmutable('2016-08-22 12:00:00');
$phpInterval = $phpDate1->diff($phpDate2);
$interval = DateInterval::fromDateInterval($phpInterval);
self::assertEquals('P3MT-1H', (string) $interval);
}
示例4: diff
/**
* @param \DateTimeInterface $dateTime
* @param bool $absolute
* @return DateInterval
*/
public function diff($dateTime, $absolute = false)
{
return DateInterval::fromDateInterval(parent::diff($dateTime, $absolute));
}
示例5: isExpired
/**
* Checks if the token is expired comparing
* with the given lifetime.
*
* @param int $lifetime The lifetime of the token
*
* @return bool
*/
public function isExpired($lifetime)
{
$interval = $this->createdOn->diff(new \DateTimeImmutable());
return $interval->s >= (int) $lifetime;
}
示例6: generatePriceReturning
function generatePriceReturning()
{
$isValidInput = true;
$_SESSION['typeReturning'] = true;
$dbhandle = mysql_connect("localhost", "root", "") or die("Could not connect to database");
$selected = mysql_select_db("airone", $dbhandle);
$query1 = 'SELECT DistanceIndex FROM cities WHERE CityName = "' . $_GET['from'] . '"';
$distanceIndex1 = mysql_query($query1) or die(mysql_error() . "[" . $query1 . "]");
$distanceIndex1fetched = mysql_fetch_array($distanceIndex1);
$distance1 = intval($distanceIndex1fetched['DistanceIndex']);
$query2 = 'SELECT DistanceIndex FROM cities WHERE CityName = "' . $_GET['To'] . '"';
$distanceIndex2 = mysql_query($query2) or die(mysql_error() . "[" . $query2 . "]");
$distanceIndex2fetched = mysql_fetch_array($distanceIndex2);
$distance2 = intval($distanceIndex2fetched['DistanceIndex']);
mysql_close();
if ($distance2 > $distance1) {
$priceIndex = $distance2 - $distance1;
} else {
$priceIndex = $distance1 - $distance2;
}
switch ($priceIndex) {
case 0:
$defaultPrice = 60;
break;
case 1:
$defaultPrice = 70;
break;
case 2:
$defaultPrice = 80;
break;
case 3:
$defaultPrice = 90;
break;
case 4:
$defaultPrice = 100;
break;
case 5:
$defaultPrice = 120;
break;
case 6:
$defaultPrice = 140;
break;
case 7:
$defaultPrice = 170;
break;
case 8:
$defaultPrice = 200;
break;
}
switch ($_GET['flightClass']) {
case 'Business':
$defaultPrice *= 1.4;
break;
}
$returningDateInput = str_replace('/', '-', $_GET['returning']);
$departingDateInput = str_replace('/', '-', $_GET['departing']);
$returningDate = new DateTimeImmutable($returningDateInput);
$minus3days = $returningDate->modify('-3 days');
$minus2days = $returningDate->modify('-2 days');
$minus1day = $returningDate->modify('-1 day');
$plus1day = $returningDate->modify('+1 day');
$plus2days = $returningDate->modify('+2 days');
$plus3days = $returningDate->modify('+3 days');
$todayInit = date('Y-m-d');
$today = new DateTime($todayInit);
$timeDifferenceReturning = $returningDate->diff($today)->format("%a");
$timeDifferenceReturning = intval($timeDifferenceReturning);
if ($timeDifferenceReturning <= 30) {
$defaultPrice *= 1.1;
} else {
if ($timeDifferenceReturning > 30 && $timeDifferenceReturning <= 60) {
$defaultPrice -= 1;
} else {
if ($timeDifferenceReturning > 60 && $timeDifferenceReturning <= 90) {
$defaultPrice *= 0.9;
} else {
$defaultPrice *= 0.75;
}
}
}
$defaultPrice = floor($defaultPrice);
switch ($timeDifferenceReturning) {
case $timeDifferenceReturning < 0:
echo "Returning date cannot be earlier than departing date!";
$isValidInput = false;
break;
case 0:
$minus3daysPrice = "";
$minus2daysPrice = "";
$minus1dayPrice = "";
$plus1dayPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
value="' . $defaultPrice . '_' . $plus1day->format('d M Y') . '">' . $defaultPrice . "€";
$plus2daysPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
value="' . $defaultPrice . '_' . $plus2days->format('d M Y') . '">' . $defaultPrice . "€";
$plus3daysPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)"
value="' . floor($defaultPrice * 0.95) . '_' . $plus3days->format('d M Y') . '">' . floor($defaultPrice * 0.95) . "€";
$defaultPrice = "";
break;
case 1:
$minus3daysPrice = "";
//.........这里部分代码省略.........
示例7: dateIntervalDiff
/**
* Create a PeriodLib object from a Year and a Quarter.
*
* @param PeriodLib $period
*
* @return \DateInterval
*/
public function dateIntervalDiff(PeriodLib $period)
{
return $this->endDate->diff($this->withDuration($period->getTimestampInterval())->endDate);
}