/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2009.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: sgx/src/sgx/core/time/utctime.cpp

*/

#include "sgx/core/types/types.hpp"
#include "sgx/core/time/time.hpp"

/**
yesterday.isEarlier(today) returns TRUE
*/
tBOOL		
UTCDate::isEarlier(const UTCDate &rhs_date) const {
	if (day.isEarlier(rhs_date.day)) {
		return TRUE;
	} else if (day.isSame(rhs_date.day)) {
		if (time.isEarlier(rhs_date.time)) {
			return TRUE;
		}
	}
	return FALSE;
}


tBOOL		
UTCDay::isSame(const UTCDay &rhs_day) const {
	return year == rhs_day.year && month == rhs_day.month && day == rhs_day.day;
}

tBOOL		
UTCDay::isEarlier(const UTCDay &rhs_day) const {
	if (year > rhs_day.year) {
		return FALSE;
	} else if (year < rhs_day.year) {
		return TRUE;
	}
	if (month > rhs_day.month) {
		return FALSE;
	} else if (month < rhs_day.month) {
		return TRUE;
	}
	if (day > rhs_day.day) {
		return FALSE;
	} else if (day < rhs_day.day) {
		return TRUE;
	}
	return FALSE;	// equal
}

tBOOL		
UTCDay::isLater(const UTCDay &rhs_day) const {
	if (year < rhs_day.year) {
		return TRUE;
	} else if (year > rhs_day.year) {
		return FALSE;
	}
	if (month < rhs_day.month) {
		return TRUE;
	} else if (month > rhs_day.month) {
		return FALSE;
	}
	if (day < rhs_day.day) {
		return TRUE;
	} else if (day > rhs_day.day) {
		return FALSE;
	}
	return FALSE;
}

tREAL32	
UTCTime::timeBetween(const UTCTime &rhs_time) const {
	tREAL32 t1 = hours*60*60 + minutes*60 + seconds + milliseconds/1000.0f;
	tREAL32 t2 = rhs_time.hours*60*60 + rhs_time.minutes*60 + rhs_time.seconds + rhs_time.milliseconds/1000.0f;
	return t1 - t2;
}

tBOOL		
UTCTime::isSame(const UTCTime &rhs_time) const {
	return hours == rhs_time.hours && minutes == rhs_time.minutes && seconds == rhs_time.seconds && milliseconds == rhs_time.milliseconds;
}

tBOOL		
UTCTime::isEarlier(const UTCTime &rhs_time) const {
	if (hours > rhs_time.hours) {
		return FALSE;
	} else if (hours < rhs_time.hours) {
		return TRUE;
	}
	//
	if (minutes > rhs_time.minutes) {
		return FALSE;
	} else if (minutes < rhs_time.minutes) {
		return TRUE;
	}
	if (seconds > rhs_time.seconds) {
		return FALSE;
	} else if (seconds < rhs_time.seconds) {
		return TRUE;
	}
	if (milliseconds > rhs_time.milliseconds) {
		return FALSE;
	} else if (milliseconds < rhs_time.milliseconds) {
		return TRUE;
	}
	// technically equal...
	return FALSE;
}

tBOOL		
UTCTime::isLater(const UTCTime &rhs_time) const {
	if (hours < rhs_time.hours) {
		return TRUE;
	} else if (hours > rhs_time.hours) {
		return FALSE;
	}
	//
	if (minutes < rhs_time.minutes) {
		return TRUE;
	} else if (minutes > rhs_time.minutes) {
		return FALSE;
	}
	if (seconds < rhs_time.seconds) {
		return TRUE;
	} else if (seconds > rhs_time.seconds) {
		return FALSE;
	}
	if (milliseconds < rhs_time.milliseconds) {
		return TRUE;
	} else if (milliseconds > rhs_time.milliseconds) {
		return FALSE;
	}
	// technically equal...
	return FALSE;
}
