public function testApplyWeekContext() { $now = new DateTime('2016-01-13'); // Wed $date = new DateTime('2016-03-12'); $this->assertEquals(new DateTime('2016-01-18'), Dates::applyWeekContext(clone $date, 0, $now)); $this->assertEquals(new DateTime('2016-01-19'), Dates::applyWeekContext(clone $date, 1, $now)); $this->assertEquals(new DateTime('2016-01-13'), Dates::applyWeekContext(clone $date, 2, $now)); $this->assertEquals(new DateTime('2016-01-14'), Dates::applyWeekContext(clone $date, 3, $now)); $this->assertEquals(new DateTime('2016-01-15'), Dates::applyWeekContext(clone $date, 4, $now)); $this->assertEquals(new DateTime('2016-01-16'), Dates::applyWeekContext(clone $date, 5, $now)); $this->assertEquals(new DateTime('2016-01-17'), Dates::applyWeekContext(clone $date, 6, $now)); }
/** * Returns a copy of this Period in another time context meaning the dates of the start and end time may be * in another week depending on $date * * @param DateTime $date The date context for the new Period * * @return Period The new Period in another date context */ public function getCopyInDateContext(DateTime $date) { $period = clone $this; $period->timeStart = Dates::applyWeekContext(clone $this->timeStart, $this->weekday, $date); $period->timeEnd = Dates::applyWeekContext(clone $this->timeEnd, $this->weekday, $date); if ($period->spansTwoDays) { $period->timeEnd->add(new DateInterval('P1D')); } return $period; }
public function testCreateDummy() { $p = Period::createDummy(); $expectedStart = Dates::applyWeekContext(new DateTime('now'), 0); $expectedStart->setTime(0, 0, 0); $this->assertEquals(0, $p->getWeekday()); $this->assertEquals($expectedStart, $p->getTimeStart()); $this->assertEquals($expectedStart->add(new DateInterval('P1D')), $p->getTimeEnd()); $this->assertTrue($p->isDummy()); }
/** * Returns first active irregular opening on a specific weekday * * @param int $weekday weekday number, 0-6 * @param DateTime $now custom time * * @return IrregularOpening The first active irregular opening fpr the current weekday */ public function getActiveIrregularOpeningOnWeekday($weekday, DateTime $now = null) { $date = Dates::applyWeekContext(new DateTime('now'), $weekday, $now); return $this->getActiveIrregularOpening($date); }