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


PHP DateTimeImmutable::modify方法代码示例

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


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

示例1: testFormattedOutput

 public function testFormattedOutput()
 {
     $today = new \DateTimeImmutable();
     // Show 1 has an upcoming episode.
     for ($i = 1; $i <= 3; $i++) {
         $serie = $this->getMockBuilder('Moinax\\TvDb\\Serie')->disableOriginalConstructor()->getMock();
         $serie->id = 1;
         $serie->name = "Serie {$i}";
         $series[] = $serie;
     }
     $show_1 = [$this->getEpisode('S1E1', $today->modify("-7 days")), $this->getEpisode('S1E2', $today->modify('+7 days'))];
     // Show 2 only has episodes in the past.
     $show_2 = [$this->getEpisode('S2E1', $today->modify("-21 days")), $this->getEpisode('S2E2', $today->modify('-14 days'))];
     // Show 3 has an episode coming out today.
     $show_3 = [$this->getEpisode('S3E1', $today->modify("-7 days")), $this->getEpisode('S3E2', $today)];
     $episodes = [['episodes' => $show_1], ['episodes' => $show_2], ['episodes' => $show_3]];
     $shows = ['show1' => 'imdb1', 'show2' => 'imdb2', 'show3' => 'imdb3'];
     $application = new Application();
     $application->add($this->getCommand($series, $episodes, $shows));
     $command = $application->find('status');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName()], ['decorated' => TRUE]);
     //    $this->assertEquals('', $commandTester->getDisplay());
     //    $this->assertTrue(stripos($commandTester->getDisplay(), 'red') !== FALSE);
     $a = $commandTester->getDisplay();
     $b = $commandTester->getOutput();
 }
开发者ID:benjy,项目名称:tv,代码行数:27,代码来源:StatusCommandTest.php

示例2: testBinEmptyDeletionCriteria

 public function testBinEmptyDeletionCriteria()
 {
     $todayOb = new \DateTimeImmutable("today");
     $today = $todayOb->format("c");
     $yesterday = $todayOb->modify("-1 days")->format("c");
     $dayBefore = $todayOb->modify("-2 days")->format("c");
     $tomorrow = $todayOb->modify("+1 days")->format("c");
     $r = new Recycle($this->storageDir);
     $inputItems = [$tomorrow, $today, $yesterday, $dayBefore, "somerandomfile"];
     $toDelete = $this->invokeMethod($r, "generateDeletionList", ["keepDays" => 0, "items" => $inputItems]);
     static::assertEquals([$tomorrow, $today, $yesterday, $dayBefore], $toDelete);
     $toDelete = $this->invokeMethod($r, "generateDeletionList", ["keepDays" => 1, "items" => $inputItems]);
     static::assertEquals([$tomorrow, $yesterday, $dayBefore], $toDelete);
     $toDelete = $this->invokeMethod($r, "generateDeletionList", ["keepDays" => 2, "items" => $inputItems]);
     static::assertEquals([$tomorrow, $dayBefore], $toDelete);
     $toDelete = $this->invokeMethod($r, "generateDeletionList", ["keepDays" => 3, "items" => $inputItems]);
     static::assertEquals([$tomorrow], $toDelete);
 }
开发者ID:patternseek,项目名称:recycle,代码行数:18,代码来源:RecycleTest.php

示例3: testModify

 public function testModify()
 {
     $time = '2000-01-02T03:14:25';
     $immutable = new DateTimeImmutable($time);
     $control = new DateTimeImmutable($time);
     $mutable = new DateTime($time);
     $new = $immutable->modify('+1 day');
     $mutable->modify('+1 day');
     $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,代码行数:12,代码来源:DateTimeImmutableTest.php

示例4: it_publishes_messages

 /**
  * @test
  */
 public function it_publishes_messages()
 {
     $now = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));
     $producer = $this->prophesize(Producer::class);
     $producer->publish(['message_name' => 'test-message', 'uuid' => 'ccefedef-85e1-4fd0-b247-ed13d378b050', 'version' => 1, 'payload' => [], 'metadata' => ['execute_at' => $now->modify('+5 seconds')->format('Y-m-d\\TH:i:s.u')], 'created_at' => $now->format('Y-m-d\\TH:i:s.u')], 'test-message', Constants::AMQP_NOPARAM, ['app_id' => 'test_app', 'timestamp' => $now->getTimestamp(), 'type' => 'test-message', 'headers' => ['x-delay' => 5000]])->shouldBeCalled();
     $message = $this->prophesize(DelayedMessage::class);
     $message->delay()->willReturn(5000)->shouldBeCalled();
     $message->createdAt()->willReturn($now)->shouldBeCalled();
     $message->messageName()->willReturn('test-message')->shouldBeCalled();
     $messageConverter = $this->prophesize(MessageConverter::class);
     $messageConverter->convertToArray($message)->willReturn(['message_name' => 'test-message', 'uuid' => 'ccefedef-85e1-4fd0-b247-ed13d378b050', 'version' => 1, 'payload' => [], 'metadata' => ['execute_at' => $now->modify('+5 seconds')->format('Y-m-d\\TH:i:s.u')], 'created_at' => $now])->shouldBeCalled();
     $messageProducer = new AmqpDelayedMessageProducer($producer->reveal(), $messageConverter->reveal(), 'test_app');
     $messageProducer($message->reveal());
 }
开发者ID:prooph,项目名称:humus-amqp-producer,代码行数:17,代码来源:AmqpDelayedMessageProducerTest.php

示例5: array

<?php

include "mysql.php";
$deviceLookup = array(0, 3, 4, 6, 7, 8, 9, 10, 11, 13);
$Lehrer = $_GET['lehrer'];
$when = explode("_", $_GET['time']);
$woche = $_GET['woche'];
$date = new DateTimeImmutable("last monday +{$woche} week");
$q = mysqli_query($conn, "DELETE FROM res WHERE Stunde = {$when['0']} AND Date = '" . $date->modify('+' . $when[1] . ' days')->format("Y-m-d") . "' AND Lehrer = '{$Lehrer}'");
开发者ID:Alphazork,项目名称:res,代码行数:9,代码来源:remove.php

示例6: DateTimeImmutable

<?php

$formatString = 'l, F j, Y';
$date1 = new DateTimeImmutable('12/25/2015');
$date2 = $date1->modify('+1 month');
echo 'Date 1: ' . $date1->format($formatString) . '<br>';
echo 'Date 2: ' . $date2->format($formatString) . '<br>';
开发者ID:hassanazimi,项目名称:PHP_DateTime,代码行数:7,代码来源:immutable.php

示例7: modify

 /**
  * @param string $string
  * @return static
  */
 public function modify($string)
 {
     return parent::modify($string);
 }
开发者ID:wscore,项目名称:site,代码行数:8,代码来源:DateTime.php

示例8: array

//0...2 => Dell Laptops
//3...5 => HP Laptops
//6...7 => Beamer Medienwagen
//8...9 => Fernseher Medienwagen
//10...11 => Beamer
//12...15 => DVD
//16...17 => VHS
$deviceLookup = array(0, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 15, 16, 17);
include "mysql.php";
$wk = array(0 => "8:10 - 9:00", 1 => "9:05 - 9:55", 2 => "10:05 - 10:55", 3 => "11:05 - 11:55", 4 => "12:05 - 12:55", 5 => "13:00 - 13:50", 6 => "13:50 - 14:40", 7 => "14:40 - 15:30", 8 => "15:30 - 16:20", 9 => "16:20 - 17:10", 10 => "17:10 - 18:00", 11 => "18:00 - 18:50");
$deviceName = array(0 => "Laptop(DELL) 1", 1 => "Laptop(DELL) 2", 2 => "Laptop(DELL) 3", 3 => "Laptop(HP) 1", 4 => "Laptop(HP) 2", 5 => "Laptop(HP) 3", 6 => "Medienwagen(Beamer) 1", 7 => "Medienwagen(Beamer) 2", 8 => "Medienwagen(Fernseher) 1", 9 => "Medienwagen(Fernseher) 2", 10 => "Beamer 1", 11 => "Beamer 2", 12 => "DVD 1", 13 => "DVD 2", 14 => "DVD 3", 15 => "DVD 4", 16 => "VHS 2", 17 => "VHS 3");
echo "<table class='table table-striped'>";
$week = $_GET["week"];
$device = $_GET["device"];
$date = new DateTimeImmutable("last monday +{$week} week");
echo "<tr>\n                <th>Uhrzeit</th>\n                <th>Montag " . $date->format("d.m") . "</th>\n                <th>Dienstag " . $date->modify("+1 days")->format("d.m") . "</th>\n                <th>Mittwoch " . $date->modify("+2 days")->format("d.m") . "</th>\n                <th>Donnerstag " . $date->modify("+3 days")->format("d.m") . "</th>\n                <th>Freitag " . $date->modify("+4 days")->format("d.m") . "</th>\n            </tr>";
$data = array();
$q = mysqli_query($conn, "SELECT * FROM res WHERE Date BETWEEN '" . $date->format("Y-m-d") . "' AND '" . $date->modify("+4 days")->format("Y-m-d") . "';");
while ($d = mysqli_fetch_assoc($q)) {
    if (!array_key_exists($d["Date"], $data)) {
        $data[$d["Date"]] = array();
    }
    if (!array_key_exists($d["Stunde"], $data[$d["Date"]])) {
        $data[$d["Date"]][$d["Stunde"]] = array();
    }
    array_push($data[$d["Date"]][$d["Stunde"]], $d["DeviceID"]);
}
for ($i = 0; $i < 12; $i++) {
    for ($d = 0; $d < 5; $d++) {
        $stunde = $i;
        echo "<th>" . $wk[$i] . "</th>";
开发者ID:Alphazork,项目名称:res,代码行数:31,代码来源:makeTable.php

示例9: checkDateIsNotNormalLengthDay

 protected function checkDateIsNotNormalLengthDay(\DateTimeImmutable $operatingDate)
 {
     $checkState = $this->model->checkDateIsNotNormalLengthDay($operatingDate->format("Y-m-d"));
     if (ToBoolean::dataToBool($checkState)) {
         if (!$checkState instanceof \StdClass) {
             throw new OccurrencesException("Model didn't return object for not normal length day.");
         }
         $correctedWorkDayStart = new \DateTimeImmutable($checkState->date_start);
         $correctedWorkDayFinish = $correctedWorkDayStart->modify($checkState->date_finish);
         $this->workTime->setWorkDayStart($correctedWorkDayStart->format("H:i"));
         $this->workTime->setWorkDayFinish($correctedWorkDayFinish->format("H:i"));
     }
     return NULL;
 }
开发者ID:jeronimos,项目名称:php-time-manage,代码行数:14,代码来源:CalculateOccurrences.php

示例10: createFullDateResult

 protected function createFullDateResult(\DateTimeImmutable $currentDate)
 {
     return DateDiffResult::createFullDate(new DateDiffRequest($currentDate, $currentDate->modify('tomorrow')));
 }
开发者ID:wookieb,项目名称:relative-date,代码行数:4,代码来源:AbstractFormattersTest.php

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

示例12: DateTimeImmutable

<?php

$launch = new DateTimeImmutable('0717 2 March 2004 UTC');
// using DateTime::add() with DateInterval
$duration = new DateInterval('P10Y8M10DT8H46M');
$landing = $launch->add($duration);
// using a relative date string with DateTime::modify()
$date_string = '10 years 8 months 10 days 8 hours 46 minutes';
$landing2 = $launch->modify($date_string);
echo $landing->format('l, F j, Y H:i e') . '<br>';
echo $landing2->format('l, F j, Y H:i e');
开发者ID:hassanazimi,项目名称:PHP_DateTime,代码行数:11,代码来源:rosetta.php

示例13: DateTimeImmutable

<?php

$d1 = new DateTimeImmutable('03/08/2015 1:59am GMT-05:00');
echo $d1->format(DateTime::ISO8601) . "\n";
$d2 = $d1->modify('+0 hours');
echo $d2->format(DateTime::ISO8601) . "\n";
echo "--\n";
$d1 = new DateTime('03/08/2015 1:59am GMT-05:00');
echo $d1->format(DateTime::ISO8601) . "\n";
$d2 = clone $d1;
echo $d2->format(DateTime::ISO8601) . "\n";
开发者ID:badlamer,项目名称:hhvm,代码行数:11,代码来源:datetime_clone.php

示例14: array

<?php

session_start();
//0...3 => Laptops
//4...6 => Beamer
//7...8 => DVD
//9...10 => VHS
//11...13 => Medienwägen
include "mysql.php";
$deviceLookup = array(0, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 15, 16, 17);
$Lehrer = $_SESSION["user"];
$when = explode("_", $_GET['time']);
$woche = $_GET['woche'];
$device = $_GET['device'];
$date = new DateTimeImmutable("last monday +{$woche} week");
$test = array();
for ($i = $deviceLookup[$device * 2]; $i <= $deviceLookup[$device * 2 + 1]; $i++) {
    $q = mysqli_query($conn, "SELECT DeviceID FROM res WHERE DeviceID = {$i} AND Stunde = {$when['0']} AND Date = '" . $date->modify('+' . $when[1] . ' days')->format("Y-m-d") . "' ");
    if (mysqli_num_rows($q) == 0) {
        $a1 = $deviceLookup[$device * 2];
        $a2 = $deviceLookup[$device * 2 + 1];
        $test = mysqli_query($conn, "SELECT * FROM res WHERE DeviceID BETWEEN {$a1} AND {$a2} AND Stunde = {$when['0']} AND Date = '" . $date->modify('+' . $when[1] . ' days')->format("Y-m-d") . "' AND Lehrer = '{$Lehrer}'");
        if (mysqli_num_rows($test) == 0) {
            $q = mysqli_query($conn, "INSERT INTO res (Date,Stunde,Lehrer,DeviceID) values ('" . $date->modify('+' . $when[1] . ' days')->format("Y-m-d") . "',{$when['0']},'{$Lehrer}',{$i});");
            break;
        }
    }
}
开发者ID:Alphazork,项目名称:res,代码行数:28,代码来源:insert.php


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