Skip to content

Commit

Permalink
More updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Byrdman32 committed Jan 7, 2025
1 parent 41d8bd5 commit ca653c3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
25 changes: 21 additions & 4 deletions src/util/TimeOperations.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/******************************************************************************
* @brief
* @brief Defines and implements functions related to operations on time and
* date within the timeops namespace.
*
* @file TimeOperations.hpp
* @author Eli Byrd ([email protected])
* @author Eli Byrd ([email protected])
* @date 2025-01-07
*
* @copyright Copyright Mars Rover Design Team 2025 - All Rights Reserved
Expand All @@ -18,8 +19,24 @@

/// \endcond

/******************************************************************************
* @brief Namespace containing functions related to operations on time and
* date related data types.
*
* @author Eli Byrd ([email protected])
* @date 2025-01-07
******************************************************************************/
namespace timeops
{
/******************************************************************************
* @brief Accessor for getting the current time in a specified format.
*
* @param szFormat - The format to return the time in.
* @return std::string - The current time in the specified format.
*
* @author Eli Byrd ([email protected])
* @date 2025-01-07
******************************************************************************/
inline std::string GetTimestamp(std::string szFormat = "%Y%m%d-%H%M%S")
{
// Retrieve the current time for the log file name
Expand All @@ -32,7 +49,7 @@ namespace timeops
// Format the current time in a format that can be used as a file name.
std::array<char, 80> cCurrentTime;
size_t siTimeCharacters;
siTimeCharacters = std::strftime(cCurrentTime.data(), cCurrentTime.size(), szFormat, tLocalTime);
siTimeCharacters = std::strftime(cCurrentTime.data(), cCurrentTime.size(), szFormat.c_str(), tLocalTime);
if (siTimeCharacters == 0)
{
std::cerr << "Unable to format calendar date & time (exceeds string length)" << std::endl;

Check warning on line 55 in src/util/TimeOperations.hpp

View check run for this annotation

Codecov / codecov/patch

src/util/TimeOperations.hpp#L55

Added line #L55 was not covered by tests
Expand All @@ -42,4 +59,4 @@ namespace timeops
}
} // namespace timeops

#endif // TIME_OPERATIONS_HPP
#endif // TIME_OPERATIONS_HPP
19 changes: 17 additions & 2 deletions tests/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,23 @@
******************************************************************************/
int main(int argc, char** argv)
{
// Setup logging.
logging::InitializeLoggers(constants::LOGGING_OUTPUT_PATH_ABSOLUTE);
bool skipLogging = false;

// Check if the test being run is "AutonomyLogging"
for (int i = 1; i < argc; ++i)
{
if (std::string(argv[i]).find("--gtest_filter=AutonomyLoggingTest") != std::string::npos)
{
skipLogging = true;
break;
}
}

// Setup logging if not skipped.
if (!skipLogging)
{
logging::InitializeLoggers(constants::LOGGING_OUTPUT_PATH_ABSOLUTE);
}

// Initialize tests.
testing::InitGoogleTest(&argc, argv);
Expand Down

0 comments on commit ca653c3

Please sign in to comment.