3 #include <boost/chrono/system_clocks.hpp>
4 #include <boost/date_time/posix_time/posix_time.hpp>
11 namespace bch = boost::chrono;
20 const auto ptime = boost::posix_time::from_time_t( time_t(
sec_since_epoch() ) );
21 return boost::posix_time::to_iso_string( ptime );
26 const auto ptime = boost::posix_time::from_time_t( time_t(
sec_since_epoch() ) );
27 return boost::posix_time::to_iso_extended_string( ptime );
30 time_point_sec::operator std::string()
const
32 return this->to_iso_string();
37 static boost::posix_time::ptime epoch = boost::posix_time::from_time_t( 0 );
38 boost::posix_time::ptime pt;
39 if( s.size() >= 5 && s.at( 4 ) ==
'-' )
40 pt = boost::date_time::parse_delimited_time<boost::posix_time::ptime>( s,
'T' );
42 pt = boost::posix_time::from_iso_string( s );
46 time_point::operator std::string()
const
72 const std::string& default_ago ) {
75 string ago = default_ago;
79 ago =
" in the future";
80 seconds_ago = -seconds_ago;
85 result << seconds_ago <<
" second" << (seconds_ago > 1 ?
"s" :
"") << ago;
88 uint32_t minutes_ago = (seconds_ago + 30) / 60;
91 result << minutes_ago <<
" minute" << (minutes_ago > 1 ?
"s" :
"") << ago;
94 uint32_t hours_ago = (minutes_ago + 30) / 60;
97 result << hours_ago <<
" hour" << (hours_ago > 1 ?
"s" :
"") << ago;
100 uint32_t days_ago = (hours_ago + 12) / 24;
103 result << days_ago <<
" day" << (days_ago > 1 ?
"s" :
"") << ago;
106 uint32_t weeks_ago = (days_ago + 3) / 7;
109 result << weeks_ago <<
" week" << (weeks_ago > 1 ?
"s" :
"") << ago;
112 uint32_t months_ago = (days_ago + 15) / 30;
115 result << months_ago <<
" month" << (months_ago > 1 ?
"s" :
"") << ago;
118 uint32_t years_ago = days_ago / 365;
119 result << years_ago <<
" year" << (months_ago > 1 ?
"s" :
"");
120 if (months_ago < 12 * 5)
122 uint32_t leftover_days = days_ago - (years_ago * 365);
123 uint32_t leftover_months = (leftover_days + 15) / 30;
125 result << leftover_months <<
" month" << (months_ago > 1 ?
"s" :
"");
132 const std::string& ago ) {
138 output_variant = input_microseconds.
count();