-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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 | ||
|
@@ -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; | ||
|
@@ -42,4 +59,4 @@ namespace timeops | |
} | ||
} // namespace timeops | ||
|
||
#endif // TIME_OPERATIONS_HPP | ||
#endif // TIME_OPERATIONS_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters