Ejemplo 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());
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
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());
 }
Ejemplo n.º 4
0
 public function testMinus()
 {
     $point = new TimePoint(2012, 1, 1, 9, 30);
     $this->assertEquals(new TimePoint(2009, 1, 1, 9, 30), $point->minus(new Duration(3, TimeUnit::year())));
     $this->assertEquals(new TimePoint(2011, 9, 1, 9, 30), $point->minus(new Duration(4, TimeUnit::month())));
     $this->assertEquals(new TimePoint(2011, 12, 30, 9, 30), $point->minus(new Duration(2, TimeUnit::day())));
     $this->assertEquals(new TimePoint(2012, 1, 1, 6, 30), $point->minus(new Duration(3, TimeUnit::hour())));
     $this->assertEquals(new TimePoint(2012, 1, 1, 9, 0), $point->minus(new Duration(30, TimeUnit::minute())));
 }
Ejemplo 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);
 }
Ejemplo n.º 6
0
 public static function day($value)
 {
     return new Duration($value, TimeUnit::day());
 }
Ejemplo n.º 7
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()));
 }