Changeset View
Changeset View
Standalone View
Standalone View
src/util/time.cpp
Show First 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | |||||
#ifdef _WIN32 | #ifdef _WIN32 | ||||
gmtime_s(&ts, &time_val); | gmtime_s(&ts, &time_val); | ||||
#else | #else | ||||
gmtime_r(&time_val, &ts); | gmtime_r(&time_val, &ts); | ||||
#endif | #endif | ||||
return strprintf("%04i-%02i-%02i", ts.tm_year + 1900, ts.tm_mon + 1, | return strprintf("%04i-%02i-%02i", ts.tm_year + 1900, ts.tm_mon + 1, | ||||
ts.tm_mday); | ts.tm_mday); | ||||
} | } | ||||
int64_t ParseISO8601DateTime(const std::string &str) { | |||||
static const boost::posix_time::ptime epoch = | |||||
boost::posix_time::from_time_t(0); | |||||
static const std::locale loc( | |||||
std::locale::classic(), | |||||
new boost::posix_time::time_input_facet("%Y-%m-%dT%H:%M:%SZ")); | |||||
std::istringstream iss(str); | |||||
iss.imbue(loc); | |||||
boost::posix_time::ptime ptime(boost::date_time::not_a_date_time); | |||||
iss >> ptime; | |||||
if (ptime.is_not_a_date_time() || epoch > ptime) { | |||||
return 0; | |||||
} | |||||
return (ptime - epoch).total_seconds(); | |||||
} |