35 if (micros > PLUS_INF_MICROS) {
36 micros = PLUS_INF_MICROS;
38 this->setToMicrosTime(micros);
60 && m_tm.tm_mday == 0 ) {
97 char timebuf[20] =
"";
98 if (this->microsTime() >= PLUS_INF_MICROS) {
99 sprintf(timebuf,
"9999-12-12 23:59:59");
103 struct tm dummy_tm = dummy_Tm.
c_tm();
104 strftime(timebuf, 20,
"%Y-%m-%d %H:%M:%S", &dummy_tm);
106 return string(timebuf);
121 struct tm time_struct;
122 time_struct.tm_year=1970-1900;
123 time_struct.tm_mon=0;
124 time_struct.tm_mday=1;
125 time_struct.tm_sec=0;
126 time_struct.tm_min=0;
127 time_struct.tm_hour=0;
128 time_struct.tm_isdst=0;
130 time_t t1970=mktime(&time_struct);
132 time_t t_this=mktime(&s);
134 double x= difftime(t_this,t1970);
143 time_t
t = micros / 1000000;
153 m_tm = *localtime( &t );
159 m_tm = *gmtime( &t );
164 m_tm = *localtime( &t );
169 m_tm = *gmtime( &t );
173 throw(std::runtime_error)
175 sscanf(
s.c_str(),
"%04d-%02d-%02d %02d:%02d:%02d",
176 &m_tm.tm_year, &m_tm.tm_mon, &m_tm.tm_mday,
177 &m_tm.tm_hour, &m_tm.tm_min, &m_tm.tm_sec);
180 if (m_tm.tm_year > 9999 || m_tm.tm_year < 1900) {
181 throw(std::runtime_error(
"Year out of bounds"));
182 }
else if (m_tm.tm_mon > 12 || m_tm.tm_mon < 1) {
183 throw(std::runtime_error(
"Month out of bounds"));
184 }
else if (m_tm.tm_mday > 31 || m_tm.tm_mday < 1) {
185 throw(std::runtime_error(
"Day out of bounds"));
186 }
else if (m_tm.tm_hour > 23 || m_tm.tm_mday < 0) {
187 throw(std::runtime_error(
"Hour out of bounds"));
188 }
else if (m_tm.tm_min > 59 || m_tm.tm_min < 0) {
189 throw(std::runtime_error(
"Minute out of bounds"));
190 }
else if (m_tm.tm_sec > 59 || m_tm.tm_sec < 0) {
191 throw(std::runtime_error(
"Day out of bounds"));
194 if (m_tm.tm_year >= 2038) {
197 if (m_tm.tm_mon > 1) {
200 if (m_tm.tm_mday > 19) {
203 if (m_tm.tm_hour > 3) {
206 if (m_tm.tm_min > 14) {
209 if (m_tm.tm_sec > 7) {
213 m_tm.tm_year -= 1900;
215 }
catch (std::runtime_error &e) {
217 string msg(
"Tm::setToString(): ");
218 msg.append(e.what());
219 throw(std::runtime_error(msg));
225 cout <<
"=== dumpTm() ===" << endl;
226 cout <<
"tm_year " << m_tm.tm_year << endl;
227 cout <<
"tm_mon " << m_tm.tm_mon << endl;
228 cout <<
"tm_mday " << m_tm.tm_mday << endl;
229 cout <<
"tm_hour " << m_tm.tm_hour << endl;
230 cout <<
"tm_min " << m_tm.tm_min << endl;
231 cout <<
"tm_sec " << m_tm.tm_sec << endl;
232 cout <<
"tm_yday " << m_tm.tm_yday << endl;
233 cout <<
"tm_wday " << m_tm.tm_wday << endl;
234 cout <<
"tm_isdst " << m_tm.tm_isdst << endl;
235 cout <<
"================" << endl;
void setToCurrentLocalTime()
void setToCurrentGMTime()
uint64_t microsTime() const
void setToMicrosTime(uint64_t micros)
void setToString(const std::string s)
void setToGMTime(time_t t)
unsigned long long uint64_t
void setToLocalTime(time_t t)