Can we add extra functionality to the function
display_date ?
Which displays the
time ago, while currently we have basic function like
Today and
Yesterday only.
It will be more better if we can add
time ago -->
(s) ago
Second
Minutes
Hour
Day
Month
public static function display_date($var)
{
$shift = (self::$system_set['timeshift'] + self::$user_set['timeshift']) * 3600;
if (date('Y', $var) == date('Y', time())) {
if (date('z', $var + $shift) == date('z', time() + $shift)) {
return self::$lng['today'] . ', ' . date("H:i", $var + $shift);
}
if (date('z', $var + $shift) == date('z', time() + $shift) - 1) {
return self::$lng['yesterday'] . ', ' . date("H:i", $var + $shift);
}
}
return date("d.m.Y / H:i", $var + $shift);
}
Devendraoli, yes it is possible. Today, i will write.
Here's the code, but it needs to be to celebrate. And then, wherever you want to change the output varying functions of time.
* (+/-)
function slv($str,$msg1,$msg2,$msg3 {
$str = (int)$str;
$str1 = abs($str % 100;
$str2 = $str % 10;
if ($str1 > 10 && $str1 < 20 return $str .' '. $msg3;
if ($str2 > 1 && $str2 < 5 return $str .' '. $msg2;
if ($str2 == 1 return $str .' '. $msg1;
return $str .' '. $msg3;
}
function ptimenews($t, $f="d.m.Y в H:i "{
global $user;
$time = time();
if(($time - $t == 0{
$out = 'только что';
}else
if(($time - $t <= 60{
$out = slv((($time-$t),'секунду','секунды','секунд'.' назад';
}
else if(($time - $t >= 60*60*24 && ($time - $t <= 60*60*24*2)
$out = 'вчера в ' . date("H:i", $t + $user['sdvig'] * 3600;
else if(($time - $t >= 60*60*24*2 && ($time - $t <= 60*60*24*3)
$out = 'позавчера в ' . date("H:i", $t + $user['sdvig'] * 3600;
else if($time - $t >= 60*60*24*3
$out = date($f, $t + $user['sdvig'] * 3600;
else
{
$r = $time - $t;
if($r < 3600
{
$vars = array(
'минут',
'минуту',
'минуты',
'минуты',
'минуты',
'минут',
'минут',
'минут',
'минут',
'минут'
;
$a = ($r/60 % 10;
if(($r >= 11*60 && ($r <= 20*60)
$v = $vars['0'];
else
$v = $vars[$a];
$out = floor($r/60 . ' ' . $v . ' назад';
}
else if($r >= 3600 && $r <= 60*60*24
{
$vars = array(
'часов',
'час',
'часа',
'часа',
'часа',
'часов',
'часов',
'часов',
'часов',
'часов'
;
$a = ($r/3600 % 10;
if(($r >= 11*60*60 && ($r <= 20*60*60)
$v = $vars['0'];
else
$v = $vars[$a];
$out = floor($r/3600 . ' ' . $v . ' назад';
}
}
return $out;
}
П.С. переводил через гугл, не знаю все правильно написано.
Devendraoli, if i understand correctly, then you need this option
code (+/-)
public static function display_date($var)
{
$label = time() - $var;
if ($label < 60) {
$out = $label .' (s) ago';
} elseif ($label < 3600) {
$out = intval($label / 60) .' (m) ago';
} elseif ($label < (3600 * 24)) {
$out = intval($label / 3600) .' (h) ago';
} elseif ($label < (3600 * 24 * date('t'))) {
$out = intval($label / (3600 * 24)) .' (d) ago';
} elseif ($label < (3600 * 24 * (date('L') + 365))) {
$out = intval($label / (3600 * 24 * 30)) .' (m) ago';
} else {
$shift = (self::$system_set['timeshift'] + self::$user_set['timeshift']) * 3600;
$out = date('d.m.Y / H:i', $var + $shift);
}
return $out;
}