EvgeniyGlazirin / oop

0 stars 0 forks source link

Замечания по CTime #9

Open alexey-malov opened 6 years ago

alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
unsigned CTime::GetMinutes() const
{
    return m_timeStamp / SECONDS_IN_A_MINUTE - 
        ((m_timeStamp / SECONDS_IN_A_HOUR) * SECONDS_IN_A_MINUTE);
}
alexey-malov commented 6 years ago
CTime const CTime::operator++(int)
{
    unsigned tempCopy = m_timeStamp;
    m_timeStamp++;
    if (m_timeStamp >= SECONDS_IN_A_DAY)
    {
        m_timeStamp = 0;
    }
    return CTime(tempCopy);
}
alexey-malov commented 6 years ago
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);
}
alexey-malov commented 6 years ago
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;
}
alexey-malov commented 6 years ago
unsigned CTime::operator/(CTime const & time) const
{
    if (time.m_timeStamp <= 0)
    {
        throw std::invalid_argument("Invalid argument");
    }
    return (m_timeStamp / time.m_timeStamp);
}
alexey-malov commented 6 years ago
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);
}
alexey-malov commented 6 years ago
alexey-malov commented 6 years ago