38uint64_t
utcMicroseconds(
int year,
int month,
int day,
int hour,
int minute,
int second, int32_t nsec)
40 using namespace std::chrono;
41 const int64_t monthIndex =
static_cast<int64_t
>(year) * 12 + (month - 1);
42 const int64_t normalizedYear = monthIndex / 12 - (monthIndex % 12 < 0 ? 1 : 0);
43 if (normalizedYear <
int(std::chrono::year::min()) || normalizedYear >
int(std::chrono::year::max())) {
46 const auto normalizedMonth =
static_cast<unsigned>((monthIndex % 12 + 12) % 12 + 1);
47 const sys_seconds instant =
48 sys_days(std::chrono::year(
static_cast<int>(normalizedYear)) / std::chrono::month(normalizedMonth) / 1) +
49 days(day - 1) + hours(hour) + minutes(minute) + seconds(second);
50 const auto date = floor<days>(instant);
51 if (date < sys_days(std::chrono::year::min() / January / 1) ||
52 date > sys_days(std::chrono::year::max() / December / 31)) {
55 const int64_t epoch = instant.time_since_epoch().count();
57 static_cast<uint64_t
>(epoch) >
static_cast<uint64_t
>((std::numeric_limits<time_t>::max)())) {
60 return static_cast<uint64_t
>(epoch) * 1000000ULL + nsec / 1000;