From 8f993127d3aaa826c11477f324a830da7ec01d78 Mon Sep 17 00:00:00 2001 From: Theodoros Katzalis <thodkatz@gmail.com> Date: Sun, 17 Mar 2019 02:21:38 +0200 Subject: [PATCH] The private functions of TimeHelper class changed to static and public functions --- inc/Helpers/TimeHelper.hpp | 38 +++++-------------------- src/Helpers/TimeHelper.cpp | 4 +-- test/Helpers/TimeHelper.cpp | 20 ++++++------- test/Services/TimeManagementService.cpp | 4 +-- 4 files changed, 21 insertions(+), 45 deletions(-) diff --git a/inc/Helpers/TimeHelper.hpp b/inc/Helpers/TimeHelper.hpp index 97a8d183..ad9c41a3 100644 --- a/inc/Helpers/TimeHelper.hpp +++ b/inc/Helpers/TimeHelper.hpp @@ -40,14 +40,16 @@ struct TimeAndDate { * */ class TimeHelper { -private: - const uint8_t DaysOfMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +public: + static constexpr uint8_t DaysOfMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + + TimeHelper() = default; /** * @param year The year that will be examined if it is a leap year(366 days) * @return if the \p year is a leap year returns true and if it isn't returns false */ - bool IsLeapYear(uint16_t year); + static bool IsLeapYear(uint16_t year); /** * Convert UTC date to elapsed seconds since Unix epoch(1/1/1970 00:00:00). @@ -62,7 +64,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); + static uint32_t mkUTCtime(struct TimeAndDate &TimeInfo); /** * Convert elapsed seconds since Unix epoch to UTC date. @@ -77,11 +79,8 @@ 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); - -public: + static struct TimeAndDate utcTime(uint32_t seconds); - TimeHelper() = default; /** * Generate the CDS time format(3.3 in CCSDS 301.0-B-4 standard). @@ -108,30 +107,7 @@ public: * @return the UTC date */ static struct 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) { - return mkUTCtime(TimeInfo); - } - - /** - * Dummy function created only to access `utcTime` for testing - * - * @todo Delete this function - */ - struct TimeAndDate get_utcTime(uint32_t seconds) { - return utcTime(seconds); - } }; -/** - * Used to access `mkUTCtime` function and `utcTime` function in the static `implementCDSTimeFormat` - * and in the static `parseCDSTimeFormat` functions - */ -static TimeHelper Access; #endif //ECSS_SERVICES_TIMEHELPER_HPP diff --git a/src/Helpers/TimeHelper.cpp b/src/Helpers/TimeHelper.cpp index 15259622..27fe1d82 100644 --- a/src/Helpers/TimeHelper.cpp +++ b/src/Helpers/TimeHelper.cpp @@ -86,7 +86,7 @@ uint64_t TimeHelper::generateCDStimeFormat(struct TimeAndDate &TimeInfo) { */ - uint32_t seconds = Access.mkUTCtime(TimeInfo); + uint32_t seconds = mkUTCtime(TimeInfo); /** * The `DAY` segment, 16 bits as defined from standard. Actually the days passed since Unix @@ -115,5 +115,5 @@ struct TimeAndDate TimeHelper::parseCDStimeFormat(const uint8_t *data) { uint32_t seconds = elapsedDays * SECONDS_PER_DAY + msOfDay / 1000; - return Access.utcTime(seconds); + return utcTime(seconds); } diff --git a/test/Helpers/TimeHelper.cpp b/test/Helpers/TimeHelper.cpp index cc124eae..7b6436aa 100644 --- a/test/Helpers/TimeHelper.cpp +++ b/test/Helpers/TimeHelper.cpp @@ -14,7 +14,7 @@ TEST_CASE("Time format implementation", "[CUC]") { TimeInfo.second = 0; TimeHelper time; - uint32_t currTime = time.get_mkUTCtime(TimeInfo); + uint32_t currTime = TimeHelper::mkUTCtime(TimeInfo); uint16_t elapsedDays = currTime / 86400; uint32_t msOfDay = currTime % 86400 * 1000; @@ -29,7 +29,7 @@ TEST_CASE("Time format implementation", "[CUC]") { TimeInfo.minute = 0; TimeInfo.second = 0; - currTime = time.get_mkUTCtime(TimeInfo); + currTime = TimeHelper::mkUTCtime(TimeInfo); elapsedDays = currTime / 86400; msOfDay = currTime % 86400 * 1000; @@ -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); + struct TimeAndDate TimeInfo = TimeHelper::utcTime(seconds); CHECK(TimeInfo.year == 2020); CHECK(TimeInfo.month == 4); CHECK(TimeInfo.day == 10); @@ -51,7 +51,7 @@ TEST_CASE("Time format implementation", "[CUC]") { seconds = 1546300800; // elapsed seconds between 1/1/2019 00:00:00 and Unix epoch - TimeInfo = time.get_utcTime(seconds); + TimeInfo = TimeHelper::utcTime(seconds); CHECK(TimeInfo.year == 2019); CHECK(TimeInfo.month == 1); CHECK(TimeInfo.day == 1); @@ -61,7 +61,7 @@ TEST_CASE("Time format implementation", "[CUC]") { seconds = 1550966400; // elapsed seconds between 24/2/2019 00:00:00 and Unix epoch - TimeInfo = time.get_utcTime(seconds); + TimeInfo = TimeHelper::utcTime(seconds); CHECK(TimeInfo.year == 2019); CHECK(TimeInfo.month == 2); CHECK(TimeInfo.day == 24); @@ -71,7 +71,7 @@ TEST_CASE("Time format implementation", "[CUC]") { seconds = 1551571200; // elapsed seconds between 3/3/2019 00:00:00 and Unix epoch - TimeInfo = time.get_utcTime(seconds); + TimeInfo = TimeHelper::utcTime(seconds); CHECK(TimeInfo.year == 2019); CHECK(TimeInfo.month == 3); CHECK(TimeInfo.day == 3); @@ -81,7 +81,7 @@ TEST_CASE("Time format implementation", "[CUC]") { seconds = 1742907370; // elapsed seconds between 25/3/2025 12:56:10 and Unix epoch - TimeInfo = time.get_utcTime(seconds); + TimeInfo = TimeHelper::utcTime(seconds); CHECK(TimeInfo.year == 2025); CHECK(TimeInfo.month == 3); CHECK(TimeInfo.day == 25); @@ -91,7 +91,7 @@ TEST_CASE("Time format implementation", "[CUC]") { seconds = 1583020800; // elapsed seconds between 1/3/2020 00:00:00 and Unix epoch - TimeInfo = time.get_utcTime(seconds); + TimeInfo = TimeHelper::utcTime(seconds); CHECK(TimeInfo.year == 2020); CHECK(TimeInfo.month == 3); CHECK(TimeInfo.day == 1); @@ -101,7 +101,7 @@ TEST_CASE("Time format implementation", "[CUC]") { seconds = 1582934400; // elapsed seconds between 2/29/2020 00:00:00 and Unix epoch - TimeInfo = time.get_utcTime(seconds); + TimeInfo = TimeHelper::utcTime(seconds); CHECK(TimeInfo.year == 2020); CHECK(TimeInfo.month == 2); CHECK(TimeInfo.day == 29); @@ -111,7 +111,7 @@ TEST_CASE("Time format implementation", "[CUC]") { seconds = 1577923200; // elapsed seconds between 2/1/2020 00:00:00 and Unix epoch - TimeInfo = time.get_utcTime(seconds); + TimeInfo = TimeHelper::utcTime(seconds); CHECK(TimeInfo.year == 2020); CHECK(TimeInfo.month == 1); CHECK(TimeInfo.day == 2); diff --git a/test/Services/TimeManagementService.cpp b/test/Services/TimeManagementService.cpp index 612c4cde..e7ba3cdf 100644 --- a/test/Services/TimeManagementService.cpp +++ b/test/Services/TimeManagementService.cpp @@ -15,7 +15,7 @@ TEST_CASE("TM[9,3]", "[service][st09]") { TimeInfo.second = 0; TimeHelper time; - uint32_t currTime = time.get_mkUTCtime(TimeInfo); + uint32_t currTime = TimeHelper::mkUTCtime(TimeInfo); uint16_t elapsedDays = currTime/86400; uint32_t msOfDay = currTime % 86400 * 1000; @@ -50,7 +50,7 @@ TEST_CASE("TM[9,3]", "[service][st09]") { TimeInfo.minute = 0; TimeInfo.second = 0; - currTime = time.get_mkUTCtime(TimeInfo); + currTime = TimeHelper::mkUTCtime(TimeInfo); elapsedDays = currTime/86400; msOfDay = currTime % 86400 * 1000; -- GitLab