MastodonHelp/web/lib/parsetime.php

29 lines
558 B
PHP
Raw Normal View History

2023-12-26 11:16:24 +01:00
<?php
function parsetime($str) {
$str=explode(',',$str);
$secs=0;
foreach ($str as $ent) {
if (preg_match('/^(\d+)([smhdwMy])$/',$ent,$mat)!==1)
return(false);
$mat[1]+=0;
2023-12-26 11:16:24 +01:00
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;
2023-12-26 11:16:24 +01:00
}
?>