MCPcopy Create free account
hub / github.com/catboost/catboost / TimeGM

Function TimeGM

util/datetime/systime.cpp:184–207  ·  view source on GitHub ↗

Inverse of gmtime: converts struct tm to time_t, assuming the data in tm is UTC rather than local timezone. This implementation returns the number of seconds since 1970-01-01, converted to time_t. @note this code adopted from http://osdir.com/ml/web.wget.patches/2005-07/msg00010.html Subject: A more robust timegm - msg#00010

Source from the content-addressed store, hash-verified

182//! http://osdir.com/ml/web.wget.patches/2005-07/msg00010.html
183//! Subject: A more robust timegm - msg#00010
184time_t TimeGM(const struct tm* t) {
185 // Only handles years after 1970
186 if (Y_UNLIKELY(t->tm_year < 70)) {
187 return (time_t)-1;
188 }
189
190 int days = 365 * (t->tm_year - 70);
191 // Take into account the leap days between 1970 and YEAR-1
192 days += (t->tm_year - 1 - 68) / 4 - ((t->tm_year - 1) / 100) + ((t->tm_year - 1 + 300) / 400);
193
194 if (Y_UNLIKELY(t->tm_mon < 0 || t->tm_mon >= 12)) {
195 return (time_t)-1;
196 }
197 if (IsLeapYear(1900 + t->tm_year)) {
198 days += MONTH_TO_DAYS_LEAP[t->tm_mon];
199 } else {
200 days += MONTH_TO_DAYS[t->tm_mon];
201 }
202
203 days += t->tm_mday - 1;
204
205 unsigned long secs = days * 86400ul + t->tm_hour * 3600 + t->tm_min * 60 + t->tm_sec;
206 return (time_t)secs;
207}
208
209struct tm* GmTimeR(const time_t* timer, struct tm* tmbuf) {
210 i64 time = static_cast<i64>(*timer);

Callers 7

ToTimeTMethod · 0.85
ToTimeTMethod · 0.85
timegmFunction · 0.85
Y_UNIT_TESTFunction · 0.85
AsTimeTMethod · 0.85
AssertSimpleTMFunction · 0.85
GetStartUTCMethod · 0.85

Calls 1

IsLeapYearFunction · 0.70

Tested by

no test coverage detected