PhoenixClock  0.4.0
Library wrapping the usage of system's clock, allowing to use clock mock-ups
Loading...
Searching...
No Matches
PClockNs.h File Reference
#include <time.h>
#include <chrono>
#include <ctime>
#include <string>
+ Include dependency graph for PClockNs.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  PClockNs
 Nanosecond clock. More...
 

Functions

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

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(), and phoenix_dateNs().

+ Here is the caller graph for this function: