40 if (micros > PLUS_INF_MICROS) {
42 this->setToCmsNanoTime(micros);
44 this->setToMicrosTime(micros);
56 struct tm
Tm::c_tm() const
67 && m_tm.tm_mday == 0 ) {
104 char timebuf[20] =
"";
105 if (this->microsTime() >= PLUS_INF_MICROS) {
106 sprintf(timebuf,
"9999-12-12 23:59:59");
110 struct tm dummy_tm = dummy_Tm.
c_tm();
111 strftime(timebuf, 20,
"%Y-%m-%d %H:%M:%S", &dummy_tm);
118 return microsTime()/1000000 << 32;
123 return microsTime()/1000000;
138 struct tm time_struct;
139 time_struct.tm_year=1970-1900;
140 time_struct.tm_mon=0;
141 time_struct.tm_mday=1;
142 time_struct.tm_sec=0;
143 time_struct.tm_min=0;
144 time_struct.tm_hour=0;
145 time_struct.tm_isdst=0;
147 time_t t1970=mktime(&time_struct);
149 time_t t_this=mktime(&s);
151 double x= difftime(t_this,t1970);
159 setToMicrosTime((nanos >> 32) * 1000000);
164 time_t
t = micros / 1000000;
173 time_t
t =
time(
nullptr);
174 m_tm = *localtime( &t );
179 time_t
t =
time(
nullptr);
180 m_tm = *gmtime( &t );
185 m_tm = *localtime( &t );
190 m_tm = *gmtime( &t );
196 sscanf(
s.c_str(),
"%04d-%02d-%02d %02d:%02d:%02d",
197 &m_tm.tm_year, &m_tm.tm_mon, &m_tm.tm_mday,
198 &m_tm.tm_hour, &m_tm.tm_min, &m_tm.tm_sec);
201 if (m_tm.tm_year > 9999 || m_tm.tm_year < 1900) {
202 throw(std::runtime_error(
"Year out of bounds"));
203 }
else if (m_tm.tm_mon > 12 || m_tm.tm_mon < 1) {
204 throw(std::runtime_error(
"Month out of bounds"));
205 }
else if (m_tm.tm_mday > 31 || m_tm.tm_mday < 1) {
206 throw(std::runtime_error(
"Day out of bounds"));
207 }
else if (m_tm.tm_hour > 23 || m_tm.tm_mday < 0) {
208 throw(std::runtime_error(
"Hour out of bounds"));
209 }
else if (m_tm.tm_min > 59 || m_tm.tm_min < 0) {
210 throw(std::runtime_error(
"Minute out of bounds"));
211 }
else if (m_tm.tm_sec > 59 || m_tm.tm_sec < 0) {
212 throw(std::runtime_error(
"Day out of bounds"));
215 if (m_tm.tm_year >= 2038) {
218 if (m_tm.tm_mon > 1) {
221 if (m_tm.tm_mday > 19) {
224 if (m_tm.tm_hour > 3) {
227 if (m_tm.tm_min > 14) {
230 if (m_tm.tm_sec > 7) {
234 m_tm.tm_year -= 1900;
236 }
catch (std::runtime_error &
e) {
238 string msg(
"Tm::setToString(): ");
239 msg.append(e.what());
240 throw(std::runtime_error(msg));
246 cout <<
"=== dumpTm() ===" << endl;
247 cout <<
"tm_year " << m_tm.tm_year << endl;
248 cout <<
"tm_mon " << m_tm.tm_mon << endl;
249 cout <<
"tm_mday " << m_tm.tm_mday << endl;
250 cout <<
"tm_hour " << m_tm.tm_hour << endl;
251 cout <<
"tm_min " << m_tm.tm_min << endl;
252 cout <<
"tm_sec " << m_tm.tm_sec << endl;
253 cout <<
"tm_yday " << m_tm.tm_yday << endl;
254 cout <<
"tm_wday " << m_tm.tm_wday << endl;
255 cout <<
"tm_isdst " << m_tm.tm_isdst << endl;
256 cout <<
"================" << endl;
void setToCurrentLocalTime()
void setToCurrentGMTime()
uint64_t microsTime() const
void setToMicrosTime(uint64_t micros)
void setToCmsNanoTime(uint64_t nanos)
uint64_t unixTime() const
void setToGMTime(time_t t)
std::ostream & operator<<(std::ostream &out, const std::tuple< Types... > &value)
uint64_t cmsNanoSeconds() const
void setToString(const std::string s) noexcept(false)
unsigned long long uint64_t
void setToLocalTime(time_t t)