<?php
/**
 * DateTime
 *
 * @date 15.03.2007
 * @name DateTime
 * @author Margo Poolak <margo 'dot' poolak 'at' mail 'dot' ee>
 * @copyright Copyright &copy;2006 Margo Poolak. All Rights Reserved.
 * @version 2.0
 * @package System.Library
 * @category 
 * 
 * Date handling class
 */
if(!defined('DATE_FORMAT'))
{
	define('DATE_FORMAT','d.m.Y');
}
class DateTime
{
	private $_day; // current day
	private $_month; // current month
	private $_year; // current year
	private $_date; // used date format
	private $_timestamp;// current time
	private $_latitude; // latitude of Estonia 59, 00 to North
	private $_longitude; // longitude of Estonia 26,00 to East
	private $_zenith; // 90 degrees
	private $_gmt_offset; // +1 GMT
	/*
	*
	*/
	public function __construct()
	{
		date_default_timezone_set("Europe/Tallinn");
		$this->_timestamp = time();
		$this->_date = date(DATE_FORMAT);
		$this->_day = date('d');
		$this->_month = date('m');
		$this->_year = date('Y');
	}
	/**
	* Unix timestamp in microseconds
	* @returns float microseconds
	*/
	public function getMicrotime()
	{
		return microtime(true);
	}
	/**
	* If the GMT offset different
	* @parameter string offset
	*/	
	public function setGmtOffset($offset)
	{
		$this->_gmt_offset = $offset;
	}
	/**
	* Returns the gmt offset
	* @return integer offset
	*/	
	public function getGmtOffset()
	{
		return $this->_gmt_offset;
	}	
	/**
	* Here you can set the timezone
	* @param string timezone
	*/
	public function setTimezone($timezone)
	{
		date_default_timezone_set($timezone);
	}
	/**
	*
	*/
	public function getTimezone()
	{
		return date_default_timezone_get();
	}
	/**
	*
	*/
	public function setDate($date)
	{
		$this->_date = $date;
	}
	/**
	*
	*/
	public function getDate()
	{
		if(!isset($this->_date))
		{
			$this->_date = date(DATE_FORMAT);	
		}
		return $this->_date;		
	}
	/**
	*
	*/
	public function setYear($year)
	{
		$this->_year = $year;
	}
	/**
	*
	*/
	public function getYear()
	{
		if(!isset($this->_year))
		{
			$this->_year = date('Y');	
		}
		return $this->_year;	
	}	
	/**
	*
	*/
	public function getMonth()
	{
		if(!isset($this->_month))
		{
			$this->_month = date('m');	
		}
		return $this->_month;	
	}
	/**
	*
	*/
	public function setMonth($month)
	{
		$this->_month = $month;
	}
	/**
	*
	*/
	public function setDay($day)
	{
		$this->_day = $day;
	
	}
	/**
	*
	*/	
	public function getDay()
	{
		if(!isset($this->_day))
		{
			$this->_day = date('d');	
		}
		return $this->_day;
	}
	/**
	Calculate the sunset time for Tallinn, Estonial
		Latitude: 59, 00 to North
		Longitude: 26,00 to East
		Zenith ~= 90
		offset: +1 GMT
	@param return constant SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING  or SUNFUNCS_RET_DOUBLE | default SUNFUNCS_RET_STRING
	*/
	public function getSunset($return = SUNFUNCS_RET_STRING)
	{
		if(isset($this->_latitude) || $this->_longitude || isset($this->_zenith) || isset($this->_gmt_offset))
		{
			return date_sunset($this->_timestamp, $return, $this->_latitude, $this->_longitude, $this->_zenith, $this->_gmt_offset);
		}
		return;
	}
	/**
	*
	*/
	public function setLatitude($latitude)
	{
		$this->_latitude = $latitude;
	}
}
?>