//	Darkstar Engine  (c) UnderWorld Interactive Studio (all coding by Svarog    2008)
//
//      Данный файл является частью Darkstar Engine. Любое использование кода файла
//      без согласия компании, является нарушением закона об авторском праве (в слу-
//      чае если не оговорено обратное).
//
//      Имя файла: time.inl
//      Краткое описание: time representation
//

namespace ker
{
	inline Time::Time()
	{
		setTime(0, 0, 0);
	};

	inline Time::Time(const unsigned char hour, const unsigned char minute, const unsigned char second)
	{
		setTime(hour, minute, second);
		_calculateAllCurDayValues();
	};

	inline Time::Time(const float day_minute)
	{
		setCurrentDayMinute(day_minute);
	};

	inline Time::Time(const Time& time)
	{
		hour = time.getHour();
		minute = time.getMinute();
		second = time.getSecond();
		cur_day_second = time.getCurrentDaySecond();
		cur_day_minute = time.getCurrentDayMinute();
		cur_day_hour = time.getCurrentDayHour();
	};

	inline Time::~Time()
	{

	};

	inline Time& Time::operator =(const Time& time)
	{
		hour = time.getHour();
		minute = time.getMinute();
		second = time.getSecond();
		cur_day_second = time.getCurrentDaySecond();
		cur_day_minute = time.getCurrentDayMinute();
		cur_day_hour = time.getCurrentDayHour();
		return *this;
	};

	inline bool Time::operator <(const Time& time) const
	{
		return cur_day_second < time.getCurrentDaySecond();
	};

	inline void Time::_calculateCurDayHour()
	{
		cur_day_hour = hour + (float)minute / 60.0f + (float)second/3600.0f;
	};

	inline void Time::_calculateCurDayMin()
	{
		cur_day_minute = hour*60.0f + minute + (float)second/60.0f;
	};

	inline void Time::_calculateCurDaySec()
	{
		cur_day_second = hour*3600.0f + minute*60.0f + second;
	};

	inline void Time::_calculateAllCurDayValues()
	{
		_calculateCurDayHour();
		_calculateCurDayMin();
		_calculateCurDaySec();
	};

	inline void Time::setHour(const unsigned char new_hour)
	{
		setTime(new_hour, minute, second);
	};

	inline void Time::setMinute(const unsigned char new_minute)
	{
		setTime(hour, new_minute, second);
	};

	inline void Time::setSecond(const unsigned char new_second)
	{
		setTime(hour, minute, new_second);
	};

	inline void Time::setTime(const unsigned char new_hour, const unsigned char new_minute, const unsigned char new_second)
	{
		hour = new_hour;
		minute = new_minute;
		second = new_second;
		_calculateAllCurDayValues();
	};

	inline const unsigned char Time::getHour() const
	{
		return hour;
	};

	inline const unsigned char Time::getMinute() const
	{
		return minute;
	};

	inline const unsigned char Time::getSecond() const
	{
		return second;
	};

	inline const float Time::getCurrentDayHour() const
	{
		return cur_day_hour;
	};

	inline const float Time::getCurrentDayMinute() const
	{
		return cur_day_minute;
	};

	inline const float Time::getCurrentDaySecond() const
	{
		return cur_day_second;
	};

	inline void Time::setCurrentDayMinute(const float new_day_minute)
	{
		hour = (unsigned char)floorf(new_day_minute / 60.0f);
		minute = (unsigned char)floorf(new_day_minute - 60.0f*hour);
		second = (unsigned char)((new_day_minute - 60.0f*hour - (float)minute)*60.0f);
		cur_day_minute = new_day_minute;
		_calculateCurDayHour();
		_calculateCurDaySec();
	};

	inline std::ostream& operator <<(std::ostream& os, const Time& time)
	{
		os << (unsigned int)time.getHour() << ":" << (unsigned int)time.getMinute() << ":" << (unsigned int)time.getSecond();
		return os;
	};
};