Date Time Php

Function TimeCalculate ($o, $time1, $time2) {
if ($o == '+') {
$a = substr($time1, 0, 1) + substr($time2, 0, 1);
$b = substr($time1, 2, 2) + substr($time2, 2, 2);
if ($b >= 60) {
$a = $a + 1;
$b = $b - 60;
if ($b == 0) {
$b = '00';
}
}
return $a . ":" . $b;
} else if ($o == '-') {
$a_1 = substr($time1, 0, 1);
$b_1 = substr($time2, 0, 1);
$a_2 = substr($time1, 2, 2);
$b_2 = substr($time2, 2, 2);
$a = $a_1 - $b_1;
$b = $a_2 - $b_2;
return $a . ":" . $b;
}
}
echo TimeCalculate ('-','2:50', '1:20');
echo "
";
echo TimeCalculate ('+','2:50', '1:20');
?>