示例#1
0
 /**
  * Create a new object starting now, with a given duration. 
  * Override - as each Week has a defined duration
  * 
  * @param object DateAndTime $aDateAndTime
  * @param object Duration $aDuration
  * @param optional string $class DO NOT USE OUTSIDE OF PACKAGE.
  *		This parameter is used to get around the limitations of not being
  *		able to find the class of the object that recieved the initial 
  *		method call.
  * @return object Week
  * @access public
  * @since 5/5/05
  * @static
  */
 static function startingDuration($aDateAndTime, $aDuration, $class = 'Week')
 {
     // Validate our passed class name.
     if (!(strtolower($class) == strtolower('Week') || is_subclass_of(new $class(), 'Week'))) {
         die("Class, '{$class}', is not a subclass of 'Week'.");
     }
     $asDateAndTime = $aDateAndTime->asDateAndTime();
     $midnight = $asDateAndTime->atMidnight();
     $dayNames = ChronologyConstants::DayNames();
     $temp = $midnight->dayOfWeek() + 7 - array_search(Week::startDay(), $dayNames);
     $delta = abs($temp - intval($temp / 7) * 7);
     $adjusted = $midnight->minus(Duration::withDays($delta));
     $obj = parent::startingDuration($adjusted, Duration::withWeeks(1), $class);
     return $obj;
 }
 /**
  * Test printable string.
  * 
  */
 function test_printable_string()
 {
     $duration = Duration::withWeeks(1.374);
     $this->assertEqual($duration->printableString(), '9:14:49:55');
     $duration = Duration::withWeeks(-1.374);
     $this->assertEqual($duration->printableString(), '-9:14:49:55');
     $duration = Duration::withWeeks(1.5);
     $this->assertEqual($duration->printableString(), '10:12:00:00');
     $duration = Duration::withDaysHoursMinutesSeconds(3, 2, 23, 7);
     $this->assertEqual($duration->printableString(), '3:02:23:07');
     // 3 days, 2 hours, 23 minutes, and 12 seconds
     $duration = Duration::withDaysHoursMinutesSeconds(3, 2, 23, 12);
     $this->assertEqual($duration->printableString(), '3:02:23:12');
     // -3 days, -2 hours, -23 minutes, and -12 seconds
     $duration = Duration::withDaysHoursMinutesSeconds(-3, -2, -23, -12);
     $this->assertEqual($duration->printableString(), '-3:02:23:12');
 }