#include "TimeOfDayDef.h"

void FTimeOfDayDef::AddTime(int32 InSeconds)
{
	int32 days = InSeconds / DAYS_TO_SECONDS;
	InSeconds %= DAYS_TO_SECONDS;
	
	int32 hours = InSeconds / HOURS_TO_SECONDS;
	InSeconds %= HOURS_TO_SECONDS;
	
	int32 minutes = InSeconds / MINUTES_TO_SECONDS;
	InSeconds %= MINUTES_TO_SECONDS;
	
	Days += days;
	Hours += hours;
	Minutes += minutes;
	Seconds += InSeconds;
	
	if (Seconds >= 60)
	{
		Minutes += Seconds / MINUTES_TO_SECONDS;
		Seconds %= MINUTES_TO_SECONDS;
	}
	if (Minutes >= 60)
	{
		Hours += Minutes / 60;
		Minutes %= 60;
	}
	if (Hours >= 24)
	{
		Days += Hours / 24;
		Hours %= 24;
	}
	uint8 DaysEnum = static_cast<uint8>(Days % 7) + 1;
	Weekday = static_cast<EWeekday>(DaysEnum);
}

float FTimeOfDayDef::GetTimeOfDayInHours() const
{
	return Hours + (Minutes / 60.f) + (Seconds / 3600.f);
}
