#include <xtd/console>
#include <xtd/environment>
#include <xtd/format>
#include <chrono>
using namespace std::literals;
enum class cap {title, middle, end};
template <typename type_t, typename period_t = std::ratio<1>>
auto print_duration(const string& text, const std::chrono::duration<type_t, period_t>& value, cap c) {
if (c == cap::title)
console::out
<< "┌────────────────────────────────────────────────────┬────────────┬────────────────────────────┐" << environment::new_line
<< "│ duration │ format │ representation │" << environment::new_line
<< "├────────────────────────────────────────────────────┼────────────┼────────────────────────────┤" << environment::new_line;
console::out <<
"│ " << text.pad_right(50) <<
" │ {} │ " << format(
"{}", value).
pad_right(26) <<
" │" << environment::new_line;
console::out <<
"│ " << text.pad_right(50) <<
" │ {:c} │ " << format(
"{:c}", value).
pad_right(26) <<
" │" << environment::new_line;
console::out <<
"│ " << text.pad_right(50) <<
" │ {:d} │ " << format(
"{:d}", value).
pad_right(26) <<
" │" << environment::new_line;
console::out <<
"│ " << text.pad_right(50) <<
" │ {:D} │ " << format(
"{:D}", value).
pad_right(26) <<
" │" << environment::new_line;
console::out <<
"│ " << text.pad_right(50) <<
" │ {:f} │ " << format(
"{:f}", value).
pad_right(26) <<
" │" << environment::new_line;
console::out <<
"│ " << text.pad_right(50) <<
" │ {:F} │ " << format(
"{:F}", value).
pad_right(26) <<
" │" << environment::new_line;
console::out <<
"│ " << text.pad_right(50) <<
" │ {:g} │ " << format(
"{:g}", value).
pad_right(26) <<
" │" << environment::new_line;
console::out <<
"│ " << text.pad_right(50) <<
" │ {:G} │ " << format(
"{:G}", value).
pad_right(26) <<
" │" << environment::new_line;
console::out <<
"│ " << text.pad_right(50) <<
" │ {:h} │ " << format(
"{:h}", value).
pad_right(26) <<
" │" << environment::new_line;
console::out <<
"│ " << text.pad_right(50) <<
" │ {:H} │ " << format(
"{:H}", value).
pad_right(26) <<
" │" << environment::new_line;
console::out <<
"│ " << text.pad_right(50) <<
" │ {:m} │ " << format(
"{:m}", value).
pad_right(26) <<
" │" << environment::new_line;
console::out <<
"│ " << text.pad_right(50) <<
" │ {:M} │ " << format(
"{:M}", value).
pad_right(26) <<
" │" << environment::new_line;
console::out <<
"│ " << text.pad_right(50) <<
" │ {:n} │ " << format(
"{:n}", value).
pad_right(26) <<
" │" << environment::new_line;
console::out <<
"│ " << text.pad_right(50) <<
" │ {:N} │ " << format(
"{:N}", value).
pad_right(26) <<
" │" << environment::new_line;
console::out <<
"│ " << text.pad_right(50) <<
" │ {:s} │ " << format(
"{:s}", value).
pad_right(26) <<
" │" << environment::new_line;
console::out <<
"│ " << text.pad_right(50) <<
" │ {:S} │ " << format(
"{:S}", value).
pad_right(26) <<
" │" << environment::new_line;
console::out <<
"│ " << text.pad_right(50) <<
" │ {:t} │ " << format(
"{:t}", value).
pad_right(26) <<
" │" << environment::new_line;
console::out <<
"│ " << text.pad_right(50) <<
" │ {:T} │ " << format(
"{:T}", value).
pad_right(26) <<
" │" << environment::new_line;
if (c != cap::end)
console::out << "├────────────────────────────────────────────────────┼────────────┼────────────────────────────┤" << environment::new_line;
else
console::out << "└────────────────────────────────────────────────────┴────────────┴────────────────────────────┘" << environment::new_line;
}
auto main() -> int {
print_duration("std::chrono::nanoseconds {}", std::chrono::nanoseconds {}, cap::title);
print_duration("6h + 3min + 8s", 6h + 3min + 8s, cap::middle);
print_duration("52h + 3min + 32s", 52h + 3min + 2s, cap::middle);
print_duration("24ms + 543ns", 24ms + 543ns, cap::middle);
print_duration("52h + 3min + 2s + 24ms + 543ns", 52h + 3min + 2s + 24ms + 543ns, cap::middle);
print_duration("std::chrono::nanoseconds {int64_object::min_value}", std::chrono::nanoseconds {int64_object::min_value}, cap::middle);
print_duration("std::chrono::nanoseconds {int64_object::max_value}", std::chrono::nanoseconds {int64_object::max_value}, cap::end);
}
basic_string pad_right(xtd::size total_width) const noexcept
Left-aligns the characters in this basic_string, padding with spaces on the right for a specified tot...
Definition basic_string.hpp:1597
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10