// inspired by show_date_relative() in git's date.c 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& default_ago /* = " ago" */) { string ago = default_ago; int32_t seconds_ago = relative_to_time.sec_since_epoch() - event_time.sec_since_epoch(); if (seconds_ago < 0) { ago = " in the future"; seconds_ago = -seconds_ago; } stringstream result; if (seconds_ago < 90) { result << seconds_ago << " second" << (seconds_ago > 1 ? "s" : "") << ago; return result.str(); } uint32_t minutes_ago = (seconds_ago + 30) / 60; if (minutes_ago < 90) { result << minutes_ago << " minute" << (minutes_ago > 1 ? "s" : "") << ago; return result.str(); } uint32_t hours_ago = (minutes_ago + 30) / 60; if (hours_ago < 90) { result << hours_ago << " hour" << (hours_ago > 1 ? "s" : "") << ago; return result.str(); } uint32_t days_ago = (hours_ago + 12) / 24; if (days_ago < 90) { result << days_ago << " day" << (days_ago > 1 ? "s" : "") << ago; return result.str(); } uint32_t weeks_ago = (days_ago + 3) / 7; if (weeks_ago < 70) { result << weeks_ago << " week" << (weeks_ago > 1 ? "s" : "") << ago; return result.str(); } uint32_t months_ago = (days_ago + 15) / 30; if (months_ago < 12) { result << months_ago << " month" << (months_ago > 1 ? "s" : "") << ago; return result.str(); } uint32_t years_ago = days_ago / 365; result << years_ago << " year" << (months_ago > 1 ? "s " : " "); if (months_ago < 12 * 5) { uint32_t leftover_days = days_ago - (years_ago * 365); uint32_t leftover_months = (leftover_days + 15) / 30; if (leftover_months) result << leftover_months << " month" << (months_ago > 1 ? "s" : ""); } result << ago; return result.str(); }
/// The time when @ref current_feed would expire time_point_sec feed_expiration_time()const { uint32_t current_feed_seconds = current_feed_publication_time.sec_since_epoch(); if( std::numeric_limits<uint32_t>::max() - current_feed_seconds <= options.feed_lifetime_sec ) return time_point_sec::maximum(); else return current_feed_publication_time + options.feed_lifetime_sec; }
time_point_sec get_file_start_time( const time_point_sec& timestamp, const microseconds& interval ) { int64_t interval_seconds = interval.to_seconds(); int64_t file_number = timestamp.sec_since_epoch() / interval_seconds; return time_point_sec( (uint32_t)(file_number * interval_seconds) ); }