<?php
	class Date {

		protected $date;

		public static function singleton() {
        	return SingletonBase::singleton(get_class());
    	}

		public function setCountry($country) {
			date_default_timezone_set($country);	
		}

		public function setDate($date) {
			$this->date = $date;
			return $this;
		}

		public static function getToday() {
			return date('Y-m-d', mktime(date("h")+2,0,0,date("m"),date("d"),date("Y")));
		}

		public function getYesterday() {
			return date('Y-m-d', mktime(date("h")+2,0,0,date("m"),date("d")-1,date("Y")));
		}

		public function getTomorrow() {
			$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
			return date("d/m/Y", $tomorrow);
		}

		public function formatDate($mask, $date) {
			return date($mask, strtotime($date)); 
		}

		public function compareDate() {
			$today = self::getToday();
			$yesterday = self::getYesterday();
			$current = date('Y-m-d', strtotime($this->date));
			if ($current == $today)
				return date('h:i: A', strtotime($this->date));
			elseif ($current == $yesterday)
				return 'yesterday';
			else
				return date('Y-m-d', strtotime($this->date));
		}

		/*
		*@return difference (in years, days, hours, min m sec )between two specific dates
		*param $start, $end
		*/
		public function diffTime($start, $end) {
			$subTime = $end - $start;
			$mininsec = $subTime/60;
			$sec = $subTime%60;
			$hourinmin = $mininsec/60;
			$min = $mininsec%60;
			$dayinhour = $hourinmin/24;
			$hour = $hourinmin%24;
			$year = $dayinhour/365;
			$day = $dayinhour%365;
			$diff = intval($year)."years<br />".$day."days<br />".$hour."hours<br />".$min."minutes<br />".$sec."seconds <br />";
			return $diff;	
		}
		/*
		*@return number of days in specific month and specific year accroding to GARGORIAN Calendar
		*@param $month, $year
		*/
		public function daysInMonth($month, $year) {
			$num = cal_days_in_month(CAL_GREGORIAN, $month, $year);
			return $num;
		}
	}

?>
