Поясните пожалуйста код С++ class Time {
public:
Time()
: m_hours(0), m_minutes(0) {
//TODO
}
Time(short hours, short minutes)
: m_hours(hours), m_minutes(minutes) {
//TODO
}
Time operator-(const Time& time) {
Time tempTime;
tempTime.m_minutes = this->m_minutes - time.m_minutes;
if (tempTime.m_minutes < 0) {
tempTime.m_minutes += 60;
}
tempTime.m_hours = this->m_hours - time.m_hours;
if (tempTime.m_hours < 0) {
tempTime.m_hours += 23;
}
return tempTime;
}
friend std::ostream& operator<<(std::ostream& os, const Time& time);
friend std::istream& operator>>(std::istream& is, Time& time);
short m_hours;
short m_minutes;
};
std::ostream& operator<<(std::ostream& os, const Time& time) {
if (time.m_hours < 10) {
os<< "0";
}
os<< time.m_hours << ":";
if (time.m_minutes < 10) {
os<< "0";
}
os << time.m_minutes;
return os;
}
std::istream& operator>>(std::istream& is, Time& time) {
char delim{ ':' };
is >> time.m_hours >> delim >> time.m_minutes;
if (time.m_hours > 23) {
time.m_hours %= 24;
}
if (time.m_minutes > 59) {
time.m_minutes %= 60;
}