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


PHP DateTimeImmutable::diff方法代码示例

本文整理汇总了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');
 }
开发者ID:evandrolacerda,项目名称:caps_laravel,代码行数:33,代码来源:RelatorioTratamento.php

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

示例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);
 }
开发者ID:pauci,项目名称:datetime,代码行数:22,代码来源:DateIntervalTest.php

示例4: diff

 /**
  * @param \DateTimeInterface $dateTime
  * @param bool $absolute
  * @return DateInterval
  */
 public function diff($dateTime, $absolute = false)
 {
     return DateInterval::fromDateInterval(parent::diff($dateTime, $absolute));
 }
开发者ID:pauci,项目名称:datetime,代码行数:9,代码来源:DateTime.php

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

示例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 = "";
//.........这里部分代码省略.........
开发者ID:stoyanmkd,项目名称:airOne,代码行数:101,代码来源:booking.php

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


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