From f9e399b911ec31997fd9c27c411cf017263440de Mon Sep 17 00:00:00 2001
From: kongr45gpen <electrovesta@gmail.com>
Date: Tue, 23 Aug 2022 00:24:54 +0000
Subject: [PATCH] Fix time parameters

---
 inc/Helpers/Parameter.hpp                         | 12 +++++++++++-
 .../{TimeFormats.cpp => TimeFormatsTests.cpp}     | 15 +++++++++++++++
 test/Time/{TimeStamp.cpp => TimeStampTests.cpp}   |  0
 3 files changed, 26 insertions(+), 1 deletion(-)
 rename test/Time/{TimeFormats.cpp => TimeFormatsTests.cpp} (64%)
 rename test/Time/{TimeStamp.cpp => TimeStampTests.cpp} (100%)

diff --git a/inc/Helpers/Parameter.hpp b/inc/Helpers/Parameter.hpp
index ccc55ae9..3ce19915 100644
--- a/inc/Helpers/Parameter.hpp
+++ b/inc/Helpers/Parameter.hpp
@@ -58,8 +58,18 @@ public:
 		return currentValue;
 	}
 
+	/**
+	 * Converts the value of a parameter to a double.
+	 *
+	 * Some precision may be lost in the process. If the value is not arithmetic,
+	 * then 0 is returned.
+	 */
 	inline double getValueAsDouble() override {
-		return static_cast<double>(currentValue);
+		if constexpr (std::is_arithmetic_v<DataType>) {
+			return static_cast<double>(currentValue);
+		} else {
+			return 0;
+		}
 	}
 
 	/**
diff --git a/test/Time/TimeFormats.cpp b/test/Time/TimeFormatsTests.cpp
similarity index 64%
rename from test/Time/TimeFormats.cpp
rename to test/Time/TimeFormatsTests.cpp
index b5121afd..828cf885 100644
--- a/test/Time/TimeFormats.cpp
+++ b/test/Time/TimeFormatsTests.cpp
@@ -1,6 +1,7 @@
 #include "../Services/ServiceTests.hpp"
 #include "Time/Time.hpp"
 #include "Time/UTCTimestamp.hpp"
+#include "Message.hpp"
 #include "catch2/catch_all.hpp"
 
 TEST_CASE("UTC timestamps") {
@@ -25,3 +26,17 @@ TEST_CASE("UTC timestamps") {
 	CHECK(ServiceTests::countErrors() == 6);
 	CHECK(ServiceTests::thrownError(ErrorHandler::InvalidDate));
 }
+
+TEST_CASE("CUC Custom Timestamp as Parameter") {
+	Time::CustomCUC_t time;
+	time.elapsed100msTicks = 999;
+
+	auto parameter = Parameter<Time::CustomCUC_t>(time);
+
+	auto message = Message(0, 0, Message::TC);
+	parameter.appendValueToMessage(message);
+	CHECK(message.dataSize == 8);
+
+	parameter.setValueFromMessage(message);
+	CHECK(time == parameter.getValue());
+}
\ No newline at end of file
diff --git a/test/Time/TimeStamp.cpp b/test/Time/TimeStampTests.cpp
similarity index 100%
rename from test/Time/TimeStamp.cpp
rename to test/Time/TimeStampTests.cpp
-- 
GitLab