/****************************************************************************************


		MCDateTime.h


		Copyright: (c) 2001 Eovia Corp. All rights reserved.


		Author:	maz/tsh
		Date:	9/11/98

		Revision History

		when		who			what & why
		==========	==========	======================================================

*****************************************************************************************/

#ifndef __MCDATETIME__
#define __MCDATETIME__

#if CP_PRAGMA_ONCE
#pragma once
#endif

#include "MCBasicTypes.h"
#include "MCString.h"

class TMCUserTimeRecord;


/// Gives the computer time.
///
/// On the Mac fSeconds is "GetDateTime" time/date
/// On Windows fSecondsHighOrder,,fSeconds is FILETIME
///
class TMCSystemTime : public TMCObject
{
public:
				TMCSystemTime		() { fSecondsHighOrder = fSeconds = 0; }

	void		GetCurrentLocalTime	(void);
	void		SysTimeString		(TMCString& str, boolean display_seconds) const;
	void		SysDateString		(TMCString& str) const;
	void		TimeRecordToSysTime	(const TMCUserTimeRecord& tr);

	
	uint32		fSecondsHighOrder; ///< always zero on Mac - used on Windows
	uint32		fSeconds;
};



inline boolean operator== (const TMCSystemTime& lhs, const TMCSystemTime& rhs)
	{ return(lhs.fSecondsHighOrder == rhs.fSecondsHighOrder && lhs.fSeconds == rhs.fSeconds); }

inline boolean operator!= (const TMCSystemTime& lhs, const TMCSystemTime& rhs)
	{ return(lhs.fSecondsHighOrder != rhs.fSecondsHighOrder || lhs.fSeconds != rhs.fSeconds); }

inline boolean operator < (const TMCSystemTime& lhs, const TMCSystemTime& rhs)
{
	return (lhs.fSecondsHighOrder < rhs.fSecondsHighOrder) || ((lhs.fSecondsHighOrder == rhs.fSecondsHighOrder) && (lhs.fSeconds < rhs.fSeconds));
}


/// Gives the time and date in a human readable form.
///
class TMCUserTimeRecord : public TMCObject
{
public:
	TMCUserTimeRecord	() { fYear = fMonth = fDay = fHour = fMinute = fSecond = fDayOfWeek = 0; }
	
	void		NormalizeTimeRecord	(void);
	void		SysTimeToTimeRecord	(const TMCSystemTime& systemTime);
	
	static void		NormalizeDate	(int16& year, int16& month, int16& day);
	static int16	DayOfWeek		(int16 year, int16 month, int16 day);
	static boolean	IsLeapYear		(int16 year);
	static int16	DaysInMonth		(int16 year, int16 month);
	

	int32 Compare(const TMCUserTimeRecord& date) const
	{
		if		(fYear   < date.fYear)		return -1;
		else if (fYear   > date.fYear)		return  1;
		else if (fMonth  < date.fMonth)		return -1;
		else if (fMonth	 > date.fMonth)		return  1;
		else if (fDay	 < date.fDay)		return -1;
		else if (fDay	 > date.fDay)		return  1;
		else if (fHour	 < date.fHour)		return -1;
		else if (fHour	 > date.fHour)		return  1;
		else if (fMinute < date.fMinute)	return -1;
		else if (fMinute > date.fMinute)	return  1;
		else if (fSecond < date.fSecond)	return -1;
		else if (fSecond > date.fSecond)	return  1;
		else return 0;
	}
	
public:
	int16		fYear;
	int16		fMonth;
	int16		fDay;
	int16		fHour;
	int16		fMinute;
	int16		fSecond;
	int16		fDayOfWeek;
};

#endif // __MCDATETIME__