diff options
author | Elichai Turkel <elichai.turkel@gmail.com> | 2019-10-26 21:10:44 +0300 |
---|---|---|
committer | Elichai Turkel <elichai.turkel@gmail.com> | 2019-10-27 01:00:05 +0300 |
commit | 9e2c623be50ee7e586a411923b9ed136acfa2b3f (patch) | |
tree | 811ee6b1a86b8ace053c83b84d2004cab0251e20 /src/util | |
parent | be50469217bd775c4305938634c32e5932f47841 (diff) |
Rename DecodeDumpTime to ParseISO8601DateTime and move to time.cpp
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/time.cpp | 14 | ||||
-rw-r--r-- | src/util/time.h | 1 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/util/time.cpp b/src/util/time.cpp index 2b202ae95f..2afff2626b 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -111,3 +111,17 @@ std::string FormatISO8601Date(int64_t nTime) { #endif return strprintf("%04i-%02i-%02i", ts.tm_year + 1900, ts.tm_mon + 1, 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(); +}
\ No newline at end of file diff --git a/src/util/time.h b/src/util/time.h index c0470a2136..af4390aa1c 100644 --- a/src/util/time.h +++ b/src/util/time.h @@ -48,5 +48,6 @@ T GetTime(); */ std::string FormatISO8601DateTime(int64_t nTime); std::string FormatISO8601Date(int64_t nTime); +int64_t ParseISO8601DateTime(const std::string& str); #endif // BITCOIN_UTIL_TIME_H |