mirror of
https://git.wownero.com/wownero/onion-wownero-blockchain-explorer.git
synced 2024-08-15 00:33:12 +00:00
timestamp_to_str rewritten to generate UTC time strings
This commit is contained in:
parent
a2c3c575ba
commit
6054c3e691
4 changed files with 40 additions and 28 deletions
|
@ -139,4 +139,5 @@ target_link_libraries(${PROJECT_NAME}
|
|||
pthread
|
||||
unbound
|
||||
unwind
|
||||
curl
|
||||
dl)
|
||||
|
|
31
src/page.h
31
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;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<chrono::seconds>(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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue