diff --git a/src/Helpers/TimeAndDate.cpp b/src/Helpers/TimeAndDate.cpp index d5cd9a2ca7b495bdc808a78e432f55c7b2ce32d2..2fbf5b85d50256110cd8cb0600d12b4561d0e86a 100644 --- a/src/Helpers/TimeAndDate.cpp +++ b/src/Helpers/TimeAndDate.cpp @@ -13,6 +13,16 @@ TimeAndDate::TimeAndDate() { TimeAndDate::TimeAndDate(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) { + // check if the parameters makes sense + + // @todo change the condition of the assertion for the \p year + assertI(2019 <= year < 2025, ErrorHandler::InternalErrorType::UnknownInternalError); + assertI(1 <= month <= 12, ErrorHandler::InternalErrorType::UnknownInternalError); + assertI(1 <= day <= 31, ErrorHandler::InternalErrorType::UnknownInternalError); + assertI(0 <= hour <= 24, ErrorHandler::InternalErrorType::UnknownInternalError); + assertI(0 <= minute <= 60, ErrorHandler::InternalErrorType::UnknownInternalError); + assertI(0 <= second <= 60, ErrorHandler::InternalErrorType::UnknownInternalError); + this->year = year; this->month = month; this->hour = hour; @@ -119,110 +129,6 @@ bool TimeAndDate::operator>(const TimeAndDate &Date) { return false; } -bool TimeAndDate::operator<=(const TimeAndDate &Date) { - // compare years - if (this->year < Date.year) { - return true; - } - if (this->year > Date.year) { - return false; - } - - // compare months - if (this->month < Date.month) { - return true; - } - if (this->month > Date.month) { - return false; - } - - // compare days - if (this->day < Date.day) { - return true; - } - if (this->day > Date.day) { - return false; - } - - // compare hours - if (this->hour < Date.hour) { - return true; - } - if (this->hour > Date.hour) { - return false; - } - - // compare minutes - if (this->minute < Date.minute) { - return true; - } - if (this->minute > Date.minute) { - return false; - } - - // compare seconds - if (this->second < Date.second) { - return true; - } - if (this->second > Date.second) { - return false; - } - - return true; -} - -bool TimeAndDate::operator>=(const TimeAndDate &Date) { - // compare years - if (this->year > Date.year) { - return true; - } - if (this->year < Date.year) { - return false; - } - - // compare months - if (this->month > Date.month) { - return true; - } - if (this->month < Date.month) { - return false; - } - - // compare days - if (this->day > Date.day) { - return true; - } - if (this->day < Date.day) { - return false; - } - - // compare hours - if (this->hour > Date.hour) { - return true; - } - if (this->hour < Date.hour) { - return false; - } - - // compare minutes - if (this->minute > Date.minute) { - return true; - } - if (this->minute < Date.minute) { - return false; - } - - // compare seconds - if (this->second > Date.second) { - return true; - } - if (this->second < Date.second) { - return false; - } - - return true; -} - bool TimeAndDate::operator==(const TimeAndDate &Date) { // compare years if (this->year != Date.year) { @@ -256,3 +162,13 @@ bool TimeAndDate::operator==(const TimeAndDate &Date) { return true; } + + +bool TimeAndDate::operator<=(const TimeAndDate &Date) { + return (*this < Date || *this == Date); +} + +bool TimeAndDate::operator>=(const TimeAndDate &Date) { + return (*this > Date || *this == Date); +} +