Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
ECSS Services
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AcubeSat-OBC
ECSS Services
Commits
bff34baf
Commit
bff34baf
authored
6 years ago
by
Theodoros Katzalis
Browse files
Options
Downloads
Patches
Plain Diff
Added tests for the new functions
parent
9082107a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
inc/Helpers/TimeHelper.hpp
+2
-2
2 additions, 2 deletions
inc/Helpers/TimeHelper.hpp
src/Helpers/TimeHelper.cpp
+24
-24
24 additions, 24 deletions
src/Helpers/TimeHelper.cpp
test/Helpers/TimeHelper.cpp
+154
-1
154 additions, 1 deletion
test/Helpers/TimeHelper.cpp
with
180 additions
and
27 deletions
inc/Helpers/TimeHelper.hpp
+
2
−
2
View file @
bff34baf
...
@@ -92,7 +92,7 @@ public:
...
@@ -92,7 +92,7 @@ public:
* @return true if \p Now is greater than \p DateExamined. The equality depends on the \p
* @return true if \p Now is greater than \p DateExamined. The equality depends on the \p
* equalCondition
* equalCondition
*/
*/
bool
IsAfter
(
struct
TimeAndDate
&
Now
,
struct
TimeAndDate
&
Date
,
bool
equalCondition
);
static
bool
IsAfter
(
struct
TimeAndDate
&
Now
,
struct
TimeAndDate
&
Date
,
bool
equalCondition
);
/**
/**
* @param Now the date provided from the Real Time Clock(UTC format)
* @param Now the date provided from the Real Time Clock(UTC format)
...
@@ -103,7 +103,7 @@ public:
...
@@ -103,7 +103,7 @@ public:
* @return true if \p Now is smaller than \p DateExamined. The equality depends on the \p
* @return true if \p Now is smaller than \p DateExamined. The equality depends on the \p
* equalCondition
* equalCondition
*/
*/
bool
IsBefore
(
struct
TimeAndDate
&
Now
,
struct
TimeAndDate
&
Date
,
bool
equalCondition
);
static
bool
IsBefore
(
struct
TimeAndDate
&
Now
,
struct
TimeAndDate
&
Date
,
bool
equalCondition
);
/**
/**
* Generate the CDS time format(3.3 in CCSDS 301.0-B-4 standard).
* Generate the CDS time format(3.3 in CCSDS 301.0-B-4 standard).
...
...
This diff is collapsed.
Click to expand it.
src/Helpers/TimeHelper.cpp
+
24
−
24
View file @
bff34baf
...
@@ -82,44 +82,44 @@ struct TimeAndDate TimeHelper::utcTime(uint32_t seconds) {
...
@@ -82,44 +82,44 @@ struct TimeAndDate TimeHelper::utcTime(uint32_t seconds) {
bool
TimeHelper
::
IsAfter
(
struct
TimeAndDate
&
Now
,
struct
TimeAndDate
&
Date
,
bool
bool
TimeHelper
::
IsAfter
(
struct
TimeAndDate
&
Now
,
struct
TimeAndDate
&
Date
,
bool
equalCondition
)
{
equalCondition
)
{
// compare years
// compare years
if
(
Now
.
year
>
Date
.
year
)
{
if
(
Now
.
year
<
Date
.
year
)
{
return
true
;
return
true
;
}
else
if
(
Now
.
year
<
Date
.
year
)
{
}
else
if
(
Now
.
year
>
Date
.
year
)
{
return
false
;
return
false
;
}
}
// compare months
// compare months
if
(
Now
.
month
>
Date
.
month
)
{
if
(
Now
.
month
<
Date
.
month
)
{
return
true
;
return
true
;
}
else
if
(
Now
.
month
<
Date
.
month
)
{
}
else
if
(
Now
.
month
>
Date
.
month
)
{
return
false
;
return
false
;
}
}
// compare days
// compare days
if
(
Now
.
day
>
Date
.
day
)
{
if
(
Now
.
day
<
Date
.
day
)
{
return
true
;
return
true
;
}
else
if
(
Now
.
day
<
Date
.
day
)
{
}
else
if
(
Now
.
day
>
Date
.
day
)
{
return
false
;
return
false
;
}
}
// compare hours
// compare hours
if
(
Now
.
hour
>
Date
.
hour
)
{
if
(
Now
.
hour
<
Date
.
hour
)
{
return
true
;
return
true
;
}
else
if
(
Now
.
hour
<
Date
.
hour
)
{
}
else
if
(
Now
.
hour
>
Date
.
hour
)
{
return
false
;
return
false
;
}
}
// compare minutes
// compare minutes
if
(
Now
.
minute
>
Date
.
minute
)
{
if
(
Now
.
minute
<
Date
.
minute
)
{
return
true
;
return
true
;
}
else
if
(
Now
.
minute
<
Date
.
minute
)
{
}
else
if
(
Now
.
minute
>
Date
.
minute
)
{
return
false
;
return
false
;
}
}
// compare seconds
// compare seconds
if
(
Now
.
second
>
Date
.
second
)
{
if
(
Now
.
second
<
Date
.
second
)
{
return
true
;
return
true
;
}
else
if
(
Now
.
second
<
Date
.
second
)
{
}
else
if
(
Now
.
second
>
Date
.
second
)
{
return
false
;
return
false
;
}
else
if
(
Now
.
second
==
Date
.
second
)
}
else
if
(
Now
.
second
==
Date
.
second
)
return
equalCondition
;
return
equalCondition
;
...
@@ -128,44 +128,44 @@ equalCondition) {
...
@@ -128,44 +128,44 @@ equalCondition) {
bool
TimeHelper
::
IsBefore
(
struct
TimeAndDate
&
Now
,
struct
TimeAndDate
&
Date
,
bool
bool
TimeHelper
::
IsBefore
(
struct
TimeAndDate
&
Now
,
struct
TimeAndDate
&
Date
,
bool
equalCondition
)
{
equalCondition
)
{
// compare years
// compare years
if
(
Now
.
year
<
Date
.
year
)
{
if
(
Now
.
year
>
Date
.
year
)
{
return
true
;
return
true
;
}
else
if
(
Now
.
year
>
Date
.
year
)
{
}
else
if
(
Now
.
year
<
Date
.
year
)
{
return
false
;
return
false
;
}
}
// compare months
// compare months
if
(
Now
.
month
<
Date
.
month
)
{
if
(
Now
.
month
>
Date
.
month
)
{
return
true
;
return
true
;
}
else
if
(
Now
.
month
>
Date
.
month
)
{
}
else
if
(
Now
.
month
<
Date
.
month
)
{
return
false
;
return
false
;
}
}
// compare days
// compare days
if
(
Now
.
day
<
Date
.
day
)
{
if
(
Now
.
day
>
Date
.
day
)
{
return
true
;
return
true
;
}
else
if
(
Now
.
day
>
Date
.
day
)
{
}
else
if
(
Now
.
day
<
Date
.
day
)
{
return
false
;
return
false
;
}
}
// compare hours
// compare hours
if
(
Now
.
hour
<
Date
.
hour
)
{
if
(
Now
.
hour
>
Date
.
hour
)
{
return
true
;
return
true
;
}
else
if
(
Now
.
hour
>
Date
.
hour
)
{
}
else
if
(
Now
.
hour
<
Date
.
hour
)
{
return
false
;
return
false
;
}
}
// compare minutes
// compare minutes
if
(
Now
.
minute
<
Date
.
minute
)
{
if
(
Now
.
minute
>
Date
.
minute
)
{
return
true
;
return
true
;
}
else
if
(
Now
.
minute
>
Date
.
minute
)
{
}
else
if
(
Now
.
minute
<
Date
.
minute
)
{
return
false
;
return
false
;
}
}
// compare seconds
// compare seconds
if
(
Now
.
second
<
Date
.
second
)
{
if
(
Now
.
second
>
Date
.
second
)
{
return
true
;
return
true
;
}
else
if
(
Now
.
second
>
Date
.
second
)
{
}
else
if
(
Now
.
second
<
Date
.
second
)
{
return
false
;
return
false
;
}
else
if
(
Now
.
second
==
Date
.
second
)
}
else
if
(
Now
.
second
==
Date
.
second
)
return
equalCondition
;
return
equalCondition
;
...
...
This diff is collapsed.
Click to expand it.
test/Helpers/TimeHelper.cpp
+
154
−
1
View file @
bff34baf
...
@@ -37,7 +37,7 @@ TEST_CASE("Time format implementation", "[CUC]") {
...
@@ -37,7 +37,7 @@ TEST_CASE("Time format implementation", "[CUC]") {
CHECK
(
TimeHelper
::
generateCDStimeFormat
(
TimeInfo
)
==
timeFormat
);
CHECK
(
TimeHelper
::
generateCDStimeFormat
(
TimeInfo
)
==
timeFormat
);
}
}
SECTION
(
"Convert elapsed seconds since Unix epoch to UTC date"
){
SECTION
(
"Convert elapsed seconds since Unix epoch to UTC date"
)
{
uint32_t
seconds
=
1586513700
;
// elapsed seconds between 10/04/2020 10:15:00 and Unix epoch
uint32_t
seconds
=
1586513700
;
// elapsed seconds between 10/04/2020 10:15:00 and Unix epoch
TimeHelper
time
;
TimeHelper
time
;
...
@@ -121,4 +121,157 @@ TEST_CASE("Time format implementation", "[CUC]") {
...
@@ -121,4 +121,157 @@ TEST_CASE("Time format implementation", "[CUC]") {
}
}
SECTION
(
"Date comparison"
)
{
SECTION
(
"Different year"
)
{
struct
TimeAndDate
Now
=
{
0
};
// 10/04/2021 10:15:00
Now
.
year
=
2021
;
Now
.
month
=
4
;
Now
.
day
=
10
;
Now
.
hour
=
10
;
Now
.
minute
=
15
;
Now
.
second
=
0
;
struct
TimeAndDate
Date
=
{
0
};
// 10/04/2020 10:15:00
Date
.
year
=
2020
;
Date
.
month
=
4
;
Date
.
day
=
10
;
Date
.
hour
=
10
;
Date
.
minute
=
15
;
Date
.
second
=
0
;
CHECK
(
TimeHelper
::
IsAfter
(
Now
,
Date
,
true
)
==
false
);
CHECK
(
TimeHelper
::
IsAfter
(
Date
,
Now
,
true
)
==
true
);
CHECK
(
TimeHelper
::
IsBefore
(
Now
,
Date
,
true
)
==
true
);
CHECK
(
TimeHelper
::
IsBefore
(
Date
,
Now
,
true
)
==
false
);
}
SECTION
(
"Different month"
)
{
struct
TimeAndDate
Now
=
{
0
};
// 10/05/2020 10:15:00
Now
.
year
=
2020
;
Now
.
month
=
5
;
Now
.
day
=
10
;
Now
.
hour
=
10
;
Now
.
minute
=
15
;
Now
.
second
=
0
;
struct
TimeAndDate
Date
=
{
0
};
// 10/04/2020 10:15:00
Date
.
year
=
2020
;
Date
.
month
=
4
;
Date
.
day
=
10
;
Date
.
hour
=
10
;
Date
.
minute
=
15
;
Date
.
second
=
0
;
CHECK
(
TimeHelper
::
IsAfter
(
Now
,
Date
,
true
)
==
false
);
CHECK
(
TimeHelper
::
IsAfter
(
Date
,
Now
,
true
)
==
true
);
CHECK
(
TimeHelper
::
IsBefore
(
Now
,
Date
,
true
)
==
true
);
CHECK
(
TimeHelper
::
IsBefore
(
Date
,
Now
,
true
)
==
false
);
}
SECTION
(
"Different day"
)
{
struct
TimeAndDate
Now
=
{
0
};
// 11/04/2020 10:15:00
Now
.
year
=
2020
;
Now
.
month
=
5
;
Now
.
day
=
11
;
Now
.
hour
=
10
;
Now
.
minute
=
15
;
Now
.
second
=
0
;
struct
TimeAndDate
Date
=
{
0
};
// 10/04/2020 10:15:00
Date
.
year
=
2020
;
Date
.
month
=
4
;
Date
.
day
=
10
;
Date
.
hour
=
10
;
Date
.
minute
=
15
;
Date
.
second
=
0
;
CHECK
(
TimeHelper
::
IsAfter
(
Now
,
Date
,
true
)
==
false
);
CHECK
(
TimeHelper
::
IsAfter
(
Date
,
Now
,
true
)
==
true
);
CHECK
(
TimeHelper
::
IsBefore
(
Now
,
Date
,
true
)
==
true
);
CHECK
(
TimeHelper
::
IsBefore
(
Date
,
Now
,
true
)
==
false
);
}
SECTION
(
"Different hour"
)
{
struct
TimeAndDate
Now
=
{
0
};
// 10/04/2020 11:15:00
Now
.
year
=
2020
;
Now
.
month
=
4
;
Now
.
day
=
10
;
Now
.
hour
=
11
;
Now
.
minute
=
15
;
Now
.
second
=
0
;
struct
TimeAndDate
Date
=
{
0
};
// 10/04/2020 10:15:00
Date
.
year
=
2020
;
Date
.
month
=
4
;
Date
.
day
=
10
;
Date
.
hour
=
10
;
Date
.
minute
=
15
;
Date
.
second
=
0
;
CHECK
(
TimeHelper
::
IsAfter
(
Now
,
Date
,
true
)
==
false
);
CHECK
(
TimeHelper
::
IsAfter
(
Date
,
Now
,
true
)
==
true
);
CHECK
(
TimeHelper
::
IsBefore
(
Now
,
Date
,
true
)
==
true
);
CHECK
(
TimeHelper
::
IsBefore
(
Date
,
Now
,
true
)
==
false
);
}
SECTION
(
"Different minute"
)
{
struct
TimeAndDate
Now
=
{
0
};
// 11/04/2020 10:16:00
Now
.
year
=
2020
;
Now
.
month
=
4
;
Now
.
day
=
10
;
Now
.
hour
=
10
;
Now
.
minute
=
16
;
Now
.
second
=
0
;
struct
TimeAndDate
Date
=
{
0
};
// 10/04/2020 10:15:00
Date
.
year
=
2020
;
Date
.
month
=
4
;
Date
.
day
=
10
;
Date
.
hour
=
10
;
Date
.
minute
=
15
;
Date
.
second
=
0
;
CHECK
(
TimeHelper
::
IsAfter
(
Now
,
Date
,
true
)
==
false
);
CHECK
(
TimeHelper
::
IsAfter
(
Date
,
Now
,
true
)
==
true
);
CHECK
(
TimeHelper
::
IsBefore
(
Now
,
Date
,
true
)
==
true
);
CHECK
(
TimeHelper
::
IsBefore
(
Date
,
Now
,
true
)
==
false
);
}
SECTION
(
"Different second"
)
{
struct
TimeAndDate
Now
=
{
0
};
// 11/04/2020 10:15:01
Now
.
year
=
2020
;
Now
.
month
=
4
;
Now
.
day
=
10
;
Now
.
hour
=
10
;
Now
.
minute
=
15
;
Now
.
second
=
1
;
struct
TimeAndDate
Date
=
{
0
};
// 10/04/2020 10:15:00
Date
.
year
=
2020
;
Date
.
month
=
4
;
Date
.
day
=
10
;
Date
.
hour
=
10
;
Date
.
minute
=
15
;
Date
.
second
=
0
;
CHECK
(
TimeHelper
::
IsAfter
(
Now
,
Date
,
true
)
==
false
);
CHECK
(
TimeHelper
::
IsAfter
(
Date
,
Now
,
true
)
==
true
);
CHECK
(
TimeHelper
::
IsBefore
(
Now
,
Date
,
true
)
==
true
);
CHECK
(
TimeHelper
::
IsBefore
(
Date
,
Now
,
true
)
==
false
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment