/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2008.
     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: 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 &date) const {
	if (!day.isEarlier(date.day)) {
		return FALSE;
	}
	if (!time.isEarlier(date.time)) {
		return FALSE;
	}

	return TRUE;
}

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;
	}
	return TRUE;
}

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::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 TRUE;
}
