Exemple #1
0
 public function testExactLimits()
 {
     $Time = new Duration();
     $this->assertEquals('1d 00:00:00', $Time->fromString('24:00:00')->string());
     $this->assertEquals('10:00:00', $Time->fromString('10:00:00')->string());
     $this->assertEquals('1:00:00', $Time->fromString(' 1:00:00')->string());
     $this->assertEquals('10:00', $Time->fromString('   10:00')->string());
     $this->assertEquals('1:00', $Time->fromString('    1:00')->string());
 }
 /**
  * Test instance creation from a string.
  * 
  */
 function test_from_string()
 {
     $duration = Duration::fromString('-7:09:12:06.10');
     $this->assertEqual($duration->days(), -7);
     $this->assertEqual($duration->hours(), -9);
     $this->assertEqual($duration->minutes(), -12);
     $this->assertEqual($duration->seconds(), -6);
     $duration = Duration::fromString('+0:01:02');
     $this->assertEqual($duration->days(), 0);
     $this->assertEqual($duration->hours(), 1);
     $this->assertEqual($duration->minutes(), 2);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::fromString('0:00:00:00');
     $this->assertEqual($duration->days(), 0);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     // 50 years (18250 days)
     $duration = Duration::fromString('18250:12:00:00');
     $this->assertEqual($duration->days(), 18250);
     $this->assertEqual($duration->hours(), 12);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     // 500 years (182500 days)
     $duration = Duration::fromString('182500:12:00:00');
     $this->assertEqual($duration->days(), 182500);
     $this->assertEqual($duration->hours(), 12);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     // -500 years (-182500 days)
     $duration = Duration::fromString('-182500:12:00:00');
     $this->assertEqual($duration->days(), -182500);
     $this->assertEqual($duration->hours(), -12);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     // 500,000,000 years (182500000000 days)
     $duration = Duration::fromString('182500000000:12:00:00');
     $this->assertEqual($duration->days(), 182500000000);
     $this->assertEqual($duration->hours(), 12);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     // Beyond 4 billion years, the precision drops from
     // second precision to hour precision.
     // 50,000,000,000 years (18250000000000 days)
     $duration = Duration::fromString('18250000000000:12:00:00');
     $this->assertEqual($duration->days(), 18250000000000);
     $this->assertEqual($duration->hours(), 12);
     // 		$this->assertEqual($duration->minutes(), 0);
     // 		$this->assertEqual($duration->seconds(), 0);
 }