diff --git a/CMakeLists.txt b/CMakeLists.txt index 708f344..773c804 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,4 +139,5 @@ target_link_libraries(${PROJECT_NAME} pthread unbound unwind + curl dl) diff --git a/src/page.h b/src/page.h index 9918b04..2ba7673 100644 --- a/src/page.h +++ b/src/page.h @@ -2208,27 +2208,28 @@ namespace xmreg { { uint64_t estimated_blk_height {0}; - // first parse the string date into boost's ptime object - dateparser parser {"%Y-%m-%d %H:%M:%S"}; + // first parse the string date sys_seconds and then to timestamp + // since epoch + uint64_t blk_timestamp_utc = parse(search_text).time_since_epoch().count(); - if (parser(search_text)) + if (blk_timestamp_utc) { // seems we have a correct date! // so try to estimate block height from it. - cout << "timestamp: " << xmreg::ptime_to_time_t(parser.pt) << endl; + cout << "timestamp: " << blk_timestamp_utc << endl; - // estimate blockchain height from the start date provided - estimated_blk_height = xmreg::estimate_bc_height(search_text); - - result_html = show_block(estimated_blk_height); - - // nasty check if output is "Cant get" as a sign of - // a not found tx. Later need to think of something better. - if (result_html.find("Cant get") == string::npos) - { - return result_html; - } +// // estimate blockchain height from the start date provided +// estimated_blk_height = xmreg::estimate_bc_height(search_text); +// +// result_html = show_block(estimated_blk_height); +// +// // nasty check if output is "Cant get" as a sign of +// // a not found tx. Later need to think of something better. +// if (result_html.find("Cant get") == string::npos) +// { +// return result_html; +// } } } diff --git a/src/tools.cpp b/src/tools.cpp index a43ef55..d4fea25 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -143,23 +143,14 @@ namespace xmreg return bf::path(remove_trailing_path_separator(path_str)); } - string timestamp_to_str(time_t timestamp, const char* format) { + auto a_time_point = chrono::system_clock::from_time_t(timestamp); + auto utc = date::to_utc_time(chrono::system_clock::from_time_t(timestamp)); + auto sys_time = date::to_sys_time(utc); - const int TIME_LENGTH = 60; - - char str_buff[TIME_LENGTH]; - - tm *tm_ptr; - tm_ptr = localtime(×tamp); - - size_t len; - - len = std::strftime(str_buff, TIME_LENGTH, format, tm_ptr); - - return string(str_buff, len); + return date::format(format, date::floor(sys_time)); } @@ -890,5 +881,21 @@ namespace xmreg return null_pkey; } + date::sys_seconds + parse(const std::string& str, string format) + { + std::istringstream in(str); + date::sys_seconds tp; + in >> date::parse(format, tp); + if (in.fail()) + { + in.clear(); + in.str(str); + in >> date::parse(format, tp); + } + return tp; + } + + } diff --git a/src/tools.h b/src/tools.h index 728d3eb..1475a39 100644 --- a/src/tools.h +++ b/src/tools.h @@ -253,6 +253,9 @@ namespace xmreg public_key get_tx_pub_key_from_received_outs(const transaction &tx); + date::sys_seconds + parse(const std::string& str, string format="%Y-%m-%d %H:%M:%S"); + } #endif //XMREG01_TOOLS_H