53 template<
typename Rep,
typename Period>
54 static std::string
format_timespan(
const std::chrono::duration<Rep, Period>&
span,
bool detailed =
false)
56 if(
span.count() <= 0) {
57 return _(
"timespan^expired");
60 std::vector<t_string> display_text;
61 auto [
years,
months,
weeks,
days, hours, minutes, seconds] = chrono::deconstruct_duration<chrono::years, chrono::months, chrono::weeks, chrono::days, std::chrono::hours, std::chrono::minutes, std::chrono::seconds>(
span);
63 const auto push_description = [&display_text, detailed](
const auto& time_component,
const auto& fmt_singular,
const auto& fmt_plural)
65 auto amount = time_component.count();
82 push_description(
years,
N_n(
"timespan^$num year",
"timespan^$num years" )) &&
83 push_description(
months,
N_n(
"timespan^$num month",
"timespan^$num months" )) &&
84 push_description(
weeks,
N_n(
"timespan^$num week",
"timespan^$num weeks" )) &&
85 push_description(
days,
N_n(
"timespan^$num day",
"timespan^$num days" )) &&
86 push_description(hours,
N_n(
"timespan^$num hour",
"timespan^$num hours" )) &&
87 push_description(minutes,
N_n(
"timespan^$num minute",
"timespan^$num minutes")) &&
88 push_description(seconds,
N_n(
"timespan^$num second",
"timespan^$num seconds"));
#define N_n(String1, String2)
static std::string _(const char *str)
std::chrono::duration< int, std::ratio< 2629746 > > months
std::chrono::duration< int, std::ratio< 31556952 > > years
std::chrono::duration< int, std::ratio< 604800 > > weeks
std::chrono::duration< int, std::ratio< 86400 > > days
static std::string format_timespan(const std::chrono::duration< Rep, Period > &span, bool detailed=false)
Formats a timespan into human-readable text for player authentication functions.
std::string format_conjunct_list(const t_string &empty, const std::vector< t_string > &elems)
Format a conjunctive list.
std::string to_string(const Range &range, const Func &op)