public static function parseLocalTime($duration, array $allowed = [':', '.', ','])
{
if (empty($duration)) {
return 0;
}
$parts = explode(' ', $duration);
$duration = array_pop($parts);
if (strpos($duration, '.') !== false && in_array('.', $allowed)) {
$duration = static::decimalToStandardTime($duration, 2, ':');
} elseif (strpos($duration, ',') !== false && in_array(',', $allowed)) {
$duration = str_replace(',', '.', $duration);
$duration = static::decimalToStandardTime($duration, 2, ':');
}
// now there is only the time schema left...
$pieces = explode(':', $duration, 3);
$res = 0;
$hours = abs((int) $pieces[0]) * HOUR;
//echo pre($hours);
$isNegative = strpos((string) $pieces[0], '-') !== false ? true : false;
if (count($pieces) === 3) {
$res += $hours + (int) $pieces[1] * MINUTE + (int) $pieces[2] * SECOND;
} elseif (count($pieces) === 2) {
$res += $hours + (int) $pieces[1] * MINUTE;
} else {
$res += $hours;
}
if ($isNegative) {
return -$res;
}
return $res;
}