Time spec parser, first commit

This commit is contained in:
pezcurrel 2022-12-15 23:57:31 +01:00
parent fdc7ddbd1f
commit 1430cd80fb

View file

@ -0,0 +1,27 @@
<?php
function parsetime($str) {
$str=explode(',',$str);
$secs=0;
foreach ($str as $ent) {
if (preg_match('/^(\d+)([smhdwMy])$/',$ent,$mat)!==1)
return(false);
if ($mat[2]=='s')
$secs+=$mat[1];
elseif ($mat[2]=='m')
$secs+=$mat[1]*60;
elseif ($mat[2]=='h')
$secs+=$mat[1]*60*60;
elseif ($mat[2]=='d')
$secs+=$mat[1]*60*60*24;
elseif ($mat[2]=='w')
$secs+=$mat[1]*60*60*24*7;
elseif ($mat[2]=='M')
$secs+=$mat[1]*60*60*24*31;
elseif ($mat[2]=='y')
$secs+=$mat[1]*60*60*24*365;
}
return($secs);
}
?>