27 Tm::Tm(
struct tm *initTm) { m_tm = *initTm; }
31 if (micros > PLUS_INF_MICROS) {
33 this->setToCmsNanoTime(micros);
35 this->setToMicrosTime(micros);
42 struct tm
Tm::c_tm()
const {
return m_tm; }
45 if (m_tm.tm_year == 0 && m_tm.tm_mon == 0 && m_tm.tm_mday == 0) {
78 char timebuf[20] =
"";
79 if (this->microsTime() >= PLUS_INF_MICROS) {
80 sprintf(timebuf,
"9999-12-12 23:59:59");
84 struct tm dummy_tm = dummy_Tm.
c_tm();
85 strftime(timebuf, 20,
"%Y-%m-%d %H:%M:%S", &dummy_tm);
105 struct tm time_struct;
106 time_struct.tm_year = 1970 - 1900;
107 time_struct.tm_mon = 0;
108 time_struct.tm_mday = 1;
109 time_struct.tm_sec = 0;
110 time_struct.tm_min = 0;
111 time_struct.tm_hour = 0;
112 time_struct.tm_isdst = 0;
114 time_t t1970 = mktime(&time_struct);
116 time_t t_this = mktime(&
s);
118 double x = difftime(t_this, t1970);
127 time_t
t = micros / 1000000;
135 time_t
t =
time(
nullptr);
136 m_tm = *localtime(&
t);
140 time_t
t =
time(
nullptr);
150 "%04d-%02d-%02d %02d:%02d:%02d",
159 if (m_tm.tm_year > 9999 || m_tm.tm_year < 1900) {
160 throw(std::runtime_error(
"Year out of bounds"));
161 }
else if (m_tm.tm_mon > 12 || m_tm.tm_mon < 1) {
162 throw(std::runtime_error(
"Month out of bounds"));
163 }
else if (m_tm.tm_mday > 31 || m_tm.tm_mday < 1) {
164 throw(std::runtime_error(
"Day out of bounds"));
165 }
else if (m_tm.tm_hour > 23 || m_tm.tm_mday < 0) {
166 throw(std::runtime_error(
"Hour out of bounds"));
167 }
else if (m_tm.tm_min > 59 || m_tm.tm_min < 0) {
168 throw(std::runtime_error(
"Minute out of bounds"));
169 }
else if (m_tm.tm_sec > 59 || m_tm.tm_sec < 0) {
170 throw(std::runtime_error(
"Day out of bounds"));
173 if (m_tm.tm_year >= 2038) {
176 if (m_tm.tm_mon > 1) {
179 if (m_tm.tm_mday > 19) {
182 if (m_tm.tm_hour > 3) {
185 if (m_tm.tm_min > 14) {
188 if (m_tm.tm_sec > 7) {
192 m_tm.tm_year -= 1900;
194 }
catch (std::runtime_error &
e) {
196 string msg(
"Tm::setToString(): ");
197 msg.append(
e.what());
198 throw(std::runtime_error(
msg));
203 cout <<
"=== dumpTm() ===" << endl;
204 cout <<
"tm_year " << m_tm.tm_year << endl;
205 cout <<
"tm_mon " << m_tm.tm_mon << endl;
206 cout <<
"tm_mday " << m_tm.tm_mday << endl;
207 cout <<
"tm_hour " << m_tm.tm_hour << endl;
208 cout <<
"tm_min " << m_tm.tm_min << endl;
209 cout <<
"tm_sec " << m_tm.tm_sec << endl;
210 cout <<
"tm_yday " << m_tm.tm_yday << endl;
211 cout <<
"tm_wday " << m_tm.tm_wday << endl;
212 cout <<
"tm_isdst " << m_tm.tm_isdst << endl;
213 cout <<
"================" << endl;
uint64_t cmsNanoSeconds() const
void setToCurrentLocalTime()
void setToCurrentGMTime()
uint64_t unixTime() const
void setToMicrosTime(uint64_t micros)
void setToCmsNanoTime(uint64_t nanos)
void setToGMTime(time_t t)
std::ostream & operator<<(std::ostream &out, const std::tuple< Types... > &value)
void setToString(const std::string s) noexcept(false)
unsigned long long uint64_t
void setToLocalTime(time_t t)
uint64_t microsTime() const