Good day! I am writing a function that defines the time since the comment was posted, but there is a snag. in our time, in contrast to the American, where there is a single and plural number such as year and years, we get even with seconds the parking, example 1 second (back) 2 seconds, 5 seconds, and so on, or for example 1 month, 2 months , 5 months, or 1 year ago, 2 years, 5 years, etc.
I sat down to write and that's how not kosher it turns out:
function timeAgo($time_ago) { $cur_time = time(); $time_elapsed = $cur_time - $time_ago; $seconds = $time_elapsed ; $minutes = round($time_elapsed / 60 ); $hours = round($time_elapsed / 3600); $days = round($time_elapsed / 86400 ); $weeks = round($time_elapsed / 604800); $months = round($time_elapsed / 2600640 ); $years = round($time_elapsed / 31207680 ); $msg = null; // Seconds if($seconds <= 60){ if ($seconds == 1) $msg = "1 секунду"; else if ( $seconds < 5 ) $msg = "$seconds секунды"; else if ( $seconds <= 20 ) $msg = "$seconds секунд"; else if ( $seconds == 21 ) $msg = "21 секунду"; else if ( $seconds <= 24 ) $msg = "$seconds секунды"; else if ( $seconds <= 29 ) $msg = "$seconds секунд"; else if ( $seconds == 30 ) $msg = "30 секунд"; ... } ... return msg; } In general, dear progers, there may be a ready-made solution, or you can somehow simplify this matter, otherwise you can describe it for very long in all cases, and there is no readability ...
I would appreciate any suggestions on this topic.
[$second:секунд(а,ы,)]- ReinRaus