public function getTotalInterval($interval, $type){
switch($type){
case 'years':
return $interval->format('%Y');
break;
case 'months':
$years = $interval->format('%Y');
$months = 0;
if($years){
$months += $years*12;
}
$months += $interval->format('%m');
return $months;
break;
case 'days':
return $interval->format('%a');
break;
case 'hours':
$days = $interval->format('%a');
$hours = 0;
if($days){
$hours += 24 * $days;
}
$hours += $interval->format('%H');
return $hours;
break;
case 'minutes':
$days = $interval->format('%a');
$minutes = 0;
if($days){
$minutes += 24 * 60 * $days;
}
$hours = $interval->format('%H');
if($hours){
$minutes += 60 * $hours;
}
$minutes += $interval->format('%i');
return $minutes;
break;
case 'seconds':
$days = $interval->format('%a');
$seconds = 0;
if($days){
$seconds += 24 * 60 * 60 * $days;
}
$hours = $interval->format('%H');
if($hours){
$seconds += 60 * 60 * $hours;
}
$minutes = $interval->format('%i');
if($minutes){
$seconds += 60 * $minutes;
}
$seconds += $interval->format('%s');
return $seconds;
break;
case 'milliseconds':
$days = $interval->format('%a');
$seconds = 0;
if($days){
$seconds += 24 * 60 * 60 * $days;
}
$hours = $interval->format('%H');
if($hours){
$seconds += 60 * 60 * $hours;
}
$minutes = $interval->format('%i');
if($minutes){
$seconds += 60 * $minutes;
}
$seconds += $interval->format('%s');
$milliseconds = $seconds * 1000;
return $milliseconds;
break;
default:
return NULL;
}
}