From b58b3b5ebaee80d945a368a6923274e898cb7d22 Mon Sep 17 00:00:00 2001 From: Theodoros Katzalis <thodkatz@gmail.com> Date: Mon, 18 Mar 2019 17:25:35 +0200 Subject: [PATCH] Change the names of some functions to improve the readability --- inc/Helpers/TimeHelper.hpp | 5 ++-- src/Helpers/TimeHelper.cpp | 8 ++--- test/Helpers/TimeHelper.cpp | 40 ++++++++++++------------- test/Services/TimeManagementService.cpp | 4 +-- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/inc/Helpers/TimeHelper.hpp b/inc/Helpers/TimeHelper.hpp index d7aead95..71147856 100644 --- a/inc/Helpers/TimeHelper.hpp +++ b/inc/Helpers/TimeHelper.hpp @@ -68,7 +68,7 @@ public: * @todo check if we need to change the epoch to the recommended one from the standard, 1 * January 1958 */ - static uint32_t mkUTCtime(struct TimeAndDate &TimeInfo); + static uint32_t utcToSeconds(struct TimeAndDate &TimeInfo); /** * Convert elapsed seconds since Unix epoch to UTC date. @@ -83,8 +83,7 @@ public: * @todo check if we need to change the epoch to the recommended one from the standard, 1 * January 1958 */ - static struct TimeAndDate utcTime(uint32_t seconds); - + static struct TimeAndDate secondsToUTC(uint32_t seconds); /** * Generate the CDS time format (3.3 in CCSDS 301.0-B-4 standard). diff --git a/src/Helpers/TimeHelper.cpp b/src/Helpers/TimeHelper.cpp index 19314ae6..2ce9562b 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::utcToSeconds(struct TimeAndDate &TimeInfo) { // the date, that \p TimeInfo represents, should be greater than or equal to 1/1/2019 and the // date should be valid according to Gregorian calendar assertI(TimeInfo.year >= 2019, ErrorHandler::InternalErrorType::InvalidDate); @@ -42,7 +42,7 @@ uint32_t TimeHelper::mkUTCtime(struct TimeAndDate &TimeInfo) { return secs; } -struct TimeAndDate TimeHelper::utcTime(uint32_t seconds) { +struct TimeAndDate TimeHelper::secondsToUTC(uint32_t seconds) { // elapsed seconds should be between dates, that are after 1/1/2019 and Unix epoch assertI(seconds >= 1546300800, ErrorHandler::InternalErrorType::InvalidDate); @@ -103,7 +103,7 @@ uint64_t TimeHelper::generateCDStimeFormat(struct TimeAndDate &TimeInfo) { */ - uint32_t seconds = mkUTCtime(TimeInfo); + uint32_t seconds = utcToSeconds(TimeInfo); /** * The `DAY` segment, 16 bits as defined from standard. Actually the days passed since Unix @@ -132,5 +132,5 @@ struct TimeAndDate TimeHelper::parseCDStimeFormat(const uint8_t *data) { uint32_t seconds = elapsedDays * SECONDS_PER_DAY + msOfDay / 1000; - return utcTime(seconds); + return secondsToUTC(seconds); } diff --git a/test/Helpers/TimeHelper.cpp b/test/Helpers/TimeHelper.cpp index 81fe712f..c0c530d5 100644 --- a/test/Helpers/TimeHelper.cpp +++ b/test/Helpers/TimeHelper.cpp @@ -15,7 +15,7 @@ TEST_CASE("Time format implementation", "[CUC]") { TimeInfo.second = 0; TimeHelper time; - TimeHelper::mkUTCtime(TimeInfo); + TimeHelper::utcToSeconds(TimeInfo); // invalid month TimeInfo.year = 2018; @@ -25,7 +25,7 @@ TEST_CASE("Time format implementation", "[CUC]") { TimeInfo.minute = 15; TimeInfo.second = 0; - TimeHelper::mkUTCtime(TimeInfo); + TimeHelper::utcToSeconds(TimeInfo); // invalid day TimeInfo.year = 2018; @@ -35,7 +35,7 @@ TEST_CASE("Time format implementation", "[CUC]") { TimeInfo.minute = 15; TimeInfo.second = 0; - TimeHelper::mkUTCtime(TimeInfo); + TimeHelper::utcToSeconds(TimeInfo); // invalid hour TimeInfo.year = 2018; @@ -45,7 +45,7 @@ TEST_CASE("Time format implementation", "[CUC]") { TimeInfo.minute = 15; TimeInfo.second = 0; - TimeHelper::mkUTCtime(TimeInfo); + TimeHelper::utcToSeconds(TimeInfo); // invalid minute TimeInfo.year = 2018; @@ -55,7 +55,7 @@ TEST_CASE("Time format implementation", "[CUC]") { TimeInfo.minute = 200; TimeInfo.second = 0; - TimeHelper::mkUTCtime(TimeInfo); + TimeHelper::utcToSeconds(TimeInfo); // invalid second TimeInfo.year = 2018; @@ -65,7 +65,7 @@ TEST_CASE("Time format implementation", "[CUC]") { TimeInfo.minute = 15; TimeInfo.second = 122; - TimeHelper::mkUTCtime(TimeInfo); + TimeHelper::utcToSeconds(TimeInfo); } SECTION("Convert UTC date to elapsed seconds since Unix epoch") { @@ -79,7 +79,7 @@ TEST_CASE("Time format implementation", "[CUC]") { TimeInfo.second = 0; TimeHelper time; - uint32_t currTime = TimeHelper::mkUTCtime(TimeInfo); + uint32_t currTime = TimeHelper::utcToSeconds(TimeInfo); uint16_t elapsedDays = currTime / 86400; uint32_t msOfDay = currTime % 86400 * 1000; @@ -94,7 +94,7 @@ TEST_CASE("Time format implementation", "[CUC]") { TimeInfo.minute = 0; TimeInfo.second = 0; - currTime = TimeHelper::mkUTCtime(TimeInfo); + currTime = TimeHelper::utcToSeconds(TimeInfo); elapsedDays = currTime / 86400; msOfDay = currTime % 86400 * 1000; @@ -109,7 +109,7 @@ TEST_CASE("Time format implementation", "[CUC]") { TimeInfo.minute = 0; TimeInfo.second = 0; - currTime = TimeHelper::mkUTCtime(TimeInfo); + currTime = TimeHelper::utcToSeconds(TimeInfo); CHECK(currTime == 1607126400); // 10/12/2020 00:00:00 @@ -120,7 +120,7 @@ TEST_CASE("Time format implementation", "[CUC]") { TimeInfo.minute = 0; TimeInfo.second = 0; - currTime = TimeHelper::mkUTCtime(TimeInfo); + currTime = TimeHelper::utcToSeconds(TimeInfo); CHECK(currTime == 1607558400); // 15/12/2020 00:00:00 @@ -131,7 +131,7 @@ TEST_CASE("Time format implementation", "[CUC]") { TimeInfo.minute = 0; TimeInfo.second = 0; - currTime = TimeHelper::mkUTCtime(TimeInfo); + currTime = TimeHelper::utcToSeconds(TimeInfo); CHECK(currTime == 1607990400); // 20/12/2020 00:00:00 @@ -142,7 +142,7 @@ TEST_CASE("Time format implementation", "[CUC]") { TimeInfo.minute = 0; TimeInfo.second = 0; - currTime = TimeHelper::mkUTCtime(TimeInfo); + currTime = TimeHelper::utcToSeconds(TimeInfo); CHECK(currTime == 1608422400); } @@ -150,7 +150,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 = TimeHelper::utcTime(seconds); + struct TimeAndDate TimeInfo = TimeHelper::secondsToUTC(seconds); CHECK(TimeInfo.year == 2020); CHECK(TimeInfo.month == 4); CHECK(TimeInfo.day == 10); @@ -160,7 +160,7 @@ TEST_CASE("Time format implementation", "[CUC]") { seconds = 1546300800; // elapsed seconds between 1/1/2019 00:00:00 and Unix epoch - TimeInfo = TimeHelper::utcTime(seconds); + TimeInfo = TimeHelper::secondsToUTC(seconds); CHECK(TimeInfo.year == 2019); CHECK(TimeInfo.month == 1); CHECK(TimeInfo.day == 1); @@ -170,7 +170,7 @@ TEST_CASE("Time format implementation", "[CUC]") { seconds = 1550966400; // elapsed seconds between 24/2/2019 00:00:00 and Unix epoch - TimeInfo = TimeHelper::utcTime(seconds); + TimeInfo = TimeHelper::secondsToUTC(seconds); CHECK(TimeInfo.year == 2019); CHECK(TimeInfo.month == 2); CHECK(TimeInfo.day == 24); @@ -180,7 +180,7 @@ TEST_CASE("Time format implementation", "[CUC]") { seconds = 1551571200; // elapsed seconds between 3/3/2019 00:00:00 and Unix epoch - TimeInfo = TimeHelper::utcTime(seconds); + TimeInfo = TimeHelper::secondsToUTC(seconds); CHECK(TimeInfo.year == 2019); CHECK(TimeInfo.month == 3); CHECK(TimeInfo.day == 3); @@ -190,7 +190,7 @@ TEST_CASE("Time format implementation", "[CUC]") { seconds = 1742907370; // elapsed seconds between 25/3/2025 12:56:10 and Unix epoch - TimeInfo = TimeHelper::utcTime(seconds); + TimeInfo = TimeHelper::secondsToUTC(seconds); CHECK(TimeInfo.year == 2025); CHECK(TimeInfo.month == 3); CHECK(TimeInfo.day == 25); @@ -200,7 +200,7 @@ TEST_CASE("Time format implementation", "[CUC]") { seconds = 1583020800; // elapsed seconds between 1/3/2020 00:00:00 and Unix epoch - TimeInfo = TimeHelper::utcTime(seconds); + TimeInfo = TimeHelper::secondsToUTC(seconds); CHECK(TimeInfo.year == 2020); CHECK(TimeInfo.month == 3); CHECK(TimeInfo.day == 1); @@ -210,7 +210,7 @@ TEST_CASE("Time format implementation", "[CUC]") { seconds = 1582934400; // elapsed seconds between 2/29/2020 00:00:00 and Unix epoch - TimeInfo = TimeHelper::utcTime(seconds); + TimeInfo = TimeHelper::secondsToUTC(seconds); CHECK(TimeInfo.year == 2020); CHECK(TimeInfo.month == 2); CHECK(TimeInfo.day == 29); @@ -220,7 +220,7 @@ TEST_CASE("Time format implementation", "[CUC]") { seconds = 1577923200; // elapsed seconds between 2/1/2020 00:00:00 and Unix epoch - TimeInfo = TimeHelper::utcTime(seconds); + TimeInfo = TimeHelper::secondsToUTC(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 e7ba3cdf..6e03ea99 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 = TimeHelper::mkUTCtime(TimeInfo); + uint32_t currTime = TimeHelper::utcToSeconds(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 = TimeHelper::mkUTCtime(TimeInfo); + currTime = TimeHelper::utcToSeconds(TimeInfo); elapsedDays = currTime/86400; msOfDay = currTime % 86400 * 1000; -- GitLab