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(); }
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); }
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)); }
/** * @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()); }
<?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}'");
<?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>';
/** * @param string $string * @return static */ public function modify($string) { return parent::modify($string); }
//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>";
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; }
protected function createFullDateResult(\DateTimeImmutable $currentDate) { return DateDiffResult::createFullDate(new DateDiffRequest($currentDate, $currentDate->modify('tomorrow'))); }
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 = ""; $minus2daysPrice = ""; $minus1dayPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)" value="' . floor($defaultPrice * 1.02) . '_' . $minus1day->format('d M Y') . '">' . floor($defaultPrice * 1.02) . "€"; $day0Price = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)" value="' . $defaultPrice . '_' . $returningDate->format('d M Y') . '">' . $defaultPrice . "€"; $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) . "€"; break; case 2: $minus3daysPrice = ""; $minus2daysPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)" value="' . floor($defaultPrice * 1.02) . '_' . $minus2days->format('d M Y') . '">' . floor($defaultPrice * 1.02) . "€"; $minus1dayPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)" value="' . floor($defaultPrice * 1.02) . '_' . $minus1day->format('d M Y') . '">' . floor($defaultPrice * 1.02) . "€"; $day0Price = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)" value="' . $defaultPrice . '_' . $returningDate->format('d M Y') . '">' . $defaultPrice . "€"; $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) . "€"; break; case 3: $minus3daysPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)" value="' . floor($defaultPrice * 1.07) . '_' . $minus3days->format('d M Y') . '">' . floor($defaultPrice * 1.07) . "€"; $minus2daysPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)" value="' . floor($defaultPrice * 1.05) . '_' . $minus2days->format('d M Y') . '">' . floor($defaultPrice * 1.05) . "€"; $minus1dayPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)" value="' . floor($defaultPrice * 1.05) . '_' . $minus1day->format('d M Y') . '">' . floor($defaultPrice * 1.05) . "€"; $day0Price = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)" value="' . $defaultPrice . '_' . $returningDate->format('d M Y') . '">' . $defaultPrice . "€"; $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) . "€"; break; default: $minus3daysPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)" value="' . floor($defaultPrice * 1.05) . '_' . $minus3days->format('d M Y') . '">' . floor($defaultPrice * 1.05) . "€"; $minus2daysPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)" value="' . floor($defaultPrice * 1.02) . '_' . $minus2days->format('d M Y') . '">' . floor($defaultPrice * 1.02) . "€"; $minus1dayPrice = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)" value="' . floor($defaultPrice * 1.02) . '_' . $minus1day->format('d M Y') . '">' . floor($defaultPrice * 1.02) . "€"; $day0Price = '<input type="radio" name="book-returning" onclick="ticketInfoReturning(this.value)" value="' . $defaultPrice . '_' . $returningDate->format('d M Y') . '">' . $defaultPrice . "€"; $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) . "€"; } if ($isValidInput) { echo '<p>' . $_GET['To'] . ' - ' . $_GET['from'] . '</p>'; echo '<table class="flightTimetable"><tr>'; echo "<th>" . $minus3days->format('d M Y') . "</th>"; echo "<th>" . $minus2days->format('d M Y') . "</th>"; echo "<th>" . $minus1day->format('d M Y') . "</th>"; echo "<th>" . $returningDate->format('d M Y') . "</th>"; echo "<th>" . $plus1day->format('d M Y') . "</th>"; echo "<th>" . $plus2days->format('d M Y') . "</th>"; echo "<th>" . $plus3days->format('d M Y') . "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>" . $minus3daysPrice . "</td>"; echo "<td>" . $minus2daysPrice . "</td>"; echo "<td>" . $minus1dayPrice . "</td>"; echo "<td>" . $day0Price . "</td>"; echo "<td>" . $plus1dayPrice . "</td>"; echo "<td>" . $plus2daysPrice . "</td>"; echo "<td>" . $plus3daysPrice . "</td>"; echo "</tr></table>"; } }
<?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');
<?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";
<?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; } } }