{% else-1 %}

                        
<?php 
/**

* @name Класс для работы со временем

* @author Скитч. ICQ: 2134410.

* @date 23.12.2011

* @version 0.1

*/

class Mumbu_time{
/**
* длинные названия месяцов
*/
private $monthlong = array('января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря');
private $monthshort = array('янв', 'фев', 'мар', 'апр', 'май', 'июн', 'июл', 'авг', 'сен', 'окт', 'ноя', 'дек');

/**
* множественные формы слов
*/
private $yearword = array('год', 'года', 'лет');
private $monthword = array('месяц', 'месяца', 'месяцев');
private $dayword = array('день', 'дней', 'дней');
private $hourword = array('час', 'часа', 'часов');
private $minuteword = array('минута', 'минуты', 'минут');
private $secondword = array('секунда', 'секунды', 'секунд');

/**
* формат вывода даты
*/
private $year = 'y';
private $month = 'm';
private $day = 'd';
private $hour = 'H';
private $minute = 'i';
private $second = 's';

/**
* @param $tz — timezone.
*/
function __construct($tz = null){

if($tz == null)

date_default_timezone_set('Europe/Moscow');

else

date_default_timezone_set($tz);

}

/**
* Обрабатываем и выводим time()
*/
public function get(){

return time();
}

/**
* Выводим время $fullmonth — полное название месяца
*/
public function clock($time = null, $fullmonth = true){

$time = ($time == null? $this->get(): $time);

$d = date($this->day, $time);

$m = date($this->month, $time);

$y = date($this->year, $time);
$m = ($fullmonth? $this->monthlong[$m — 1]: $this->monthshort[$m — 1]);

$full_time = $d.' '.$m.' '.$y.' в '.date(($this->hour != null? $this->hour.':': null). ($this->minute != null? ($this->hour == null? ':': null). $this->minute: null), $time);

$date = date('d.m.Y', $time);

$time = date('H:i', $time);

if($date == date('d.m.Y')) $full_time = date('Сегодня в H:i', $time);

if($date == date('d.m.Y', time()-60*60*24)) $full_time = date('Вчера в H:i', $time);

return $full_time;
}

/**
* Время с момента
*/
public function time_ago($time= null){

#$ltime = $this->get() — $time;
$ltime = ($time == null? $this->get(): $time) — $time;

if($ltime < 5){ return 'только что';
}elseif($ltime < 60){ return $ltime.' '.$this->plural_form($ltime, 'секунду', 'секунды', 'секунд').'';
}elseif($ltime < 3600){ return round($ltime/60).' '.$this->plural_form(round($ltime/60), 'минуту', 'минуты', 'минут');
}elseif($ltime < 86400){ return round($ltime/3600).' '.$this->plural_form(round($ltime/3600), 'час', 'часа', 'часов');
}elseif($ltime > 1814400){ return $this->clock($ltime);
}elseif($ltime > 604800){ return round($ltime/604800).' '.$this->plural_form(round($ltime/86400), 'неделю', 'недели', 'недель');
}elseif($ltime > 86400){ return round($ltime/86400).' '.$this->plural_form(round($ltime/86400), 'день', 'дня', 'дней');
}

}

/**
* Обратный отсчёт

* @var early — время от которого начинается отсчет

* @var later — время до которого идет отсчет
* @param enclosure — вложенность вывода
*/
public function backtime($early, $later = null, $enclosure = 5){

$out = '';

$count = 0;

if ($later == null)

$later = $this->get();

$year = abs(date('y', $later) — date('y', $early));

if($year > 0){

if($enclosure != 0 and $count < $enclosure) {

++$count;

$out .= $year.' '.$this->plural_form($year, $this->yearword);
}
}

$month = abs(date('m', $later) — date('m', $early));

if($month != 0){

if($enclosure != 0 and $count < $enclosure) {

++$count;

$out .= ' '.$month.' '.$this->plural_form($month, $this->monthword);
}
}

$day = abs(date('d', $later) — date('d', $early));

if($day > 0){

if($enclosure != 0 and $count < $enclosure) {

++$count;

$out .= ' '.$day.' '.$this->plural_form($day, $this->dayword);
}
}

$hour = abs(date('H', $later) — date('H', $early));

if($hour > 0){

if($enclosure != 0 and $count < $enclosure) {

++$count;

$out .= ' '.$hour.' '.$this->plural_form($hour, $this->hourword);

}
}

$minute = abs(date('i', $later) — date('i', $early));

if($minute > 0) {

if($enclosure != 0 and $count < $enclosure) {

++$count;

$out .= ' '.$minute.' '.$this->plural_form($minute, $this->minuteword);

}
}

$second = abs(date('s', $later) — date('s', $early));

if($second > 0) {

if($enclosure != 0 and $count < $enclosure) {

$out .= ' '.$second.' '.$this->plural_form($second, $this->secondword);

}
}

return $out;

}

/**
* Форма множественного числа
*/
private function plural_form($num, $array){

$q = ($num % 10 == 1 && $num % 100 != 11? 0: ($num % 10 >= 2 && $num % 10 <= 4 &&

($num % 100 < 10 or $num % 100 >= 20)? 1: 2));

return ($q == 0? $array[0]: ($q == 1? $array[1]: ($q == 2? $array[2]: null)));
}

}
?>
0 23 0
Без комментариев...