Reputation: 10621
I have a function to deal with the "s" on the end of plurals and another to convert a total of seconds into something more human intuitive.
I'm trying to use the plurals function inside the secondstotime so that it will say "1 day" and "10 days" for example. Notice the "s" on the end.
function plurals($number)
{
if ($number == 1)
{
return '';
}
else
{
return 's';
}
}
function secondstotime($seconds)
{
$dtF = new DateTime("@0");
$dtT = new DateTime("@$seconds");
if ($seconds < 60)
{
return $dtF->diff($dtT)->format('%s seconds');
}
else if ($seconds < 3600)
{
return $dtF->diff($dtT)->format('%i minutes');
}
else if ($seconds < 86400)
{
return $dtF->diff($dtT)->format('%h hours, %i minutes');
}
else if ($seconds < 31536000)
{
return $dtF->diff($dtT)->format('%a days');
}
else
{
return $dtF->diff($dtT)->format('%y years, %a days');
}
}
How do I do this? I've tried using code like this but it doesn't work:
return $dtF->diff($dtT)->format('%a day'.plurals('%a'));
Upvotes: 1
Views: 77
Reputation: 5831
'%a'
is not a number, try this
return $dtF->diff($dtT)->format('%a day'.plurals($dtF->diff($dtT)->format('%a')));
Upvotes: 3