From 30b8b59e9f1e714c55bfa87c1cc89637c8c5ed77 Mon Sep 17 00:00:00 2001
From: Theodoros Katzalis <thodkatz@gmail.com>
Date: Sat, 16 Mar 2019 01:12:03 +0200
Subject: [PATCH] Added constructors for the TimeAndDate class

---
 inc/Helpers/TimeAndDate.hpp             |  5 +++++
 src/Helpers/TimeAndDate.cpp             | 21 +++++++++++++++++++
 src/Helpers/TimeHelper.cpp              |  2 +-
 src/main.cpp                            |  2 +-
 test/Helpers/TimeAndDate.cpp            | 28 ++++++++++++-------------
 test/Helpers/TimeHelper.cpp             |  2 +-
 test/Services/TimeManagementService.cpp |  2 +-
 7 files changed, 44 insertions(+), 18 deletions(-)

diff --git a/inc/Helpers/TimeAndDate.hpp b/inc/Helpers/TimeAndDate.hpp
index b40913df..8747aa3d 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 171f7a56..d5cd9a2c 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 a5681059..22fb1edf 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 7f49b9d5..a35ab891 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 3c6a3f2f..28532ca8 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 700c43d9..c5a58e33 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 612c4cde..f2388206 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;
-- 
GitLab