22 using period = std::ratio<1, 1'000'000>;
23 using duration = std::chrono::duration<rep, period>;
24 using time_point = std::chrono::time_point<aosn_clock>;
25 static constexpr bool is_steady =
false;
27 static constexpr rep f_second = 1000;
28 static constexpr rep f_minute = 60;
29 static constexpr rep f_hour = 60;
30 static constexpr rep f_day = 24;
31 static constexpr rep f_week = 7;
33 static constexpr rep second = f_second;
34 static constexpr rep minute = f_minute * second;
35 static constexpr rep hour = f_hour * minute;
36 static constexpr rep day = f_day * hour;
37 static constexpr rep week = f_week * day;
42 static time_point
now() noexcept
46 GetSystemTimeAsFileTime(&t);
47 return from_system(t);
51 return from_time_t(t);
55 static inline int32_t now_jul(_Out_opt_ uint32_t* hour =
nullptr) noexcept
60 duration tp = from_system(t).time_since_epoch();
63 clock_gettime(CLOCK_REALTIME, &t);
64 duration tp = from_system(t).time_since_epoch();
67 *hour = (uint32_t)(tp.count() % day);
68 return (uint32_t)(tp.count() / day);
71 static int32_t gre2jul(_In_ uint8_t day, _In_ uint8_t month, _In_ int32_t year)
noexcept
83 int32_t ctmp = (ytmp / 100);
84 int32_t dtmp = ytmp - (100 * ctmp);
85 int32_t result1 = 146097L * ctmp / 4;
86 int32_t result2 = (1461 * dtmp) / 4;
87 int32_t result3 = (153 * mtmp + 2) / 5;
89 return (int32_t)result1 + day + result2 + 1721119L + result3;
92 static void jul2gre(_In_ int32_t jul, _Out_opt_ uint8_t* day, _Out_opt_ uint8_t* month, _Out_opt_ int32_t* year)
noexcept
94 int32_t mtmp = jul - 1721119L;
95 int32_t yr = (4 * mtmp - 1) / 146097L;
96 mtmp = 4 * mtmp - 1 - 146097L * yr;
97 int32_t da = mtmp / 4;
98 mtmp = (4 * da + 3) / 1461;
99 da = 4 * da + 3 - 1461 * mtmp;
101 int32_t mo = (5 * da - 3) / 153;
102 da = 5 * da - 3 - 153 * mo;
104 yr = 100 * yr + mtmp;
113 if (day) *day =
static_cast<uint8_t
>(da);
114 if (month) *month =
static_cast<uint8_t
>(mo);
115 if (year) *year = yr;
118 static __time64_t to_time_t(_In_
const time_point& tp)
noexcept
120 return tp.time_since_epoch().count() / second - 210866803200;
123 static time_point from_time_t(_In_ __time64_t t)
noexcept
125 return time_point(duration(((rep)t + 210866803200) * second));
129 static time_point from_system(_In_
const SYSTEMTIME& t)
noexcept
131 return time_point(duration(
132 ((rep)gre2jul((uint8_t)t.wDay, (uint8_t)t.wMonth, (int32_t)t.wYear)) * day +
133 ((rep)t.wHour * hour + (rep)t.wMinute * minute + (rep)t.wSecond * second + t.wMilliseconds)));
136 static time_point from_system(_In_
const FILETIME& t)
noexcept
138 rep x = (((rep)t.dwHighDateTime) << 32) | t.dwLowDateTime;
139 return time_point(duration(x / 10000 + 199222329600000));
142 static time_point from_system(_In_ DATE t)
145 if (!VariantTimeToSystemTime(t, &st))
146 throw std::invalid_argument(
"failed to convert date from VARIANT_DATE");
147 return from_system(st);
150 static time_point from_system(_In_
const struct timespec& t)
noexcept
152 return from_time_t(t.tv_sec) + t.tv_nsec / 1000;
static time_point now() noexcept
Gets current time.
Definition chrono.hpp:42