PhoenixClock  0.4.0
Library wrapping the usage of system's clock, allowing to use clock mock-ups
Loading...
Searching...
No Matches
PClockNs.cpp
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7#include <iomanip>
8#include "PClockNs.h"
9
11
15std::string phoenix_dateNs(std::time_t currentDateNs, const char* format){
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}
25
27
30std::string phoenix_dateNs(std::time_t currentDateNs){
31 return phoenix_dateNs(currentDateNs, "%Y/%m/%d-%X");
32}
33
35
38std::string phoenix_dateCompactNs(std::time_t currentDateNs){
39 return phoenix_dateNs(currentDateNs, "%Y/%m/%d : %X");
40}
41
46
48
51 copyPClockNs(other);
52}
53
58
60
64 copyPClockNs(other);
65 return *this;
66}
67
69
71void PClockNs::setOffsetTimeNs(std::time_t offsetTimeNs){
72 p_offsetTimeNs = offsetTimeNs;
73}
74
76
78std::time_t PClockNs::getOffsetTimeNs() const{
79 return p_offsetTimeNs;
80}
81
83
85std::time_t PClockNs::getFullTimeNs() const{
86 //Let's get the time in nanoseconds since the start of the PClockNs
87 std::time_t ellapsedTimeNsSinceStart = (PClockNs::SteadyClock::now() - p_baseSteadyClockNs).count();
88
89 std::time_t fullTimeNs = p_baseSystemClockSecond*1000000000l + ellapsedTimeNsSinceStart;
90 return fullTimeNs + p_offsetTimeNs;
91}
92
94
96std::string PClockNs::getDateNs() const{
98}
99
101
103std::string PClockNs::getDateCompactNs() const{
105}
106
108
115
118 p_baseSystemClockSecond = std::time(0);
119 p_baseSteadyClockNs = PClockNs::SteadyClock::now();
120 p_offsetTimeNs = 0l;
121}
122
123
124
125
126
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
std::string phoenix_dateCompactNs(std::time_t currentDateNs)
Convert a given date in nanosecond into a text date in a more compact way.
Definition PClockNs.cpp:38
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
std::string phoenix_dateCompactNs(std::time_t currentDateNs)
Convert a given date in nanosecond into a text date in a more compact way.
Definition PClockNs.cpp:38
std::string getDateCompactNs() const
Get the date at nanosecond precision (even if it is not precise at the nanosecond scale,...
Definition PClockNs.cpp:103
void initialisationPClockNs()
Initialisation function of the class PClockNs.
Definition PClockNs.cpp:117
PClockNs & operator=(const PClockNs &other)
Definition of equal operator of PClockNs.
Definition PClockNs.cpp:63
std::time_t getOffsetTimeNs() const
Get the offset in nanoseconds of the current clock.
Definition PClockNs.cpp:78
std::time_t getFullTimeNs() const
Get the full time in nanoseconds.
Definition PClockNs.cpp:85
virtual ~PClockNs()
Destructor of PClockNs.
Definition PClockNs.cpp:55
void setOffsetTimeNs(std::time_t offsetTimeNs)
Set the offset in nanoseconds of the current clock.
Definition PClockNs.cpp:71
std::string getDateNs() const
Get the date at nanosecond precision (even if it is not precise at the nanosecond scale,...
Definition PClockNs.cpp:96
PClockNs()
Default constructor of PClockNs.
Definition PClockNs.cpp:43
std::time_t p_baseSystemClockSecond
Base of the system clock in second.
Definition PClockNs.h:42
void copyPClockNs(const PClockNs &other)
Copy function of PClockNs.
Definition PClockNs.cpp:110
std::time_t p_offsetTimeNs
Offset of time with date and nanoseconds.
Definition PClockNs.h:46
TimeNs p_baseSteadyClockNs
Base clock time with a nanosecond precision but since the starting of the CPU.
Definition PClockNs.h:44