Time spec parser, first commit
This commit is contained in:
parent
fdc7ddbd1f
commit
1430cd80fb
1 changed files with 27 additions and 0 deletions
27
web/site/mustard/include/parsetime.php
Normal file
27
web/site/mustard/include/parsetime.php
Normal 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);
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in a new issue