function get_news() { global $NEWS; foreach ($NEWS as $i) { #var_dump($i); $class = $i['isImportant'] ? 'important' : ''; $now = new DateTimeImmutable('now'); $date = new DateTimeImmutable($i['date']); $d_start = array_key_exists('dateOn', $i) ? new DateTime($i['dateOn']) : $now; $d_end = array_key_exists('dateOff', $i) ? new DateTime($i['dateOff']) : $date->add(new DateInterval('P14D')); #var_dump($date); #var_dump($d_start); #var_dump($d_end); if ($now < $d_start or $now > $d_end) { continue; } echo <<<HTML <li class="{$class}"> <div class="newsitem"> <strong>{$i['title']}</strong> <br /> {$i['text']} </div> </li> HTML; } }
public function setUp() { $this->title = "myAuction1"; $this->description = "Some rubbish from my garage."; $this->owner = new User("User01", "*****@*****.**"); $this->bidder = new User("Bidder01", "*****@*****.**"); $this->startPrice = new Money(1, new Currency('EUR')); $this->startTime = new DateTimeImmutable(); $this->endTime = $this->startTime->add(new DateInterval("PT2H")); }
protected static function expired($past, $interval) { $past = new \DateTimeImmutable($past, new \DateTimeZone('UTC')); $future = $past->add(new \DateInterval("PT{$interval}S")); $now = new \DateTimeImmutable('2000-10-10 12:30:00', new \DateTimeZone('UTC')); return $future <= $now; }
/** * Return the given ratio of the given interval. * @param \DateInterval $interval * @param number $ratio 0 to 1 * @return string */ public static function ratioIntervalString(\DateInterval $interval, $ratio) { $reference = new \DateTimeImmutable(); $endTime = $reference->add($interval); $seconds = $endTime->getTimestamp() - $reference->getTimestamp(); $seconds = $seconds * $ratio; return sprintf("PT%dS", $seconds); }
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); }
/** * @test */ public function scheduleAtSchedulesEventAtGivenTime() { $eventBus = $this->createEventBus(); $event = $this->getMockBuilder(Event::class)->getMock(); $eventBus->expects(self::once())->method('publish')->with($event); // schedule for execution 1 second from now $now = new \DateTimeImmutable(); $time = $now->add(new \DateInterval('PT1S')); $scheduler = new SimpleEventScheduler($eventBus); $scheduler->scheduleAt($time, $event); $this->wait(2); }
public function periode($beginn, $interval_spec) { $anfang_der_periode = new \DateTimeImmutable($beginn); $periode = new \DatePeriod($anfang_der_periode, new \DateInterval('P1D'), $anfang_der_periode->add(new \DateInterval($interval_spec))); $tage = array(); foreach ($periode as $datum) { $tmp_tag = $this->tag($datum); if ($tmp_tag) { $tage[] = $tmp_tag; } } return new Periode($tage); }
public function testAdd() { $time = '2000-01-02T03:14:25'; $immutable = new DateTimeImmutable($time); $control = new DateTimeImmutable($time); $mutable = new DateTime($time); $interval = new DateInterval('P1D'); $new = $immutable->add($interval); $mutable->add($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)); }
public function setUp() { $this->description = $this->getMockBuilder('\\Domain\\Context\\Task\\ValueObject\\TaskDescription')->setConstructorArgs(array('don\'t forget the milk'))->setMethods(array('value'))->getMock(); $this->description->expects($this->any())->method('value')->will($this->returnValue('don\'t forget the milk')); $today = new \DateTimeImmutable(); $this->dueDate = $today->add(new \DateInterval('P1D')); $this->task = new Task(); $this->task->setDueDate($this->dueDate)->setDescription($this->description); $mockDueDateSpecification = $this->getMockBuilder('\\Domain\\Context\\Task\\Specification\\TaskFutureDueDate')->setMethods(array('isSatisfiedBy'))->getMock(); $mockDueDateSpecification->expects($this->any())->method('isSatisfiedBy')->withAnyParameters()->will($this->returnValue(true)); $this->task->addSpecification($mockDueDateSpecification); parent::setUp(); }
/** * {@inheritdoc} */ public function importPriceFromDate(\DateTimeInterface $date) { $currentDate = new \DateTimeImmutable('yesterday'); $interval = new \DateInterval('P1D'); while ($currentDate >= $date) { $nextDay = $currentDate->add($interval); $price = $this->getPriceRepository()->findPriceByDateTime($nextDay); if (!$price) { $priceValue = $this->getPriceValueByDate($currentDate); $this->savePrice($priceValue, $nextDay); } $currentDate = $currentDate->sub($interval); } }
public static function getPeriodDays(\DateTimeImmutable $dateStart, \DateTimeImmutable $dateEnd, $excludeStartDate = NULL) { $days = []; if ($dateStart->format("Y-m-d") === $dateEnd->format("Y-m-d")) { $days[] = $dateStart->format("Y-m-d"); } else { $interval = new \DateInterval('P1D'); $dateRange = new \DatePeriod($dateStart, $interval, $dateEnd->add(new \DateInterval('P1D')), $excludeStartDate); foreach ($dateRange as $day) { $days[] = $day->format("Y-m-d"); } } return $days; }
private function getExpiration(string $duration) : \DateTimeImmutable { $expiration = new \DateTimeImmutable(); if (!preg_match('/^((?P<days>\\d+)d)?((?P<hours>\\d+)h)?((?P<minutes>\\d+)m)?((?P<seconds>\\d+)s)?$/', $duration, $matches)) { return $expiration; } $dateInterval = 'P'; $timeDelimiter = 'T'; if (!empty($matches['days'])) { $dateInterval .= $matches['days'] . 'D'; } if (!empty($matches['hours'])) { $dateInterval .= $timeDelimiter . $matches['hours'] . 'H'; $timeDelimiter = ''; } if (!empty($matches['minutes'])) { $dateInterval .= $timeDelimiter . $matches['minutes'] . 'M'; $timeDelimiter = ''; } if (!empty($matches['seconds'])) { $dateInterval .= $timeDelimiter . $matches['seconds'] . 'S'; } return $expiration->add(new \DateInterval($dateInterval)); }
protected function findNearestWorkDate(\DateTimeImmutable $operatingDate) { $result = false; while (!$result) { $checkingDate = $operatingDate->add(new \DateInterval("P1D")); $dateIsWorkDay = $this->checkDateIsWorkDay($checkingDate); $operatingDate = clone $checkingDate; if ($dateIsWorkDay) { $result = true; } } return $checkingDate; }
<?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";
$NEWS = []; foreach ($newsitems as $newsitem) { include $newsdir . '/' . $newsitem; } function cmp_by_date($a, $b) { return $a['date'] < $b['date']; } usort($NEWS, "cmp_by_date"); foreach ($NEWS as $i) { #var_dump($i); $class = $i['isImportant'] ? 'important' : ''; $now = new DateTimeImmutable('now'); $date = new DateTimeImmutable($i['date']); $d_start = array_key_exists('dateOn', $i) ? new DateTime($i['dateOn']) : $now; $d_end = array_key_exists('dateOff', $i) ? new DateTime($i['dateOff']) : $date->add(new DateInterval('P14D')); #var_dump($date); #var_dump($d_start); #var_dump($d_end); if ($now < $d_start or $now > $d_end) { continue; } echo <<<HTML <li class="{$class}"> <div class="newsitem"> <strong>{$i['title']}</strong> <br /> {$i['text']}
/** * Create a TimeValue from a \DateInterval object * * @param \DateInterval $interval * @return TimeValue */ public static function createFromDateInterval(\DateInterval $interval) { $utc = new \DateTimeZone('UTC'); $start = new \DateTimeImmutable(null, $utc); $end = $start->add($interval); return new TimeValue($end->getTimestamp() - $start->getTimestamp(), 's'); }
public function getDisponibileDa() { $giorni14 = new \DateInterval('P14D'); $giorni1 = new \DateInterval('P1D'); $prenotazioni = $this->getDettaglioOrdini()->where('datafine>CURDATE()')->orderBy(['datafine' => SORT_ASC])->all(); $simPrenDa = new \DateTimeImmutable(); //inizia la ricerca dalla data odierna foreach ($prenotazioni as $corPren) { $simPrenA = $simPrenDa->add($giorni14); $corPrenDa = new \DateTimeImmutable($corPren->datainizio); if ($corPrenDa > $simPrenA) { return $simPrenDa; } $corPrenA = new \DateTimeImmutable($corPren->datafine); $simPrenDa = $corPrenA->add($giorni1); } return $simPrenDa; }
<?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');