<?

/* Date
 * 
 * A class for storing a date
 */
 
class Date
{
	/* Private member fields
	 *
	 * int $year - the year of the date being stored (4 digits)
	 * int $month - the number of the month being stored (1-12)
	 * int $day - the number of the day for this date (day of the month, 1-31)
	 * int $hour - the hour of the date being stored (0-23)
	 * int $minute - the minute of the date being stored (0-59)
	 * int $second - the second of the date being stored (0-59)
	 */
	 
	private $year = 0;
	private $month = 0;
	private $day = 0;
	private $hour = 0;
	private $minute = 0;
	private $second = 0;

	/* __construct($initial_year, $initial_month, $initial_day, $initial_hour,
	 *             $initial_minute, $initial_second)
	 *
	 * The constructor takes in the year, month, day, hour, minute and seconds
	 * of the date that the class represents.  It simply sets all of the
	 * member variables of the class to the inputs provided.
	 *
	 * In: int $initial_year - the year of the date being stored
	 * In: int $initial_month - the month of the date being stored
	 * In: int $initial_day - the day of the date being stored
	 * In: int $initial_hour - the hour of the date being stored
	 * In: int $initial_minute - the minute of the date being stored
	 * In: int $initial_second - the second of the date being stored
	 */
	 
	function __construct($initial_year, $initial_month, $initial_day,
						 $initial_hour, $initial_minute, $initial_second){
		$this->year = $initial_year;
		$this->month = $initial_month;
		$this->day = $initial_day;
		$this->hour = $initial_hour;
		$this->minute = $initial_minute;
		$this->second = $initial_second;
	}

	/* getYear()
	 *
	 * This method returns the year of the date being stored
	 *
	 * Return - int - the year of the date represented by this class
	 */
	 
	public function getYear(){
		return $this->year;
	}

	/* getMonth()
	 *
	 * This method returns the month of the date being stored
	 *
	 * Return - int - the month of the date represented by this class
	 */
	 
	public function getMonth(){
		return $this->month;
	}

	/* getDay()
	 *
	 * This method returns the day of the date being stored
	 *
	 * Return - int - the day of the date represented by this class
	 */
	 
	public function getDay(){
		return $this->day;
	}

	/* getHour()
	 *
	 * This method returns the hour of the date being stored
	 *
	 * Return - int - the hour of the date represented by this class
	 */
	 
	public function getHour(){
		return $this->hour;
	}

	/* getMinute()
	 *
	 * This method returns the minute of the date being stored
	 *
	 * Return - int - the minute of the date represented by this class
	 */
	 
	public function getMinute(){
		return $this->minute;
	}

	/* getSecond()
	 *
	 * This method returns the second of the date being stored
	 *
	 * Return - int - the second of the date represented by this class
	 */
	 
	public function getSecond(){
		return $this->second;
	}

	/* compareToCurrentTime()
	 * 
	 * This method compares the date being stored to the current date.  Dates
	 * are compared first by year, then month, then day, then hour, then minute
	 * and then second.  If all of these things are equal, then the two dates
	 * are equal.
	 *
	 * Return: -1 if the date being stored is less than the current date
	 *		    0 if the date being stored is the same as the current date
	 *			1 if the date being stored is greater than the current date
	 */
	 
	public function compareToCurrentTime(){
		$current_time = getdate();

		if($this->year < $current_time["year"]){
			return -1;
		}
		else if($this->year > $current_time["year"]){
			return 1;
		}
		else if($this->month < $current_time["mon"]){
			return -1;
		}
		else if($this->month > $current_time["mon"]){
			return 1;
		}
		else if($this->day < $current_time["mday"]){
			return -1;
		}
		else if($this->day > $current_time["mday"]){
			return 1;
		}
		else if($this->hour < $current_time["hours"]){
			return -1;
		}
		else if($this->hour > $current_time["hours"]){
			return 1;
		}
		else if($this->minute < $current_time["minutes"]){
			return -1;
		}
		else if($this->minute > $current_time["minutes"]){
			return 1;
		}
		else if($this->second < $current_time["seconds"]){
			return -1;
		}
		else if($this->second > $current_time["seconds"]){
			return 1;
		}
		else{
			return 0;
		}	
	}

	/* compareToDate()
	 * 
	 * This method compares the date being stored to the Date provided as an
	 * argument.  Dates are compared first by year, then month, then day, 
	 * then hour, then minute and then second.  If all of these things 
	 * are equal, then the two dates are equal.
	 *
	 * In: Date $date - The Date to compare the date stored in this class to
	 * Return: -1 if the date being stored is less than the argument $date
	 *		    0 if the date being stored is the same as the argument $date
	 *			1 if the date being stored is greater than the argument $date
	 */
	 
	public function compareToDate(Date $date){
		if($this->year < $date->getYear()){
			return -1;
		}
		else if($this->year > $date->getYear()){
			return 1;
		}
		else if($this->month < $date->getMonth()){
			return -1;
		}
		else if($this->month > $date->getMonth()){
			return 1;
		}
		else if($this->day < $date->getDay()){
			return -1;
		}
		else if($this->day > $date->getDay()){
			return 1;
		}
		else if($this->hour < $date->getHour()){
			return -1;
		}
		else if($this->hour > $date->getHour()){
			return 1;
		}
		else if($this->minute < $date->getMinute()){
			return -1;
		}
		else if($this->minute > $date->getMinute()){
			return 1;
		}
		else if($this->second < $date->getSecond()){
			return -1;
		}
		else if($this->second > $date->getSecond()){
			return 1;
		}
		else{
			return 0;
		}	
	}
}

?>
