public function testGetDuration() { $interval = new DateInterval(new Date(2012, 01, 01), new Date(2012, 01, 01)); $this->assertEquals(new Duration(0, TimeUnit::day()), $interval->getDuration()); $interval = new DateInterval(new Date(2012, 01, 01), new Date(2012, 01, 03)); $this->assertEquals(new Duration(2, TimeUnit::day()), $interval->getDuration()); }
public function testUntilDuring() { $point = new TimePoint(2012, 1, 1, 9, 30); $expectedInterval = new TimeInterval(new TimePoint(2012, 1, 1, 9, 30), new TimePoint(2012, 1, 1, 13, 30)); $this->assertTrue($expectedInterval->isEquals($point->during(new Duration(4, TimeUnit::hour())))); $this->assertTrue($expectedInterval->isEquals($point->until(new TimePoint(2012, 1, 1, 13, 30)))); }
public function testHowToAddRemoveDurationFromIt() { $startTimePoint = new TimePoint(2013, 3, 12, 18, 27); $stopTimePoint = new TimePoint(2013, 3, 14, 18, 27); $duration = new Duration(2, TimeUnit::day()); $result = $startTimePoint->plus($duration); $this->assertEquals($result, $stopTimePoint); }
public function testGroup() { $cal = new Calendar('my calendar'); $cal->add(new Event(TimeIntervalFactory::create('2012-01-01 01:00', '2012-01-01 10:00'))); $cal->add(new Event(TimeIntervalFactory::create('2012-01-03 01:01', '2012-01-03 10:00'))); $cal->group(new Duration(1, TimeUnit::day())); $this->assertCount(3, $cal->getCalendars()); }
public function testHowToGetNumberOfDaysBetween2Dates() { $interval = new DateInterval(new Date(2013, 1, 1), new Date(2013, 1, 20)); $duration = $interval->getDuration(); $this->assertEquals(new Duration(19, TimeUnit::day()), $duration); }
public function testLength() { $interval = new TimeInterval(new TimePoint(2012, 1, 1, 9, 30), new TimePoint(2012, 1, 1, 13, 30)); $expectedDuration = new Duration(4, TimeUnit::hour()); $this->assertEquals($expectedDuration, $interval->getLength()); }
public static function day($value) { return new Duration($value, TimeUnit::day()); }
/** * Use cases : * - Calculate difference between 2 days * - Fetch the position of a date from another * - How many days form my birthday * * Returns a Duration Class @see Ddd\Time\Model\Duration. * */ public function testHowToKnowDiffBetweenItAndAnOtherDate() { $jan1 = new Date(2013, 1, 1); $jan10 = new Date(2013, 1, 10); $diff = $jan1->diff($jan10); $this->assertInstanceOf('Ddd\\Time\\Model\\Duration', $diff); $this->assertEquals($diff, new Duration(9, TimeUnit::day())); }