Open alexey-malov opened 6 years ago
unsigned CTime::GetMinutes() const
{
return m_timeStamp / SECONDS_IN_A_MINUTE -
((m_timeStamp / SECONDS_IN_A_HOUR) * SECONDS_IN_A_MINUTE);
}
CTime const CTime::operator++(int)
{
unsigned tempCopy = m_timeStamp;
m_timeStamp++;
if (m_timeStamp >= SECONDS_IN_A_DAY)
{
m_timeStamp = 0;
}
return CTime(tempCopy);
}
CTime CTime::operator-(CTime const & time2) const
{
unsigned resultOfSubTimes = 0;
if (m_timeStamp < time2.GetTimeStamp())
{
resultOfSubTimes = SECONDS_IN_A_DAY - (time2.GetTimeStamp() - m_timeStamp);
}
else
{
resultOfSubTimes = m_timeStamp - time2.GetTimeStamp();
}
return CTime(resultOfSubTimes);
}
CTime & CTime::operator+=(CTime const & sumTimeValue)
{
unsigned firstTime = m_timeStamp;
unsigned timeStamp = (firstTime + sumTimeValue.m_timeStamp) % SECONDS_IN_A_DAY;
m_timeStamp = timeStamp;
return *this;
}
unsigned CTime::operator/(CTime const & time) const
{
if (time.m_timeStamp <= 0)
{
throw std::invalid_argument("Invalid argument");
}
return (m_timeStamp / time.m_timeStamp);
}
bool CTime::operator >(CTime const & time) const
{
return (m_timeStamp >= time.m_timeStamp);
}
bool CTime::operator <(CTime const & time) const
{
return (m_timeStamp <= time.m_timeStamp);
}
bool CTime::operator <=(CTime const & time) const
{
return (m_timeStamp < time.m_timeStamp);
}