Skip to content

Commit 9e2c623

Browse files
committed
Rename DecodeDumpTime to ParseISO8601DateTime and move to time.cpp
1 parent be50469 commit 9e2c623

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/util/time.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,17 @@ std::string FormatISO8601Date(int64_t nTime) {
111111
#endif
112112
return strprintf("%04i-%02i-%02i", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday);
113113
}
114+
115+
int64_t ParseISO8601DateTime(const std::string& str)
116+
{
117+
static const boost::posix_time::ptime epoch = boost::posix_time::from_time_t(0);
118+
static const std::locale loc(std::locale::classic(),
119+
new boost::posix_time::time_input_facet("%Y-%m-%dT%H:%M:%SZ"));
120+
std::istringstream iss(str);
121+
iss.imbue(loc);
122+
boost::posix_time::ptime ptime(boost::date_time::not_a_date_time);
123+
iss >> ptime;
124+
if (ptime.is_not_a_date_time() || epoch > ptime)
125+
return 0;
126+
return (ptime - epoch).total_seconds();
127+
}

src/util/time.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@ T GetTime();
4848
*/
4949
std::string FormatISO8601DateTime(int64_t nTime);
5050
std::string FormatISO8601Date(int64_t nTime);
51+
int64_t ParseISO8601DateTime(const std::string& str);
5152

5253
#endif // BITCOIN_UTIL_TIME_H

src/wallet/rpcdump.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,10 @@
2323
#include <tuple>
2424

2525
#include <boost/algorithm/string.hpp>
26-
#include <boost/date_time/posix_time/posix_time.hpp>
2726

2827
#include <univalue.h>
2928

3029

31-
int64_t static DecodeDumpTime(const std::string &str) {
32-
static const boost::posix_time::ptime epoch = boost::posix_time::from_time_t(0);
33-
static const std::locale loc(std::locale::classic(),
34-
new boost::posix_time::time_input_facet("%Y-%m-%dT%H:%M:%SZ"));
35-
std::istringstream iss(str);
36-
iss.imbue(loc);
37-
boost::posix_time::ptime ptime(boost::date_time::not_a_date_time);
38-
iss >> ptime;
39-
if (ptime.is_not_a_date_time())
40-
return 0;
41-
return (ptime - epoch).total_seconds();
42-
}
4330

4431
std::string static EncodeDumpString(const std::string &str) {
4532
std::stringstream ret;
@@ -598,7 +585,7 @@ UniValue importwallet(const JSONRPCRequest& request)
598585
continue;
599586
CKey key = DecodeSecret(vstr[0]);
600587
if (key.IsValid()) {
601-
int64_t nTime = DecodeDumpTime(vstr[1]);
588+
int64_t nTime = ParseISO8601DateTime(vstr[1]);
602589
std::string strLabel;
603590
bool fLabel = true;
604591
for (unsigned int nStr = 2; nStr < vstr.size(); nStr++) {
@@ -617,7 +604,7 @@ UniValue importwallet(const JSONRPCRequest& request)
617604
} else if(IsHex(vstr[0])) {
618605
std::vector<unsigned char> vData(ParseHex(vstr[0]));
619606
CScript script = CScript(vData.begin(), vData.end());
620-
int64_t birth_time = DecodeDumpTime(vstr[1]);
607+
int64_t birth_time = ParseISO8601DateTime(vstr[1]);
621608
scripts.push_back(std::pair<CScript, int64_t>(script, birth_time));
622609
}
623610
}

0 commit comments

Comments
 (0)