<?php
class TimeDiff {
public $month;
public $day;
public $year;
public $hour;
public $minute;
public $second;
function __construct($year, $month, $day, $hour, $minute, $second) {
$this->month = $month;
$this->day = $day;
$this->year = $year;
$this->hour = $hour;
$this->minute = $minute;
$this->second = $second;
}
function TimeTo() {
$m = $this->month;
$d = $this->day;
$y = $this->year;
$ho = $this->hour;
$mi = $this->minute;
$se = $this->second;
$mn = date("m");
$dn = date("d");
$yn = date("y");
$hh = date("H");
$mm = date("i");
$ss = date("s");
$diff = mktime($ho,$mi,$se,$m,$d,$y)-mktime($hh,$mm,$ss,$mn,$dn,$yn);
$days = $diff/60/60/24;
$hours = $diff/60/60 - intval($days)*24;
$minutes = $diff/60 - intval(intval($days*24)*60);
$seconds = $diff - intval(intval(intval($days*24*60))*60);
$text.= round($days);
$mins = round($days)."";
if ($mins == "11" or $mins == "12" or $mins == "13" or $mins == "14") $text.= " суток "; else
if (
$mins[strlen($mins)-1] == "2"
or $mins[strlen($mins)-1] == "3"
or $mins[strlen($mins)-1] == "4")
$text.= " суток "; else
if($mins[strlen($mins)-1] == "1")
$text.= " сутки "; else
$text.= " суток ";
$text.= round($hours);
if (round($hours) == 1 or round($hours == 21)) $text.= " час "; else
if (round($hours) == 2 or round($hours) == 3 or round($hours) == 4 or round($hours) == 22 or round($hours) == 23) $text.= " часа ";
else $text.= " часов ";
$text.= round($minutes);
$mins = round($minutes)."";
if ($mins == "11" or $mins == "12" or $mins == "13" or $mins == "14") $text.= " минут "; else
if (
$mins[strlen($mins)-1] == "2"
or $mins[strlen($mins)-1] == "3"
or $mins[strlen($mins)-1] == "4")
$text.= " минуты "; else
if($mins[strlen($mins)-1] == "1")
$text.= " минута "; else
$text.= " минут ";
/*$text.= round($seconds);
$mins = round($seconds)."";
if ($mins == "11" or $mins == "12" or $mins == "13" or $mins == "14") $text.= " секунд "; else
if (
$mins[strlen($mins)-1] == "2"
or $mins[strlen($mins)-1] == "3"
or $mins[strlen($mins)-1] == "4")
$text.= " секунды "; else
if($mins[strlen($mins)-1] == "1")
$text.= " секунда "; else
$text.= " секунд ";*/
return $text;
}
}
?>