Esempio n. 1
0
 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());
 }
Esempio n. 2
0
 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))));
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
 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());
 }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
 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());
 }
Esempio n. 7
0
 public static function day($value)
 {
     return new Duration($value, TimeUnit::day());
 }
Esempio n. 8
0
 /**
  * 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()));
 }