#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 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 {};
}
auto print_tm(const string& text, const std::tm& value, cap c) {
if (c == cap::title)
console::out
<< "┌──────────────────────────────────┬────────────┬──────────────────────────────────────────┐" << environment::new_line
<< "│ tm │ format │ representation │" << environment::new_line
<< "├──────────────────────────────────┼────────────┼──────────────────────────────────────────┤" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {} │ " << string::format(
"{}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:a} │ " << string::format(
"{:a}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:b} │ " << string::format(
"{:b}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:B} │ " << string::format(
"{:B}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:d} │ " << string::format(
"{:d}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:D} │ " << string::format(
"{:D}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:f} │ " << string::format(
"{:f}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:F} │ " << string::format(
"{:F}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:g} │ " << string::format(
"{:g}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:G} │ " << string::format(
"{:G}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:h} │ " << string::format(
"{:h}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:H} │ " << string::format(
"{:H}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:i} │ " << string::format(
"{:i}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:I} │ " << string::format(
"{:I}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:j} │ " << string::format(
"{:j}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:J} │ " << string::format(
"{:J}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:k} │ " << string::format(
"{:k}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:K} │ " << string::format(
"{:K}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:l} │ " << string::format(
"{:l}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:L} │ " << string::format(
"{:L}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:m} │ " << string::format(
"{:m}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:M} │ " << string::format(
"{:M}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:n} │ " << string::format(
"{:n}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:n} │ " << string::format(
"{:N}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:o} │ " << string::format(
"{:o}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:O} │ " << string::format(
"{:O}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:s} │ " << string::format(
"{:s}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:t} │ " << string::format(
"{:t}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:T} │ " << string::format(
"{:T}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:u} │ " << string::format(
"{:u}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:U} │ " << string::format(
"{:U}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:v} │ " << string::format(
"{:v}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:V} │ " << string::format(
"{:V}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:w} │ " << string::format(
"{:w}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:W} │ " << string::format(
"{:W}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:x} │ " << string::format(
"{:x}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:X} │ " << string::format(
"{:X}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:y} │ " << string::format(
"{:y}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:Y} │ " << string::format(
"{:Y}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:z} │ " << string::format(
"{:z}", value).pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(32) <<
" │ {:Z} │ " << string::format(
"{:Z}", 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_tm("0", make_time(), cap::title);
print_tm("make_time(1971, 1, 5)", make_time(1971, 1, 5), cap::middle);
print_tm("make_time(1971, 1, 5, 21, 30, 3)", make_time(1971, 1, 5, 21, 30, 3), cap::middle);
auto now = std::time(nullptr);
print_tm("now", *std::localtime(&now), cap::end);
}