mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
Rename DecodeDumpTime to ParseISO8601DateTime and move to time.cpp
This commit is contained in:
parent
be50469217
commit
9e2c623be5
3 changed files with 17 additions and 15 deletions
|
@ -111,3 +111,17 @@ std::string FormatISO8601Date(int64_t nTime) {
|
||||||
#endif
|
#endif
|
||||||
return strprintf("%04i-%02i-%02i", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday);
|
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();
|
||||||
|
}
|
|
@ -48,5 +48,6 @@ T GetTime();
|
||||||
*/
|
*/
|
||||||
std::string FormatISO8601DateTime(int64_t nTime);
|
std::string FormatISO8601DateTime(int64_t nTime);
|
||||||
std::string FormatISO8601Date(int64_t nTime);
|
std::string FormatISO8601Date(int64_t nTime);
|
||||||
|
int64_t ParseISO8601DateTime(const std::string& str);
|
||||||
|
|
||||||
#endif // BITCOIN_UTIL_TIME_H
|
#endif // BITCOIN_UTIL_TIME_H
|
||||||
|
|
|
@ -23,23 +23,10 @@
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
||||||
|
|
||||||
#include <univalue.h>
|
#include <univalue.h>
|
||||||
|
|
||||||
|
|
||||||
int64_t static DecodeDumpTime(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())
|
|
||||||
return 0;
|
|
||||||
return (ptime - epoch).total_seconds();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string static EncodeDumpString(const std::string &str) {
|
std::string static EncodeDumpString(const std::string &str) {
|
||||||
std::stringstream ret;
|
std::stringstream ret;
|
||||||
|
@ -598,7 +585,7 @@ UniValue importwallet(const JSONRPCRequest& request)
|
||||||
continue;
|
continue;
|
||||||
CKey key = DecodeSecret(vstr[0]);
|
CKey key = DecodeSecret(vstr[0]);
|
||||||
if (key.IsValid()) {
|
if (key.IsValid()) {
|
||||||
int64_t nTime = DecodeDumpTime(vstr[1]);
|
int64_t nTime = ParseISO8601DateTime(vstr[1]);
|
||||||
std::string strLabel;
|
std::string strLabel;
|
||||||
bool fLabel = true;
|
bool fLabel = true;
|
||||||
for (unsigned int nStr = 2; nStr < vstr.size(); nStr++) {
|
for (unsigned int nStr = 2; nStr < vstr.size(); nStr++) {
|
||||||
|
@ -617,7 +604,7 @@ UniValue importwallet(const JSONRPCRequest& request)
|
||||||
} else if(IsHex(vstr[0])) {
|
} else if(IsHex(vstr[0])) {
|
||||||
std::vector<unsigned char> vData(ParseHex(vstr[0]));
|
std::vector<unsigned char> vData(ParseHex(vstr[0]));
|
||||||
CScript script = CScript(vData.begin(), vData.end());
|
CScript script = CScript(vData.begin(), vData.end());
|
||||||
int64_t birth_time = DecodeDumpTime(vstr[1]);
|
int64_t birth_time = ParseISO8601DateTime(vstr[1]);
|
||||||
scripts.push_back(std::pair<CScript, int64_t>(script, birth_time));
|
scripts.push_back(std::pair<CScript, int64_t>(script, birth_time));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue