I don't know if I'm really tired but this piece of code is giving me (logic?) problems while running unit tests. Does anything looks wrong in the following piece of code?
bool Date::operator <= (const Date& d) const {
if (this != &d) {
if (day > d.day)
return false;
if (hour > d.hour)
return false;
if (minute > d.minute)
return false;
if (second > d.second)
return false;
}
return true;
}
Just for testing, I replaced it with this (ugly) version and all the tests passed...
bool Date::operator <= (const Date& d) const {
if (this != &d) {
long a = (86400 * day) + (3600 * hour) + (60 * minute) + second;
long b = (86400 * d.day) + (3600 * d.hour) + (60 * d.minute) + d.second;
return a <= b;
}
return true;
}
Anyone could help? Thanks!