Пример #1
0
 /**
  * TimeSpan::Subtract()
  *
  * @param mixed $timeSpan
  * @return
  */
 function Subtract($timeSpan)
 {
     if (!is_object($timeSpan)) {
         $timeSpan = new TimeSpan($timeSpan);
     }
     $newTimeSpan = new TimeSpan();
     $carry = 0;
     $newTimeSpan->p_fractions = $this->p_fractions - $timeSpan->p_fractions;
     if ($newTimeSpan->p_fractions < 0) {
         $newTimeSpan->p_fractions += 1000;
         $carry = 1;
     }
     $newTimeSpan->p_seconds = $this->p_seconds - $timeSpan->p_seconds - $carry;
     if ($newTimeSpan->p_seconds < 0) {
         $newTimeSpan->p_seconds += 60;
         $carry = 1;
     } else {
         $carry = 0;
     }
     $newTimeSpan->p_minutes = $this->p_minutes - $timeSpan->p_minutes - $carry;
     if ($newTimeSpan->p_minutes < 0) {
         $newTimeSpan->p_minutes += 60;
         $carry = 1;
     } else {
         $carry = 0;
     }
     $newTimeSpan->p_hours = $this->p_hours - $timeSpan->p_hours - $carry;
     if ($newTimeSpan->p_hours < 0) {
         $newTimeSpan->p_hours += 24;
         $carry = 1;
     } else {
         $carry = 0;
     }
     $newTimeSpan->p_days = $this->p_days - $timeSpan->p_days - $carry;
     $newTimeSpan->ComputeTotals();
     return $newTimeSpan;
 }