4#include <boost/chrono/system_clocks.hpp>
5#include <boost/date_time/posix_time/posix_time.hpp>
12 namespace bch = boost::chrono;
24 const auto ptime = boost::posix_time::from_time_t( time_t(
sec_since_epoch() ) );
25 return boost::posix_time::to_iso_string( ptime );
30 const auto ptime = boost::posix_time::from_time_t( time_t(
sec_since_epoch() ) );
31 return boost::posix_time::to_iso_extended_string( ptime );
36 return this->to_iso_string();
41 static boost::posix_time::ptime epoch = boost::posix_time::from_time_t( 0 );
42 boost::posix_time::ptime pt;
43 if(
s.size() >= 5 &&
s.at( 4 ) ==
'-' )
44 pt = boost::date_time::parse_delimited_time<boost::posix_time::ptime>(
s,
'T' );
46 pt = boost::posix_time::from_iso_string(
s );
52 auto count = elapsed.count();
57 const auto ptime = boost::posix_time::from_time_t(time_t(secs));
58 return boost::posix_time::to_iso_extended_string(ptime) +
"." + padded_ms;
62 auto as_duration = boost::posix_time::microseconds(
count);
63 return boost::posix_time::to_iso_string(as_duration);
69 auto dot =
s.find(
'.' );
70 if( dot == std::string::npos )
73 auto ms =
s.substr( dot );
75 while( ms.size() < 4 ) ms.push_back(
'0');
96 const std::string& default_ago ) {
99 string ago = default_ago;
103 ago =
" in the future";
104 seconds_ago = -seconds_ago;
106 std::stringstream result;
107 if (seconds_ago < 90)
109 result << seconds_ago <<
" second" << (seconds_ago > 1 ?
"s" :
"") << ago;
112 uint32_t minutes_ago = (seconds_ago + 30) / 60;
113 if (minutes_ago < 90)
115 result << minutes_ago <<
" minute" << (minutes_ago > 1 ?
"s" :
"") << ago;
118 uint32_t hours_ago = (minutes_ago + 30) / 60;
121 result << hours_ago <<
" hour" << (hours_ago > 1 ?
"s" :
"") << ago;
124 uint32_t days_ago = (hours_ago + 12) / 24;
127 result << days_ago <<
" day" << (days_ago > 1 ?
"s" :
"") << ago;
130 uint32_t weeks_ago = (days_ago + 3) / 7;
133 result << weeks_ago <<
" week" << (weeks_ago > 1 ?
"s" :
"") << ago;
136 uint32_t months_ago = (days_ago + 15) / 30;
139 result << months_ago <<
" month" << (months_ago > 1 ?
"s" :
"") << ago;
142 uint32_t years_ago = days_ago / 365;
143 result << years_ago <<
" year" << (months_ago > 1 ?
"s" :
"");
144 if (months_ago < 12 * 5)
146 uint32_t leftover_days = days_ago - (years_ago * 365);
147 uint32_t leftover_months = (leftover_days + 15) / 30;
149 result << leftover_months <<
" month" << (months_ago > 1 ?
"s" :
"");
156 const std::string& ago ) {
162 output_variant = input_microseconds.
count();
constexpr int64_t count() const
static fc::time_point fc_now()
fc::string to_iso_string() const
constexpr uint32_t sec_since_epoch() const
static time_point_sec from_iso_string(const fc::string &s)
fc::string to_non_delimited_iso_string() const
constexpr time_point(microseconds e=microseconds())
constexpr const microseconds & time_since_epoch() const
static time_point from_iso_string(const fc::string &s)
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Defines exception's used by fc.
#define FC_RETHROW_EXCEPTIONS(LOG_LEVEL, FORMAT,...)
Catchs all exception's, std::exceptions, and ... and rethrows them after appending the provided log m...
fc::string to_string(double)
constexpr microseconds milliseconds(int64_t s)
string get_approximate_relative_time_string(const time_point_sec &event_time, const time_point_sec &relative_to_time=fc::time_point::now(), const std::string &ago=" ago")
void from_variant(const fc::variant &v, sysio::chain::chain_id_type &cid)
void to_variant(const sysio::chain::shared_public_key &var, fc::variant &vo)
int64_t to_int64(const fc::string &)
unsigned __int64 uint64_t