Ejemplo n.º 1
0
 /**
  * Test the creation based on a times other than a day.
  */
 function test_non_day_creation()
 {
     // 5 hours
     $duration = Duration::withDaysHoursMinutesSeconds(0, 5, 0, 0);
     $this->assertEqual($duration->days(), 0);
     $this->assertEqual($duration->hours(), 5);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $this->assertEqual($duration->asSeconds(), 3600 * 5);
     $this->assertTrue($duration->isEqualTo(Duration::withHours(5)));
     // 15 minutes
     $duration = Duration::withDaysHoursMinutesSeconds(0, 0, 15, 0);
     $this->assertEqual($duration->days(), 0);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 15);
     $this->assertEqual($duration->seconds(), 0);
     $this->assertEqual($duration->asSeconds(), 15 * 60);
     $this->assertTrue($duration->isEqualTo(Duration::withMinutes(15)));
     // 35 seconds
     $duration = Duration::withDaysHoursMinutesSeconds(0, 0, 0, 35);
     $this->assertEqual($duration->days(), 0);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 35);
     $this->assertEqual($duration->asSeconds(), 35);
     $this->assertTrue($duration->isEqualTo(Duration::withSeconds(35)));
     // 3 days, 2 hours, 23 minutes, and 12 seconds
     $duration = Duration::withDaysHoursMinutesSeconds(3, 2, 23, 12);
     $this->assertEqual($duration->days(), 3);
     $this->assertEqual($duration->hours(), 2);
     $this->assertEqual($duration->minutes(), 23);
     $this->assertEqual($duration->seconds(), 12);
     $this->assertEqual($duration->asSeconds(), ((3 * 24 + 2) * 60 + 23) * 60 + 12);
     // 48 hours
     $duration = Duration::withDaysHoursMinutesSeconds(0, 48, 0, 0);
     $this->assertEqual($duration->days(), 2);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $this->assertEqual($duration->asSeconds(), 86400 * 2);
     // Month
     $duration = Duration::withMonth('June');
     $this->assertEqual($duration->days(), 30);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::withMonth('July');
     $this->assertEqual($duration->days(), 31);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::withMonth(9);
     $this->assertEqual($duration->days(), 30);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     // Weeks
     $duration = Duration::withWeeks(1);
     $this->assertEqual($duration->days(), 7);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::withWeeks(5);
     $this->assertEqual($duration->days(), 35);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::withWeeks(1.5);
     $this->assertEqual($duration->days(), 10);
     $this->assertEqual($duration->hours(), 12);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::withWeeks(1.5);
     $this->assertEqual($duration->days(), 10);
     $this->assertEqual($duration->hours(), 12);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::withWeeks(1.374);
     $this->assertEqual($duration->days(), 9);
     $this->assertEqual($duration->hours(), 14);
     $this->assertEqual($duration->minutes(), 49);
     $this->assertEqual($duration->seconds(), 55);
     $duration = Duration::withWeeks(-1.374);
     $this->assertEqual($duration->days(), -9);
     $this->assertEqual($duration->hours(), -14);
     $this->assertEqual($duration->minutes(), -49);
     $this->assertEqual($duration->seconds(), -55);
     //Zero
     $duration = Duration::zero();
     $this->assertEqual($duration->days(), 0);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
 }