From 742ea082581e60cc4284c00e65064f2acdb154ba Mon Sep 17 00:00:00 2001 From: Theodoros Katzalis <thodkatz@gmail.com> Date: Fri, 15 Mar 2019 22:10:49 +0200 Subject: [PATCH] Use operator overloading instead of functions that perform date comparison --- CMakeLists.txt | 2 +- inc/Helpers/TimeAndDate.hpp | 62 +++++++ inc/Helpers/TimeHelper.hpp | 53 +----- inc/Services/TimeManagementService.hpp | 4 +- src/Helpers/TimeAndDate.cpp | 215 +++++++++++++++++++++++ src/Helpers/TimeHelper.cpp | 98 +---------- src/Services/TimeManagementService.cpp | 6 +- test/Helpers/TimeAndDate.cpp | 225 +++++++++++++++++++++++++ test/Helpers/TimeHelper.cpp | 159 +---------------- 9 files changed, 520 insertions(+), 304 deletions(-) create mode 100644 inc/Helpers/TimeAndDate.hpp create mode 100644 src/Helpers/TimeAndDate.cpp create mode 100644 test/Helpers/TimeAndDate.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d9e456e6..5912262a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ add_library(common OBJECT src/Services/RequestVerificationService.cpp src/Services/TestService.cpp src/Services/TimeManagementService.cpp - ) + src/Helpers/TimeAndDate.cpp) # Specify the .cpp files for the executables add_executable(ecss_services diff --git a/inc/Helpers/TimeAndDate.hpp b/inc/Helpers/TimeAndDate.hpp new file mode 100644 index 00000000..bd35d523 --- /dev/null +++ b/inc/Helpers/TimeAndDate.hpp @@ -0,0 +1,62 @@ +#ifndef ECSS_SERVICES_TIMEANDDATE_HPP +#define ECSS_SERVICES_TIMEANDDATE_HPP + +#include <cstdint> + +/** + * A class that represents the time and date. + * + * @notes + * This struct is similar to the `struct tm` of <ctime> library but it is more embedded-friendly + */ +class TimeAndDate { +public: + uint16_t year; + uint8_t month; + uint8_t day; + uint8_t hour; + uint8_t minute; + uint8_t second; + + /** + * Compare two timestamps. + * + * @param Date the date that will be compared with the pointer `this` + * @return true if the pointer `this` is smaller than \p Date + */ + bool operator<(const TimeAndDate &Date); + + /** + * Compare two timestamps. + * + * @param Date the date that will be compared with the pointer `this` + * @return true if the pointer `this` is greater than \p Date + */ + bool operator>(const TimeAndDate &Date); + + /** + * Compare two timestamps. + * + * @param Date the date that will be compared with the pointer `this` + * @return true if the pointer `this` is smaller than or equal to \p Date + */ + bool operator<=(const TimeAndDate &Date); + + /** + * Compare two timestamps. + * + * @param Date the date that will be compared with the pointer `this` + * @return true if the pointer `this` is greater than or equal to \p Date + */ + bool operator>=(const TimeAndDate &Date); + + /** + * Compare two timestamps. + * + * @param Date the date that will be compared with the pointer `this` + * @return true if the pointer `this` is equal to \p Date + */ + bool operator==(const TimeAndDate &Date); +}; + +#endif //ECSS_SERVICES_TIMEANDDATE_HPP diff --git a/inc/Helpers/TimeHelper.hpp b/inc/Helpers/TimeHelper.hpp index 051464b2..b9d11c9b 100644 --- a/inc/Helpers/TimeHelper.hpp +++ b/inc/Helpers/TimeHelper.hpp @@ -3,24 +3,8 @@ #include <cstdint> #include <Message.hpp> +#include "TimeAndDate.hpp" -/** - * The time and date provided from Real Time Clock(Real Time Clock). - * - * @notes - * This struct is similar to the `struct tm` of <ctime> library but it is more embedded-friendly - * - * For the current implementation this struct takes dummy values, because RTC hasn't been - * implemented - */ -struct TimeAndDate { - uint16_t year; - uint8_t month; - uint8_t day; - uint8_t hour; - uint8_t minute; - uint8_t second; -}; /** * This class formats the spacecraft time and cooperates closely with the ST[09] time management. @@ -61,7 +45,7 @@ private: * @todo check if we need to change the epoch to ,the recommended from the standard, 1 January * 1958 */ - uint32_t mkUTCtime(struct TimeAndDate &TimeInfo); + uint32_t mkUTCtime(TimeAndDate &TimeInfo); /** * Convert elapsed seconds since Unix epoch to UTC date. @@ -76,35 +60,12 @@ private: * @todo check if we need to change the epoch to ,the recommended from the standard, 1 January * 1958 */ - struct TimeAndDate utcTime(uint32_t seconds); + TimeAndDate utcTime(uint32_t seconds); public: TimeHelper() = default; - - /** - * @param Now the date provided from the Real Time Clock(UTC format) - * @param Date the date that will be compared with the \p Now - * @param equalCondition if it is true, then this function returns true when the dates - * are equal. If the \p equalCondition is false, then this function returns false when - * the dates are equal - * @return true if \p Now is greater than \p DateExamined. The equality depends on the \p - * equalCondition - */ - static bool IsAfter(struct TimeAndDate &Now, struct TimeAndDate &Date, bool equalCondition); - - /** - * @param Now the date provided from the Real Time Clock(UTC format) - * @param Date the date that will be compared with the \p Now - * @param equalCondition if it is true, then this function returns true when the dates - * are equal. If the \p equalCondition is false, then this function returns false when - * the dates are equal. - * @return true if \p Now is smaller than \p DateExamined. The equality depends on the \p - * equalCondition - */ - static bool IsBefore(struct TimeAndDate &Now, struct TimeAndDate &Date, bool equalCondition); - /** * Generate the CDS time format(3.3 in CCSDS 301.0-B-4 standard). * @@ -127,16 +88,16 @@ public: * * @param data time information provided from the ground segment. The length of the data is a * fixed size of 48 bits - * @return the UTC date + * @return the UTC date that the RTC will be synchronized */ - static struct TimeAndDate parseCDStimeFormat(const uint8_t *data); + static TimeAndDate parseCDStimeFormat(const uint8_t *data); /** * Dummy function created only to access `mkUTCtime` for testing * * @todo Delete this function */ - uint32_t get_mkUTCtime(struct TimeAndDate &TimeInfo) { + uint32_t get_mkUTCtime(TimeAndDate &TimeInfo) { return mkUTCtime(TimeInfo); } @@ -145,7 +106,7 @@ public: * * @todo Delete this function */ - struct TimeAndDate get_utcTime(uint32_t seconds) { + TimeAndDate get_utcTime(uint32_t seconds) { return utcTime(seconds); } }; diff --git a/inc/Services/TimeManagementService.hpp b/inc/Services/TimeManagementService.hpp index 6f504425..432c5125 100644 --- a/inc/Services/TimeManagementService.hpp +++ b/inc/Services/TimeManagementService.hpp @@ -48,7 +48,7 @@ public: * or should ignore the standard? */ - void cdsTimeReport(struct TimeAndDate &TimeInfo); + void cdsTimeReport(TimeAndDate &TimeInfo); /** * TC[9,128] CDS time request. @@ -61,7 +61,7 @@ public: * @param message the message that will be parsed for its time-data. The data of the \p message * should be a fixed size of 48 bits */ - struct TimeAndDate cdsTimeRequest(Message &message); + TimeAndDate cdsTimeRequest(Message &message); }; diff --git a/src/Helpers/TimeAndDate.cpp b/src/Helpers/TimeAndDate.cpp new file mode 100644 index 00000000..1d93ac5e --- /dev/null +++ b/src/Helpers/TimeAndDate.cpp @@ -0,0 +1,215 @@ +#include "Helpers/TimeHelper.hpp" + +bool TimeAndDate::operator<(const TimeAndDate &Date) { + // compare years + if (this->year < Date.year) { + return true; + } else if (this->year > Date.year) { + return false; + } + + // compare months + if (this->month < Date.month) { + return true; + } else if (this->month > Date.month) { + return false; + } + + // compare days + if (this->day < Date.day) { + return true; + } else if (this->day > Date.day) { + return false; + } + + // compare hours + if (this->hour < Date.hour) { + return true; + } else if (this->hour > Date.hour) { + return false; + } + + // compare minutes + if (this->minute < Date.minute) { + return true; + } else if (this->minute > Date.minute) { + return false; + } + + // compare seconds + if (this->second < Date.second) { + return true; + } else { + return false; + } +} + +bool TimeAndDate::operator>(const TimeAndDate &Date) { + // compare years + if (this->year > Date.year) { + return true; + } else if (this->year < Date.year) { + return false; + } + + // compare months + if (this->month > Date.month) { + return true; + } else if (this->month < Date.month) { + return false; + } + + // compare days + if (this->day > Date.day) { + return true; + } else if (this->day < Date.day) { + return false; + } + + // compare hours + if (this->hour > Date.hour) { + return true; + } else if (this->hour < Date.hour) { + return false; + } + + // compare minutes + if (this->minute > Date.minute) { + return true; + } else if (this->minute < Date.minute) { + return false; + } + + // compare seconds + if (this->second > Date.second) { + return true; + } else { + return false; + } +} + +bool TimeAndDate::operator<=(const TimeAndDate &Date) { + // compare years + if (this->year < Date.year) { + return true; + } else if (this->year > Date.year) { + return false; + } + + // compare months + if (this->month < Date.month) { + return true; + } else if (this->month > Date.month) { + return false; + } + + // compare days + if (this->day < Date.day) { + return true; + } else if (this->day > Date.day) { + return false; + } + + // compare hours + if (this->hour < Date.hour) { + return true; + } else if (this->hour > Date.hour) { + return false; + } + + // compare minutes + if (this->minute < Date.minute) { + return true; + } else if (this->minute > Date.minute) { + return false; + } + + // compare seconds + if (this->second < Date.second) { + return true; + } else if (this->second > Date.second) { + return false; + } else { + return true; + } +} + +bool TimeAndDate::operator>=(const TimeAndDate &Date) { + // compare years + if (this->year > Date.year) { + return true; + } else if (this->year < Date.year) { + return false; + } + + // compare months + if (this->month > Date.month) { + return true; + } else if (this->month < Date.month) { + return false; + } + + // compare days + if (this->day > Date.day) { + return true; + } else if (this->day < Date.day) { + return false; + } + + // compare hours + if (this->hour > Date.hour) { + return true; + } else if (this->hour < Date.hour) { + return false; + } + + // compare minutes + if (this->minute > Date.minute) { + return true; + } else if (this->minute < Date.minute) { + return false; + } + + // compare seconds + if (this->second > Date.second) { + return true; + } else if (this->second < Date.second) { + return false; + } else { + return true; + } +} + +bool TimeAndDate::operator==(const TimeAndDate &Date) { + // compare years + if (this->year != Date.year) { + return false; + } + + // compare months + if (this->month != Date.month) { + return false; + } + + // compare days + if (this->day != Date.day) { + return false; + } + + // compare hours + if (this->hour != Date.hour) { + return false; + } + + // compare minutes + if (this->minute != Date.minute) { + return false; + } + + // compare seconds + if (this->second != Date.second) { + return false; + } else { + return true; + } +} \ No newline at end of file diff --git a/src/Helpers/TimeHelper.cpp b/src/Helpers/TimeHelper.cpp index 6bf5fef9..a5681059 100644 --- a/src/Helpers/TimeHelper.cpp +++ b/src/Helpers/TimeHelper.cpp @@ -10,7 +10,7 @@ bool TimeHelper::IsLeapYear(uint16_t year) { return (year % 400) == 0; } -uint32_t TimeHelper::mkUTCtime(struct TimeAndDate &TimeInfo) { +uint32_t TimeHelper::mkUTCtime(TimeAndDate &TimeInfo) { uint32_t secs = 1546300800; // elapsed seconds from Unix epoch until 1/1/2019 00:00:00(UTC date) for (uint16_t y = 2019; y < TimeInfo.year; ++y) { secs += (IsLeapYear(y) ? 366 : 365) * SecondsPerDay; @@ -79,99 +79,7 @@ struct TimeAndDate TimeHelper::utcTime(uint32_t seconds) { return TimeInfo; } -bool TimeHelper::IsAfter(struct TimeAndDate &Now, struct TimeAndDate &Date, bool -equalCondition) { - // compare years - if (Now.year < Date.year) { - return true; - } else if (Now.year > Date.year) { - return false; - } - - // compare months - if (Now.month < Date.month) { - return true; - } else if (Now.month > Date.month) { - return false; - } - - // compare days - if (Now.day < Date.day) { - return true; - } else if (Now.day > Date.day) { - return false; - } - - // compare hours - if (Now.hour < Date.hour) { - return true; - } else if (Now.hour > Date.hour) { - return false; - } - - // compare minutes - if (Now.minute < Date.minute) { - return true; - } else if (Now.minute > Date.minute) { - return false; - } - - // compare seconds - if (Now.second < Date.second) { - return true; - } else if (Now.second > Date.second) { - return false; - } else if (Now.second == Date.second) - return equalCondition; -} - -bool TimeHelper::IsBefore(struct TimeAndDate &Now, struct TimeAndDate &Date, bool -equalCondition) { - // compare years - if (Now.year > Date.year) { - return true; - } else if (Now.year < Date.year) { - return false; - } - - // compare months - if (Now.month > Date.month) { - return true; - } else if (Now.month < Date.month) { - return false; - } - - // compare days - if (Now.day > Date.day) { - return true; - } else if (Now.day < Date.day) { - return false; - } - - // compare hours - if (Now.hour > Date.hour) { - return true; - } else if (Now.hour < Date.hour) { - return false; - } - - // compare minutes - if (Now.minute > Date.minute) { - return true; - } else if (Now.minute < Date.minute) { - return false; - } - - // compare seconds - if (Now.second > Date.second) { - return true; - } else if (Now.second < Date.second) { - return false; - } else if (Now.second == Date.second) - return equalCondition; -} - -uint64_t TimeHelper::generateCDStimeFormat(struct TimeAndDate &TimeInfo) { +uint64_t TimeHelper::generateCDStimeFormat(TimeAndDate &TimeInfo) { /** * Define the T-field. The total number of octets for the implementation of T-field is 6(2 for * the `DAY` and 4 for the `ms of day` @@ -197,7 +105,7 @@ uint64_t TimeHelper::generateCDStimeFormat(struct TimeAndDate &TimeInfo) { return timeFormat; } -struct TimeAndDate TimeHelper::parseCDStimeFormat(const uint8_t *data) { +TimeAndDate TimeHelper::parseCDStimeFormat(const uint8_t *data) { uint16_t elapsedDays = (static_cast<uint16_t >(data[0])) << 8 | static_cast<uint16_t > (data[1]); uint32_t msOfDay = (static_cast<uint32_t >(data[2])) << 24 | diff --git a/src/Services/TimeManagementService.cpp b/src/Services/TimeManagementService.cpp index 33301a70..e54fcdeb 100644 --- a/src/Services/TimeManagementService.cpp +++ b/src/Services/TimeManagementService.cpp @@ -1,6 +1,6 @@ #include "Services/TimeManagementService.hpp" -void TimeManagementService::cdsTimeReport(struct TimeAndDate &TimeInfo) { +void TimeManagementService::cdsTimeReport(TimeAndDate &TimeInfo) { // TM[9,3] CDS time report Message timeReport = createTM(3); @@ -13,14 +13,14 @@ void TimeManagementService::cdsTimeReport(struct TimeAndDate &TimeInfo) { storeMessage(timeReport); } -struct TimeAndDate TimeManagementService::cdsTimeRequest(Message &message) { +TimeAndDate TimeManagementService::cdsTimeRequest(Message &message) { // TC{9,128] CDS time request // check if we have the correct size of the data. The size should be 6(48 bits) ErrorHandler::assertRequest(message.dataSize == 6, message, ErrorHandler::AcceptanceErrorType::UnacceptableMessage); - struct TimeAndDate timeInfo = TimeHelper::parseCDStimeFormat(message.data); + TimeAndDate timeInfo = TimeHelper::parseCDStimeFormat(message.data); return timeInfo; } diff --git a/test/Helpers/TimeAndDate.cpp b/test/Helpers/TimeAndDate.cpp new file mode 100644 index 00000000..3c6a3f2f --- /dev/null +++ b/test/Helpers/TimeAndDate.cpp @@ -0,0 +1,225 @@ +#include "catch2/catch.hpp" +#include "Helpers/TimeAndDate.hpp" + + +TEST_CASE("Date comparison", "[operands]") { + + SECTION("Different year") { + TimeAndDate Now = {0}; + // 10/04/2021 10:15:00 + Now.year = 2021; + Now.month = 4; + Now.day = 10; + Now.hour = 10; + Now.minute = 15; + Now.second = 0; + + TimeAndDate Date = {0}; + // 10/04/2020 10:15:00 + Date.year = 2020; + Date.month = 4; + Date.day = 10; + Date.hour = 10; + Date.minute = 15; + Date.second = 0; + + CHECK((Now < Date) == false); + CHECK((Now > Date) == true); + CHECK((Now > Date) == true); + CHECK((Now < Date) == false); + + CHECK((Now <= Date) == false); + CHECK((Now >= Date) == true); + CHECK((Now >= Date) == true); + CHECK((Now <= Date) == false); + + CHECK((Now == Date) == false); + } + + SECTION("Different month") { + + TimeAndDate Now = {0}; + // 10/05/2020 10:15:00 + Now.year = 2020; + Now.month = 5; + Now.day = 10; + Now.hour = 10; + Now.minute = 15; + Now.second = 0; + + TimeAndDate Date = {0}; + // 10/04/2020 10:15:00 + Date.year = 2020; + Date.month = 4; + Date.day = 10; + Date.hour = 10; + Date.minute = 15; + Date.second = 0; + + CHECK((Now < Date) == false); + CHECK((Now > Date) == true); + CHECK((Now > Date) == true); + CHECK((Now < Date) == false); + + CHECK((Now <= Date) == false); + CHECK((Now >= Date) == true); + CHECK((Now >= Date) == true); + CHECK((Now <= Date) == false); + + CHECK((Now == Date) == false); + } + + SECTION("Different day") { + TimeAndDate Now = {0}; + // 11/04/2020 10:15:00 + Now.year = 2020; + Now.month = 5; + Now.day = 11; + Now.hour = 10; + Now.minute = 15; + Now.second = 0; + + TimeAndDate Date = {0}; + // 10/04/2020 10:15:00 + Date.year = 2020; + Date.month = 4; + Date.day = 10; + Date.hour = 10; + Date.minute = 15; + Date.second = 0; + + CHECK((Now < Date) == false); + CHECK((Now > Date) == true); + CHECK((Now > Date) == true); + CHECK((Now < Date) == false); + + CHECK((Now <= Date) == false); + CHECK((Now >= Date) == true); + CHECK((Now >= Date) == true); + CHECK((Now <= Date) == false); + + CHECK((Now == Date) == false); + } + + SECTION("Different hour") { + TimeAndDate Now = {0}; + // 10/04/2020 11:15:00 + Now.year = 2020; + Now.month = 4; + Now.day = 10; + Now.hour = 11; + Now.minute = 15; + Now.second = 0; + + TimeAndDate Date = {0}; + // 10/04/2020 10:15:00 + Date.year = 2020; + Date.month = 4; + Date.day = 10; + Date.hour = 10; + Date.minute = 15; + Date.second = 0; + + CHECK((Now < Date) == false); + CHECK((Now > Date) == true); + CHECK((Now > Date) == true); + CHECK((Now < Date) == false); + + CHECK((Now <= Date) == false); + CHECK((Now >= Date) == true); + CHECK((Now >= Date) == true); + CHECK((Now <= Date) == false); + + CHECK((Now == Date) == false); + } + + SECTION("Different minute") { + TimeAndDate Now = {0}; + // 10/04/2020 10:16:00 + Now.year = 2020; + Now.month = 4; + Now.day = 10; + Now.hour = 10; + Now.minute = 16; + Now.second = 0; + + TimeAndDate Date = {0}; + // 10/04/2020 10:15:00 + Date.year = 2020; + Date.month = 4; + Date.day = 10; + Date.hour = 10; + Date.minute = 15; + Date.second = 0; + + CHECK((Now < Date) == false); + CHECK((Now > Date) == true); + CHECK((Now > Date) == true); + CHECK((Now < Date) == false); + + CHECK((Now <= Date) == false); + CHECK((Now >= Date) == true); + CHECK((Now >= Date) == true); + CHECK((Now <= Date) == false); + + CHECK((Now == Date) == false); + } + + SECTION("Different second") { + TimeAndDate Now = {0}; + // 10/04/2020 10:15:01 + Now.year = 2020; + Now.month = 4; + Now.day = 10; + Now.hour = 10; + Now.minute = 15; + Now.second = 1; + + TimeAndDate Date = {0}; + // 10/04/2020 10:15:00 + Date.year = 2020; + Date.month = 4; + Date.day = 10; + Date.hour = 10; + Date.minute = 15; + Date.second = 0; + + CHECK((Now < Date) == false); + CHECK((Now > Date) == true); + CHECK((Now > Date) == true); + CHECK((Now < Date) == false); + + CHECK((Now <= Date) == false); + CHECK((Now >= Date) == true); + CHECK((Now >= Date) == true); + CHECK((Now <= Date) == false); + + CHECK((Now == Date) == false); + } + + SECTION("Same date"){ + TimeAndDate Now = {0}; + // 10/04/2020 10:15:01 + Now.year = 2020; + Now.month = 4; + Now.day = 10; + Now.hour = 10; + Now.minute = 15; + Now.second = 0; + + TimeAndDate Date = {0}; + // 10/04/2020 10:15:00 + Date.year = 2020; + Date.month = 4; + Date.day = 10; + Date.hour = 10; + Date.minute = 15; + Date.second = 0; + + CHECK((Now == Date) == true); + CHECK((Now <= Date) == true); + CHECK((Now >= Date) == true); + CHECK((Now >= Date) == true); + CHECK((Now <= Date) == true); + } +} diff --git a/test/Helpers/TimeHelper.cpp b/test/Helpers/TimeHelper.cpp index 0d733167..700c43d9 100644 --- a/test/Helpers/TimeHelper.cpp +++ b/test/Helpers/TimeHelper.cpp @@ -4,7 +4,7 @@ TEST_CASE("Time format implementation", "[CUC]") { SECTION("Convert UTC date to elapsed seconds since Unix epoch") { - struct TimeAndDate TimeInfo = {0}; + TimeAndDate TimeInfo = {0}; // 10/04/2020 10:15:00 TimeInfo.year = 2020; TimeInfo.month = 4; @@ -41,7 +41,7 @@ TEST_CASE("Time format implementation", "[CUC]") { uint32_t seconds = 1586513700; // elapsed seconds between 10/04/2020 10:15:00 and Unix epoch TimeHelper time; - struct TimeAndDate TimeInfo = time.get_utcTime(seconds); + TimeAndDate TimeInfo = time.get_utcTime(seconds); CHECK(TimeInfo.year == 2020); CHECK(TimeInfo.month == 4); CHECK(TimeInfo.day == 10); @@ -118,160 +118,5 @@ TEST_CASE("Time format implementation", "[CUC]") { CHECK(TimeInfo.hour == 0); CHECK(TimeInfo.minute == 0); CHECK(TimeInfo.second == 0); - - } - - SECTION("Date comparison") { - SECTION("Different year") { - struct TimeAndDate Now = {0}; - // 10/04/2021 10:15:00 - Now.year = 2021; - Now.month = 4; - Now.day = 10; - Now.hour = 10; - Now.minute = 15; - Now.second = 0; - - struct TimeAndDate Date = {0}; - // 10/04/2020 10:15:00 - Date.year = 2020; - Date.month = 4; - Date.day = 10; - Date.hour = 10; - Date.minute = 15; - Date.second = 0; - - CHECK(TimeHelper::IsAfter(Now, Date, true) == false); - CHECK(TimeHelper::IsAfter(Date, Now, true) == true); - CHECK(TimeHelper::IsBefore(Now, Date, true) == true); - CHECK(TimeHelper::IsBefore(Date, Now, true) == false); - } - - SECTION("Different month") { - - struct TimeAndDate Now = {0}; - // 10/05/2020 10:15:00 - Now.year = 2020; - Now.month = 5; - Now.day = 10; - Now.hour = 10; - Now.minute = 15; - Now.second = 0; - - struct TimeAndDate Date = {0}; - // 10/04/2020 10:15:00 - Date.year = 2020; - Date.month = 4; - Date.day = 10; - Date.hour = 10; - Date.minute = 15; - Date.second = 0; - - CHECK(TimeHelper::IsAfter(Now, Date, true) == false); - CHECK(TimeHelper::IsAfter(Date, Now, true) == true); - CHECK(TimeHelper::IsBefore(Now, Date, true) == true); - CHECK(TimeHelper::IsBefore(Date, Now, true) == false); - } - - SECTION("Different day") { - struct TimeAndDate Now = {0}; - // 11/04/2020 10:15:00 - Now.year = 2020; - Now.month = 5; - Now.day = 11; - Now.hour = 10; - Now.minute = 15; - Now.second = 0; - - struct TimeAndDate Date = {0}; - // 10/04/2020 10:15:00 - Date.year = 2020; - Date.month = 4; - Date.day = 10; - Date.hour = 10; - Date.minute = 15; - Date.second = 0; - - CHECK(TimeHelper::IsAfter(Now, Date, true) == false); - CHECK(TimeHelper::IsAfter(Date, Now, true) == true); - CHECK(TimeHelper::IsBefore(Now, Date, true) == true); - CHECK(TimeHelper::IsBefore(Date, Now, true) == false); - } - - SECTION("Different hour") { - struct TimeAndDate Now = {0}; - // 10/04/2020 11:15:00 - Now.year = 2020; - Now.month = 4; - Now.day = 10; - Now.hour = 11; - Now.minute = 15; - Now.second = 0; - - struct TimeAndDate Date = {0}; - // 10/04/2020 10:15:00 - Date.year = 2020; - Date.month = 4; - Date.day = 10; - Date.hour = 10; - Date.minute = 15; - Date.second = 0; - - CHECK(TimeHelper::IsAfter(Now, Date, true) == false); - CHECK(TimeHelper::IsAfter(Date, Now, true) == true); - CHECK(TimeHelper::IsBefore(Now, Date, true) == true); - CHECK(TimeHelper::IsBefore(Date, Now, true) == false); - } - - SECTION("Different minute") { - struct TimeAndDate Now = {0}; - // 11/04/2020 10:16:00 - Now.year = 2020; - Now.month = 4; - Now.day = 10; - Now.hour = 10; - Now.minute = 16; - Now.second = 0; - - struct TimeAndDate Date = {0}; - // 10/04/2020 10:15:00 - Date.year = 2020; - Date.month = 4; - Date.day = 10; - Date.hour = 10; - Date.minute = 15; - Date.second = 0; - - CHECK(TimeHelper::IsAfter(Now, Date, true) == false); - CHECK(TimeHelper::IsAfter(Date, Now, true) == true); - CHECK(TimeHelper::IsBefore(Now, Date, true) == true); - CHECK(TimeHelper::IsBefore(Date, Now, true) == false); - } - - SECTION("Different second") { - struct TimeAndDate Now = {0}; - // 11/04/2020 10:15:01 - Now.year = 2020; - Now.month = 4; - Now.day = 10; - Now.hour = 10; - Now.minute = 15; - Now.second = 1; - - struct TimeAndDate Date = {0}; - // 10/04/2020 10:15:00 - Date.year = 2020; - Date.month = 4; - Date.day = 10; - Date.hour = 10; - Date.minute = 15; - Date.second = 0; - - CHECK(TimeHelper::IsAfter(Now, Date, true) == false); - CHECK(TimeHelper::IsAfter(Date, Now, true) == true); - CHECK(TimeHelper::IsBefore(Now, Date, true) == true); - CHECK(TimeHelper::IsBefore(Date, Now, true) == false); - } } - } -- GitLab