For I project I'm working on I have a struct for a timestamp that contains multiple time values like seconds, minutes, hours etc.
I wanted to make a < operator and came up with the following monstrosity:
bool operator< (const RTCTime& lhs, const RTCTime& rhs) {
if (lhs.getYear() > rhs.getYear()) return false;
else if (lhs.getYear() == rhs.getYear()) {
if (lhs.getMonth() > rhs.getMonth()) return false;
else if (lhs.getMonth() == rhs.getMonth()) {
if (lhs.getDayOfTheMonth() > rhs.getDayOfTheMonth()) return false;
else if (lhs.getDayOfTheMonth() == rhs.getDayOfTheMonth()) {
if (lhs.getHours() > rhs.getHours()) return false;
else if (lhs.getHours() == rhs.getHours()) {
if (lhs.getMinutes() > rhs.getMinutes()) return fals;
else if (lhs.getMinutes() > rhs.getMinutes()) {
if (lhs.getSeconds() > rhs.getSeconds()) return false;
}
}
}
}
}
return true;
}
I feel like it could be much simpler, but I have not idea how.