Created
February 24, 2016 11:18
-
-
Save Foxy79/747c2f0c1b0e55cc4d20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function TimeRangeRusString($time1,$time2) { | |
$diff = $time2-$time1; | |
if ($diff==0) return "0 секунд"; | |
$str = array(); | |
if ($diff>=2592000) { $h = floor($diff/2592000); $str[] = omNumber($h, array('месяц','месяца','месяцев')); $diff-=$h*2592000; } | |
if ($diff>=604800 && count($str)<1) { $h = floor($diff/604800); $str[] = omNumber($h, array('неделю','недели','недель')); $diff-=$h*604800; } | |
if ($diff>=86400 && count($str)<1) { $h = floor($diff/86400); $str[] = omNumber($h, array('день','дня','дней')); $diff-=$h*86400; } | |
if ($diff>=3600 && count($str)<1) { $h = floor($diff/3600); $str[] = omNumber($h, array('час','часа','часов')); $diff-=$h*3600; } | |
if ($diff>=60 && count($str)<1) { $m = floor($diff/60); $str[] = omNumber($m, array('минуту','минуты','минут')); $diff-=$m*60; } | |
if ($diff>0 && count($str)<1) { $str[] = omNumber($diff, array('секунду','секунды','секунд')); } | |
return implode(', ',$str); | |
} | |
function omNumber($number, $titles, $addnum = true){ | |
$cases = array (2, 0, 1, 1, 1, 2); | |
return ($addnum ? $number." ":'').$titles[ ($number%100>4 && $number%100<20)? 2 : $cases[min($number%10, 5)] ]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment