20 using period = std::ratio<1, 1'000'000>;
21 using duration = std::chrono::duration<rep, period>;
22 using time_point = std::chrono::time_point<aosn_clock>;
23 static constexpr bool is_steady =
false;
25 static constexpr rep f_second = 1000;
26 static constexpr rep f_minute = 60;
27 static constexpr rep f_hour = 60;
28 static constexpr rep f_day = 24;
29 static constexpr rep f_week = 7;
31 static constexpr rep second = f_second;
32 static constexpr rep minute = f_minute * second;
33 static constexpr rep hour = f_hour * minute;
34 static constexpr rep day = f_day * hour;
35 static constexpr rep week = f_week * day;
40 static time_point
now() noexcept
44 GetSystemTimeAsFileTime(&t);
45 return from_system(t);
49 return from_time_t(t);
53 static inline int32_t now_jul(_Out_opt_ uint32_t* hour =
nullptr) noexcept
58 duration tp = from_system(t).time_since_epoch();
61 clock_gettime(CLOCK_REALTIME, &t);
62 duration tp = from_system(t).time_since_epoch();
65 *hour = (uint32_t)(tp.count() % day);
66 return (uint32_t)(tp.count() / day);
69 static int32_t gre2jul(_In_ uint8_t day, _In_ uint8_t month, _In_ int32_t year)
noexcept
81 int32_t ctmp = (ytmp / 100);
82 int32_t dtmp = ytmp - (100 * ctmp);
83 int32_t result1 = 146097L * ctmp / 4;
84 int32_t result2 = (1461 * dtmp) / 4;
85 int32_t result3 = (153 * mtmp + 2) / 5;
87 return (int32_t)result1 + day + result2 + 1721119L + result3;
90 static void jul2gre(_In_ int32_t jul, _Out_opt_ uint8_t* day, _Out_opt_ uint8_t* month, _Out_opt_ int32_t* year)
noexcept
92 int32_t mtmp = jul - 1721119L;
93 int32_t yr = (4 * mtmp - 1) / 146097L;
94 mtmp = 4 * mtmp - 1 - 146097L * yr;
95 int32_t da = mtmp / 4;
96 mtmp = (4 * da + 3) / 1461;
97 da = 4 * da + 3 - 1461 * mtmp;
99 int32_t mo = (5 * da - 3) / 153;
100 da = 5 * da - 3 - 153 * mo;
102 yr = 100 * yr + mtmp;
111 if (day) *day =
static_cast<uint8_t
>(da);
112 if (month) *month =
static_cast<uint8_t
>(mo);
113 if (year) *year = yr;
116 static __time64_t to_time_t(_In_
const time_point& tp)
noexcept
118 return tp.time_since_epoch().count() / second - 210866803200;
121 static time_point from_time_t(_In_ __time64_t t)
noexcept
123 return time_point(duration(((rep)t + 210866803200) * second));
127 static time_point from_system(_In_
const SYSTEMTIME& t)
noexcept
129 return time_point(duration(
130 ((rep)gre2jul((uint8_t)t.wDay, (uint8_t)t.wMonth, (int32_t)t.wYear)) * day +
131 ((rep)t.wHour * hour + (rep)t.wMinute * minute + (rep)t.wSecond * second + t.wMilliseconds)));
134 static time_point from_system(_In_
const FILETIME& t)
noexcept
136 rep x = (((rep)t.dwHighDateTime) << 32) | t.dwLowDateTime;
137 return time_point(duration(x / 10000 + 199222329600000));
140 static time_point from_system(_In_ DATE t)
143 if (!VariantTimeToSystemTime(t, &st))
144 throw std::invalid_argument(
"failed to convert date from VARIANT_DATE");
145 return from_system(st);
148 static time_point from_system(_In_
const struct timespec& t)
noexcept
150 return from_time_t(t.tv_sec) + t.tv_nsec / 1000;
static time_point now() noexcept
Gets current time.
Definition chrono.hpp:40