PhoenixClockMock  2.0.0
Tool to manipulate mock of clock (split, merge and get info)
PClockNs.cpp File Reference
#include <iomanip>
#include "PClockNs.h"
+ Include dependency graph for PClockNs.cpp:

Go to the source code of this file.

Functions

std::string phoenix_dateCompactNs (std::time_t currentDateNs)
 Convert a given date in nanosecond into a text date in a more compact way. More...
 
std::string phoenix_dateNs (std::time_t currentDateNs)
 Convert a given date in nanosecond into a text date. More...
 
std::string phoenix_dateNs (std::time_t currentDateNs, const char *format)
 Convert a given date in nanosecond into a text date. More...
 

Function Documentation

◆ phoenix_dateCompactNs()

std::string phoenix_dateCompactNs ( std::time_t  currentDateNs)

Convert a given date in nanosecond into a text date in a more compact way.

Parameters
currentDateNs: date in nanosecond to be converted
Returns
corresponding date in std::string

Definition at line 38 of file PClockNs.cpp.

38  {
39  return phoenix_dateNs(currentDateNs, "%Y/%m/%d : %X");
40 }
std::string phoenix_dateNs(std::time_t currentDateNs, const char *format)
Convert a given date in nanosecond into a text date.
Definition: PClockNs.cpp:15

References phoenix_dateNs().

Referenced by PClockNs::getDateCompactNs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ phoenix_dateNs() [1/2]

std::string phoenix_dateNs ( std::time_t  currentDateNs)

Convert a given date in nanosecond into a text date.

Parameters
currentDateNs: date in nanosecond to be converted
Returns
corresponding date in std::string

Definition at line 30 of file PClockNs.cpp.

30  {
31  return phoenix_dateNs(currentDateNs, "%Y/%m/%d-%X");
32 }

References phoenix_dateNs().

+ Here is the call graph for this function:

◆ phoenix_dateNs() [2/2]

std::string phoenix_dateNs ( std::time_t  currentDateNs,
const char *  format 
)

Convert a given date in nanosecond into a text date.

Parameters
currentDateNs: date in nanosecond to be converted
format: format to print the date (refer to std::strftime for the detail)
Returns
corresponding date in std::string

Definition at line 15 of file PClockNs.cpp.

15  {
16  std::time_t currentTimeSecond = currentDateNs / 1000000000l;
17  std::tm* now_tm = std::gmtime(&currentTimeSecond);
18  char buf[42];
19  std::strftime(buf, 42, "%Y/%m/%d : %X", now_tm);
20  std::time_t timeNanoSecond = currentDateNs - currentTimeSecond*1000000000l;
21  std::stringstream dateNs;
22  dateNs << buf << "." << std::setfill('0') << std::setw(9) << timeNanoSecond;
23  return dateNs.str();
24 }

Referenced by PClockNs::getDateNs(), phoenix_dateCompactNs(), phoenix_dateNs(), and testPClockNsCoherence().

+ Here is the caller graph for this function: