27 Tm::Tm(
struct tm *initTm) { m_tm = *initTm; }
31 if (micros > PLUS_INF_MICROS) {
33 this->setToCmsNanoTime(micros);
35 this->setToMicrosTime(micros);
47 if (m_tm.tm_year == 0 && m_tm.tm_mon == 0 && m_tm.tm_mday == 0) {
80 char timebuf[20] =
"";
81 if (this->microsTime() >= PLUS_INF_MICROS) {
82 sprintf(timebuf,
"9999-12-12 23:59:59");
86 struct tm dummy_tm = dummy_Tm.
c_tm();
87 strftime(timebuf, 20,
"%Y-%m-%d %H:%M:%S", &dummy_tm);
107 struct tm time_struct;
108 time_struct.tm_year = 1970 - 1900;
109 time_struct.tm_mon = 0;
110 time_struct.tm_mday = 1;
111 time_struct.tm_sec = 0;
112 time_struct.tm_min = 0;
113 time_struct.tm_hour = 0;
114 time_struct.tm_isdst = 0;
116 time_t t1970 = mktime(&time_struct);
118 time_t t_this = mktime(&
s);
120 double x = difftime(t_this, t1970);
129 time_t
t = micros / 1000000;
137 time_t
t =
time(
nullptr);
138 m_tm = *localtime(&
t);
142 time_t
t =
time(
nullptr);
152 "%04d-%02d-%02d %02d:%02d:%02d",
161 if (m_tm.tm_year > 9999 || m_tm.tm_year < 1900) {
162 throw(std::runtime_error(
"Year out of bounds"));
163 }
else if (m_tm.tm_mon > 12 || m_tm.tm_mon < 1) {
164 throw(std::runtime_error(
"Month out of bounds"));
165 }
else if (m_tm.tm_mday > 31 || m_tm.tm_mday < 1) {
166 throw(std::runtime_error(
"Day out of bounds"));
167 }
else if (m_tm.tm_hour > 23 || m_tm.tm_mday < 0) {
168 throw(std::runtime_error(
"Hour out of bounds"));
169 }
else if (m_tm.tm_min > 59 || m_tm.tm_min < 0) {
170 throw(std::runtime_error(
"Minute out of bounds"));
171 }
else if (m_tm.tm_sec > 59 || m_tm.tm_sec < 0) {
172 throw(std::runtime_error(
"Day out of bounds"));
175 if (m_tm.tm_year >= 2038) {
178 if (m_tm.tm_mon > 1) {
181 if (m_tm.tm_mday > 19) {
184 if (m_tm.tm_hour > 3) {
187 if (m_tm.tm_min > 14) {
190 if (m_tm.tm_sec > 7) {
194 m_tm.tm_year -= 1900;
196 }
catch (std::runtime_error &
e) {
198 string msg(
"Tm::setToString(): ");
199 msg.append(
e.what());
200 throw(std::runtime_error(
msg));
205 cout <<
"=== dumpTm() ===" << endl;
206 cout <<
"tm_year " << m_tm.tm_year << endl;
207 cout <<
"tm_mon " << m_tm.tm_mon << endl;
208 cout <<
"tm_mday " << m_tm.tm_mday << endl;
209 cout <<
"tm_hour " << m_tm.tm_hour << endl;
210 cout <<
"tm_min " << m_tm.tm_min << endl;
211 cout <<
"tm_sec " << m_tm.tm_sec << endl;
212 cout <<
"tm_yday " << m_tm.tm_yday << endl;
213 cout <<
"tm_wday " << m_tm.tm_wday << endl;
214 cout <<
"tm_isdst " << m_tm.tm_isdst << endl;
215 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