Answer the question
In order to leave comments, you need to log in
How to convert numeric representation of minutes to text?
Hello! Please tell me, maybe there is some solution on the git or somewhere else?
It is necessary, for example, to convert 123 minutes into the string "2 hours 3 minutes", but at the same time, so that everything is normal with declensions (that is, I could cram different numbers there, and at the same time everything would look normal from the point of view of the Russian language)
Answer the question
In order to leave comments, you need to log in
I will offer my library, which does just what you need: https://github.com/wapmorgan/Morphos
After installing via composer, you can use the \morphos\Russian\TimeSpeller::spellDifference method :
var_dump(\morphos\Russian\TimeSpeller::spellDifference('+123 minute'));
// либо unix timestamp
var_dump(\morphos\Russian\TimeSpeller::spellDifference(time() + 123*60+1));
// +1 нужно потому, что во время парсинга эта секунда "съедается"
I passed the value through this function.
function test($value)
{
$ost = $value % 10;
if ($value >= 5 && $value <= 20) {
$str = 'часов';
} else if ($ost == 2 || $ost == 3 || $ost == 4) {
$str = 'часа';
} else if ($ost == 1) {
$str = 'час';
} else {
$str = 'часов';
}
return $value . ' ' . $str;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question