Skip to content
Snippets Groups Projects
Commit 9082107a authored by Theodoros Katzalis's avatar Theodoros Katzalis
Browse files

Added two functions that perform date comparison

parent f75f5bd6
No related branches found
No related tags found
No related merge requests found
......@@ -3,25 +3,6 @@
<option name="RIGHT_MARGIN" value="100" />
<option name="WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN" value="true" />
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="hpp" fileNamingConvention="PASCAL_CASE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
......
......@@ -82,6 +82,29 @@ public:
TimeHelper() = default;
/**
* @param Now the date provided from the Real Time Clock(UTC format)
* @param Date the date that will be compared with the \p Now
* @param equalCondition if it is true, then this function returns true when the dates
* are equal. If the \p equalCondition is false, then this function returns false when
* the dates are equal
* @return true if \p Now is greater than \p DateExamined. The equality depends on the \p
* equalCondition
*/
bool IsAfter(struct TimeAndDate &Now, struct TimeAndDate &Date, bool equalCondition);
/**
* @param Now the date provided from the Real Time Clock(UTC format)
* @param Date the date that will be compared with the \p Now
* @param equalCondition if it is true, then this function returns true when the dates
* are equal. If the \p equalCondition is false, then this function returns false when
* the dates are equal.
* @return true if \p Now is smaller than \p DateExamined. The equality depends on the \p
* equalCondition
*/
bool IsBefore(struct TimeAndDate &Now, struct TimeAndDate &Date, bool equalCondition);
/**
* Generate the CDS time format(3.3 in CCSDS 301.0-B-4 standard).
*
......
......@@ -61,16 +61,16 @@ struct TimeAndDate TimeHelper::utcTime(uint32_t seconds) {
}
// calculate days
TimeInfo.day = seconds/SecondsPerDay;
TimeInfo.day = seconds / SecondsPerDay;
seconds -= TimeInfo.day * SecondsPerDay;
TimeInfo.day++; // add 1 day because we start count from 1 January(and not 0 January!)
// calculate hours
TimeInfo.hour = seconds/SecondsPerHour;
TimeInfo.hour = seconds / SecondsPerHour;
seconds -= TimeInfo.hour * SecondsPerHour;
// calculate minutes
TimeInfo.minute = seconds/SecondsPerMinute;
TimeInfo.minute = seconds / SecondsPerMinute;
seconds -= TimeInfo.minute * SecondsPerMinute;
// calculate seconds
......@@ -79,6 +79,98 @@ struct TimeAndDate TimeHelper::utcTime(uint32_t seconds) {
return TimeInfo;
}
bool TimeHelper::IsAfter(struct TimeAndDate &Now, struct TimeAndDate &Date, bool
equalCondition) {
// compare years
if (Now.year > Date.year) {
return true;
} else if (Now.year < Date.year) {
return false;
}
// compare months
if (Now.month > Date.month) {
return true;
} else if (Now.month < Date.month) {
return false;
}
// compare days
if (Now.day > Date.day) {
return true;
} else if (Now.day < Date.day) {
return false;
}
// compare hours
if (Now.hour > Date.hour) {
return true;
} else if (Now.hour < Date.hour) {
return false;
}
// compare minutes
if (Now.minute > Date.minute) {
return true;
} else if (Now.minute < Date.minute) {
return false;
}
// compare seconds
if (Now.second > Date.second) {
return true;
} else if (Now.second < Date.second) {
return false;
} else if (Now.second == Date.second)
return equalCondition;
}
bool TimeHelper::IsBefore(struct TimeAndDate &Now, struct TimeAndDate &Date, bool
equalCondition) {
// compare years
if (Now.year < Date.year) {
return true;
} else if (Now.year > Date.year) {
return false;
}
// compare months
if (Now.month < Date.month) {
return true;
} else if (Now.month > Date.month) {
return false;
}
// compare days
if (Now.day < Date.day) {
return true;
} else if (Now.day > Date.day) {
return false;
}
// compare hours
if (Now.hour < Date.hour) {
return true;
} else if (Now.hour > Date.hour) {
return false;
}
// compare minutes
if (Now.minute < Date.minute) {
return true;
} else if (Now.minute > Date.minute) {
return false;
}
// compare seconds
if (Now.second < Date.second) {
return true;
} else if (Now.second > Date.second) {
return false;
} else if (Now.second == Date.second)
return equalCondition;
}
uint64_t TimeHelper::generateCDStimeFormat(struct TimeAndDate &TimeInfo) {
/**
* Define the T-field. The total number of octets for the implementation of T-field is 6(2 for
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment