6static time_t __make_local_date_time(
struct tm *tm)
noexcept {
return mktime(tm);}
7static time_t __make_utc_date_time(
struct tm *tm)
noexcept {
return _mkgmtime(tm);}
9static time_t __make_local_date_time(
struct tm *tm)
noexcept {
return mktime(tm);}
10static time_t __make_utc_date_time(
struct tm *tm)
noexcept {
return timegm(tm);}
14 enum class date_time_kind {
19 enum class day_of_week {
31 static std::tm create(date_time_kind kind = date_time_kind::local)
noexcept {
return create(min(), kind);}
33 static std::tm create(time_t time, date_time_kind kind = date_time_kind::utc)
noexcept {
return kind == date_time_kind::utc ? to_universal_time(time) : to_local_time(time);}
35 static std::tm create(
const tm& time, date_time_kind kind = date_time_kind::utc)
noexcept {
return kind == date_time_kind::utc ? to_universal_time(time) : to_local_time(time);}
37 static std::tm create(
int year,
int month,
int day, date_time_kind kind = date_time_kind::local)
noexcept {
39 time.tm_year = year - 1900;
40 time.tm_mon = month - 1;
42 time.tm_hour = time.tm_min = time.tm_sec = time.tm_wday = time.tm_yday = 0;
45 time.tm_zone =
nullptr;
46 return create(time, kind);
49 static std::tm create(
int year,
int month,
int day,
int hour,
int minute,
int second, date_time_kind kind = date_time_kind::local)
noexcept {
51 time.tm_year = year - 1900;
52 time.tm_mon = month - 1;
57 time.tm_wday = time.tm_yday = 0;
60 time.tm_zone =
nullptr;
61 return create(time, kind);
65 static std::tm min()
noexcept {
return to_local_time(
static_cast<time_t
>(0));}
66 static std::tm max()
noexcept {
return to_local_time(
static_cast<time_t
>(253402300799));}
68 static std::tm to_local_time(time_t time)
noexcept {
return *std::localtime(&time);}
69 static std::tm to_local_time(
const std::chrono::system_clock::time_point& time)
noexcept {
return to_local_time(std::chrono::system_clock::to_time_t(time));}
70 static std::tm to_local_time(std::tm time)
noexcept {
71 if (time.tm_zone !=
nullptr && std::string(time.tm_zone) ==
"UTC")
return to_local_time(__make_utc_date_time(&time));
72 return to_local_time(__make_local_date_time(&time));
75 static std::tm to_universal_time(time_t time)
noexcept {
return *std::gmtime(&time);}
76 static std::tm to_universal_time(
const std::chrono::system_clock::time_point& time)
noexcept {
return to_universal_time(std::chrono::system_clock::to_time_t(time));}
77 static std::tm to_universal_time(std::tm time)
noexcept {
78 if (time.tm_zone !=
nullptr && std::string(time.tm_zone) !=
"UTC")
return to_universal_time(__make_local_date_time(&time));
79 return to_universal_time(__make_utc_date_time(&time));
82 static std::tm now() {
return to_local_time(std::chrono::system_clock::now());}
84 static std::tm utc_now() {
return to_universal_time(std::chrono::system_clock::now());}
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition system_report.h:17