Exemplo n.º 1
0
 public function testCanConvertToDateIntervalWithNegativeValue()
 {
     /*
     $expectedInterval = new \DateInterval('P1Y1M6DT14H12M6S');
     object(DateInterval)[2]
       public 'y' => int 1
       public 'm' => int 1
       public 'd' => int 7
       public 'h' => int 14
       public 'i' => int 12
       public 's' => int 6
       public 'weekday' => int 0
       public 'weekday_behavior' => int 0
       public 'first_last_day_of' => int 0
       public 'invert' => int 1
       public 'days' => int 402
       public 'special_type' => int 0
       public 'special_amount' => int 0
       public 'have_weekday_relative' => int 0
       public 'have_special_relative' => int 0
     */
     $testTimeValue = new TimeValue('-34783926', 's');
     $testInterval = $testTimeValue->toDateInterval();
     $this->assertEquals(1, $testInterval->y, "Test Interval years not correct");
     $this->assertEquals(1, $testInterval->m, "Test Interval months not correct");
     $this->assertEquals(7, $testInterval->d, "Test Interval days not correct");
     $this->assertEquals(14, $testInterval->h, "Test Interval hours not correct");
     $this->assertEquals(12, $testInterval->i, "Test Interval minutes not correct");
     $this->assertEquals(6, $testInterval->s, "Test Interval seconds not correct");
     $this->assertEquals(1, $testInterval->invert, "Test Interval invert not correct");
     $this->assertEquals(402, $testInterval->days, "Test Interval total full days not correct");
 }
Exemplo n.º 2
0
 /**
  * Subtract a TimeValue from $this and return a new object.
  *
  * @param TimeValue $time
  * @return TimeValue
  */
 public function sub(TimeValue $time)
 {
     $totalSeconds = $this->seconds - $time->getSeconds();
     return new TimeValue("{$totalSeconds}", 's');
 }