diff --git a/inc/Helpers/TimeAndDate.hpp b/inc/Helpers/TimeAndDate.hpp index b40913dfa323227af22d338252d0398c9778ded4..8747aa3d7e004506353e4d8c3041cbb0a66cbc2f 100644 --- a/inc/Helpers/TimeAndDate.hpp +++ b/inc/Helpers/TimeAndDate.hpp @@ -18,6 +18,11 @@ public: uint8_t minute; uint8_t second; + TimeAndDate(); + + TimeAndDate(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t + second); + /** * Compare two timestamps. * diff --git a/src/Helpers/TimeAndDate.cpp b/src/Helpers/TimeAndDate.cpp index 171f7a561a0136438416c8b873b9156ddad746c0..d5cd9a2ca7b495bdc808a78e432f55c7b2ce32d2 100644 --- a/src/Helpers/TimeAndDate.cpp +++ b/src/Helpers/TimeAndDate.cpp @@ -1,5 +1,26 @@ #include "Helpers/TimeHelper.hpp" + +TimeAndDate::TimeAndDate() { + // Unix epoch 1/1/1970 + year = 1970; + month = 1; + day = 1; + hour = 0; + minute = 0; + second = 0; +} + +TimeAndDate::TimeAndDate(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, + uint8_t second) { + this->year = year; + this->month = month; + this->hour = hour; + this->day = day; + this->minute = minute; + this->second = second; +} + bool TimeAndDate::operator<(const TimeAndDate &Date) { // compare years if (this->year < Date.year) { diff --git a/src/Helpers/TimeHelper.cpp b/src/Helpers/TimeHelper.cpp index a5681059f177eb6ae51221440ee16e444e105ec9..22fb1edf9a3683ab8f17fc36754190900decd728 100644 --- a/src/Helpers/TimeHelper.cpp +++ b/src/Helpers/TimeHelper.cpp @@ -30,7 +30,7 @@ uint32_t TimeHelper::mkUTCtime(TimeAndDate &TimeInfo) { struct TimeAndDate TimeHelper::utcTime(uint32_t seconds) { seconds -= 1546300800; // elapsed seconds from Unix epoch until 1/1/2019 00:00:00(UTC date) - struct TimeAndDate TimeInfo = {0}; + TimeAndDate TimeInfo; TimeInfo.year = 2019; TimeInfo.month = 1; TimeInfo.day = 0; diff --git a/src/main.cpp b/src/main.cpp index 7f49b9d59dd818882c6b570e3d8681fc90a6afd0..a35ab891973152f905737268a50ccb448fa21eb4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -174,7 +174,7 @@ int main() { // ST[09] test TimeManagementService timeReport; - struct TimeAndDate timeInfo = {0}; + TimeAndDate timeInfo; // 10/04/1998 10:15:00 timeInfo.year = 1998; timeInfo.month = 4; diff --git a/test/Helpers/TimeAndDate.cpp b/test/Helpers/TimeAndDate.cpp index 3c6a3f2f911e7a1b8072f234fdb8993b7684065e..28532ca88c34f652e9ad428bb98ccc939ecb321f 100644 --- a/test/Helpers/TimeAndDate.cpp +++ b/test/Helpers/TimeAndDate.cpp @@ -5,7 +5,7 @@ TEST_CASE("Date comparison", "[operands]") { SECTION("Different year") { - TimeAndDate Now = {0}; + TimeAndDate Now; // 10/04/2021 10:15:00 Now.year = 2021; Now.month = 4; @@ -14,7 +14,7 @@ TEST_CASE("Date comparison", "[operands]") { Now.minute = 15; Now.second = 0; - TimeAndDate Date = {0}; + TimeAndDate Date; // 10/04/2020 10:15:00 Date.year = 2020; Date.month = 4; @@ -38,7 +38,7 @@ TEST_CASE("Date comparison", "[operands]") { SECTION("Different month") { - TimeAndDate Now = {0}; + TimeAndDate Now; // 10/05/2020 10:15:00 Now.year = 2020; Now.month = 5; @@ -47,7 +47,7 @@ TEST_CASE("Date comparison", "[operands]") { Now.minute = 15; Now.second = 0; - TimeAndDate Date = {0}; + TimeAndDate Date; // 10/04/2020 10:15:00 Date.year = 2020; Date.month = 4; @@ -70,7 +70,7 @@ TEST_CASE("Date comparison", "[operands]") { } SECTION("Different day") { - TimeAndDate Now = {0}; + TimeAndDate Now; // 11/04/2020 10:15:00 Now.year = 2020; Now.month = 5; @@ -79,7 +79,7 @@ TEST_CASE("Date comparison", "[operands]") { Now.minute = 15; Now.second = 0; - TimeAndDate Date = {0}; + TimeAndDate Date; // 10/04/2020 10:15:00 Date.year = 2020; Date.month = 4; @@ -102,7 +102,7 @@ TEST_CASE("Date comparison", "[operands]") { } SECTION("Different hour") { - TimeAndDate Now = {0}; + TimeAndDate Now; // 10/04/2020 11:15:00 Now.year = 2020; Now.month = 4; @@ -111,7 +111,7 @@ TEST_CASE("Date comparison", "[operands]") { Now.minute = 15; Now.second = 0; - TimeAndDate Date = {0}; + TimeAndDate Date; // 10/04/2020 10:15:00 Date.year = 2020; Date.month = 4; @@ -134,7 +134,7 @@ TEST_CASE("Date comparison", "[operands]") { } SECTION("Different minute") { - TimeAndDate Now = {0}; + TimeAndDate Now; // 10/04/2020 10:16:00 Now.year = 2020; Now.month = 4; @@ -143,7 +143,7 @@ TEST_CASE("Date comparison", "[operands]") { Now.minute = 16; Now.second = 0; - TimeAndDate Date = {0}; + TimeAndDate Date; // 10/04/2020 10:15:00 Date.year = 2020; Date.month = 4; @@ -166,7 +166,7 @@ TEST_CASE("Date comparison", "[operands]") { } SECTION("Different second") { - TimeAndDate Now = {0}; + TimeAndDate Now; // 10/04/2020 10:15:01 Now.year = 2020; Now.month = 4; @@ -175,7 +175,7 @@ TEST_CASE("Date comparison", "[operands]") { Now.minute = 15; Now.second = 1; - TimeAndDate Date = {0}; + TimeAndDate Date; // 10/04/2020 10:15:00 Date.year = 2020; Date.month = 4; @@ -198,7 +198,7 @@ TEST_CASE("Date comparison", "[operands]") { } SECTION("Same date"){ - TimeAndDate Now = {0}; + TimeAndDate Now; // 10/04/2020 10:15:01 Now.year = 2020; Now.month = 4; @@ -207,7 +207,7 @@ TEST_CASE("Date comparison", "[operands]") { Now.minute = 15; Now.second = 0; - TimeAndDate Date = {0}; + TimeAndDate Date; // 10/04/2020 10:15:00 Date.year = 2020; Date.month = 4; diff --git a/test/Helpers/TimeHelper.cpp b/test/Helpers/TimeHelper.cpp index 700c43d947b848380254b5ef4a80dd7bf44d08fb..c5a58e33573276a233f43ca991cbe1fad169c18d 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") { - TimeAndDate TimeInfo = {0}; + TimeAndDate TimeInfo; // 10/04/2020 10:15:00 TimeInfo.year = 2020; TimeInfo.month = 4; diff --git a/test/Services/TimeManagementService.cpp b/test/Services/TimeManagementService.cpp index 612c4cdeaaa5171d2ea0f45cdb9f6d4aab9309fe..f23882061f741ba93df2f749f1df1e87b1cee057 100644 --- a/test/Services/TimeManagementService.cpp +++ b/test/Services/TimeManagementService.cpp @@ -5,7 +5,7 @@ TEST_CASE("TM[9,3]", "[service][st09]") { TimeManagementService timeService; - struct TimeAndDate TimeInfo = {0}; + TimeAndDate TimeInfo; // 10/04/2020 10:15:00 TimeInfo.year = 2020; TimeInfo.month = 4;