#include <xtd/xtd>
enum class cap {title, middle, end};
auto make_time(uint32 year, uint32 month, uint32 day, uint32 hour, uint32 minute, uint32 second) {
auto date = std::tm {};
date.tm_year = year - 1900;
date.tm_mon = month - 1;
date.tm_hour = hour;
date.tm_min = minute;
date.tm_sec = second;
return std::mktime(&date);
}
auto make_time(uint32 year, uint32 month, uint32 day) {
return make_time(year, month, day, 0, 0, 0);
}
auto make_time() {
return std::tm {};
}
template<typename clock_t>
auto print_system_clock(const string& text, const std::chrono::time_point<clock_t>& value, cap c) {
if (c == cap::title)
console::out
<< "┌───────────────────────────────────────┬─────────────────────┬──────────────────────────────────────────┐" << environment::new_line
<< "│ system_clock │ format │ representation │" << environment::new_line
<< "├───────────────────────────────────────┼─────────────────────┼──────────────────────────────────────────┤" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {} │ " <<
format(
"{}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:d} │ " <<
format(
"{:d}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:D} │ " <<
format(
"{:D}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:f} │ " <<
format(
"{:f}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:F} │ " <<
format(
"{:F}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:g} │ " <<
format(
"{:g}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:G} │ " <<
format(
"{:G}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:m} │ " <<
format(
"{:m}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:M} │ " <<
format(
"{:M}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:o} │ " <<
format(
"{:o}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:O} │ " <<
format(
"{:O}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:r} │ " <<
format(
"{:r}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:R} │ " <<
format(
"{:R}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:s} │ " <<
format(
"{:s}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:t} │ " <<
format(
"{:t}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:T} │ " <<
format(
"{:T}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:u} │ " <<
format(
"{:u}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:U} │ " <<
format(
"{:U}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:y} │ " <<
format(
"{:y}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:Y} │ " <<
format(
"{:Y}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:h:mm:ss.ff t} │ " <<
format(
"{:h:mm:ss.ff t}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:d MMM yyyy} │ " <<
format(
"{:d MMM yyyy}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:HH:mm:ss.f} │ " <<
format(
"{:HH:mm:ss.f}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:dd MMM HH:mm:ss} │ " <<
format(
"{:dd MMM HH:mm:ss}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:\\Mon\\t\\h\\: M} │ " <<
format(
"{:\\Mon\\t\\h\\: M}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(37) <<
" │ {:HH:mm:ss.ffffzzz} │ " <<
format(
"{:HH:mm:ss.ffffzzz}", value).
pad_right(40) <<
" │" << environment::new_line;
if (c != cap::end)
console::out << "├───────────────────────────────────────┼─────────────────────┼──────────────────────────────────────────┤" << environment::new_line;
else
console::out << "└───────────────────────────────────────┴─────────────────────┴──────────────────────────────────────────┘" << environment::new_line;
}
auto main() -> int {
print_system_clock("0", std::chrono::system_clock::from_time_t(0), cap::title);
print_system_clock("12345678912", std::chrono::system_clock::from_time_t(12345678912), cap::middle);
print_system_clock("make_time(1971, 1, 5)", std::chrono::system_clock::from_time_t(make_time(1971, 1, 5)), cap::middle);
print_system_clock("make_time(1971, 1, 5, 21, 30, 3)", std::chrono::system_clock::from_time_t(make_time(1971, 1, 5, 21, 30, 3)), cap::middle);
print_system_clock("now", std::chrono::system_clock::now(), 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:1037