28# if FMT_HAS_INCLUDE("winapifamily.h")
29# include <winapifamily.h>
31# if defined(_WIN32) && (!defined(WINAPI_FAMILY) || \
32 (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP))
33# define FMT_USE_TZSET 1
35# define FMT_USE_TZSET 0
40#ifndef FMT_SAFE_DURATION_CAST
41# define FMT_SAFE_DURATION_CAST 1
43#if FMT_SAFE_DURATION_CAST
53template <
typename To,
typename From,
59 using F = std::numeric_limits<From>;
60 using T = std::numeric_limits<To>;
75 return static_cast<To
>(
from);
82template <
typename To,
typename From,
88 using F = std::numeric_limits<From>;
89 using T = std::numeric_limits<To>;
101 from >
static_cast<From
>(detail::max_value<To>())) {
108 F::digits >= T::digits) &&
109 from >
static_cast<From
>(detail::max_value<To>())) {
113 return static_cast<To
>(
from);
116template <
typename To,
typename From,
137template <
typename To,
typename From,
141 using T = std::numeric_limits<To>;
142 static_assert(std::is_floating_point<From>::value,
"From must be floating");
143 static_assert(std::is_floating_point<To>::value,
"To must be floating");
148 return static_cast<To
>(
from);
156 return static_cast<To
>(
from);
159template <
typename To,
typename From,
163 static_assert(std::is_floating_point<From>::value,
"From must be floating");
170template <
typename To,
typename FromRep,
typename FromPeriod,
175 using From = std::chrono::duration<FromRep, FromPeriod>;
180 : std::ratio_divide<typename From::period, typename To::period> {};
182 static_assert(Factor::num > 0,
"num must be positive");
183 static_assert(Factor::den > 0,
"den must be positive");
189 using IntermediateRep =
190 typename std::common_type<
typename From::rep,
typename To::rep,
191 decltype(Factor::num)>
::type;
194 IntermediateRep
count =
195 lossless_integral_conversion<IntermediateRep>(
from.count(), ec);
199 const auto max1 = detail::max_value<IntermediateRep>() / Factor::num;
206 if (!std::is_unsigned<IntermediateRep>::value &&
count < min1) {
210 count *= Factor::num;
214 auto tocount = lossless_integral_conversion<typename To::rep>(
count, ec);
215 return ec ? To() : To(tocount);
221template <
typename To,
typename FromRep,
typename FromPeriod,
223 FMT_ENABLE_IF(std::is_floating_point<typename To::rep>::value)>
226 using From = std::chrono::duration<FromRep, FromPeriod>;
230 return To{std::numeric_limits<typename To::rep>::quiet_NaN()};
237 return To{
from.count()};
243 : std::ratio_divide<typename From::period, typename To::period> {};
245 static_assert(Factor::num > 0,
"num must be positive");
246 static_assert(Factor::den > 0,
"den must be positive");
252 using IntermediateRep =
253 typename std::common_type<
typename From::rep,
typename To::rep,
254 decltype(Factor::num)>
::type;
258 IntermediateRep
count =
259 safe_float_conversion<IntermediateRep>(
from.count(), ec);
266 constexpr auto max1 = detail::max_value<IntermediateRep>() /
267 static_cast<IntermediateRep
>(Factor::num);
272 constexpr auto min1 = std::numeric_limits<IntermediateRep>::lowest() /
273 static_cast<IntermediateRep
>(Factor::num);
278 count *=
static_cast<IntermediateRep
>(Factor::num);
288 using ToRep =
typename To::rep;
290 const ToRep tocount = safe_float_conversion<ToRep>(
count, ec);
304template <
typename T =
void>
struct null {};
311 static const auto& locale = std::locale::classic();
320template <
typename CodeUnit>
323template <
typename CodeUnit>
325 const std::locale& loc) {
327# pragma clang diagnostic push
328# pragma clang diagnostic ignored "-Wdeprecated"
329 auto& f = std::use_facet<std::codecvt<CodeUnit, char, std::mbstate_t>>(loc);
330# pragma clang diagnostic pop
332 auto& f = std::use_facet<std::codecvt<CodeUnit, char, std::mbstate_t>>(loc);
334 auto mb = std::mbstate_t();
335 const char* from_next =
nullptr;
338 if (
result != std::codecvt_base::ok)
342template <
typename OutputIt>
348#if FMT_MSC_VERSION != 0 || \
349 (defined(__GLIBCXX__) && !defined(_GLIBCXX_USE_DUAL_ABI))
352 using code_unit = wchar_t;
354 using code_unit = char32_t;
362 for (code_unit* p = unit.buf; p != unit.end; ++p) {
364 if (
sizeof(code_unit) == 2 &&
c >= 0xd800 &&
c <= 0xdfff) {
367 if (p == unit.end || (
c & 0xfc00) != 0xd800 ||
368 (*p & 0xfc00) != 0xdc00) {
371 c = (c << 10) + static_cast<uint32_t>(*p) - 0x35fdc00;
374 buf.push_back(
static_cast<char>(
c));
375 }
else if (
c < 0x800) {
376 buf.push_back(
static_cast<char>(0xc0 | (
c >> 6)));
377 buf.push_back(
static_cast<char>(0x80 | (
c & 0x3f)));
378 }
else if ((
c >= 0x800 &&
c <= 0xd7ff) || (
c >= 0xe000 &&
c <= 0xffff)) {
379 buf.push_back(
static_cast<char>(0xe0 | (
c >> 12)));
380 buf.push_back(
static_cast<char>(0x80 | ((
c & 0xfff) >> 6)));
381 buf.push_back(
static_cast<char>(0x80 | (
c & 0x3f)));
382 }
else if (
c >= 0x10000 &&
c <= 0x10ffff) {
383 buf.push_back(
static_cast<char>(0xf0 | (
c >> 18)));
384 buf.push_back(
static_cast<char>(0x80 | ((
c & 0x3ffff) >> 12)));
385 buf.push_back(
static_cast<char>(0x80 | ((
c & 0xfff) >> 6)));
386 buf.push_back(
static_cast<char>(0x80 | (
c & 0x3f)));
391 return copy_str<char>(buf.data(), buf.data() + buf.size(), out);
393 return copy_str<char>(in.data(), in.data() + in.size(), out);
396template <
typename Char,
typename OutputIt,
402 return copy_str<Char>(unit.
buf, unit.
end, out);
405template <
typename Char,
typename OutputIt,
412template <
typename Char>
413inline void do_write(buffer<Char>& buf,
const std::tm& time,
414 const std::locale& loc,
char format,
char modifier) {
416 auto&& os = std::basic_ostream<Char>(&format_buf);
418 using iterator = std::ostreambuf_iterator<Char>;
419 const auto& facet = std::use_facet<std::time_put<Char, iterator>>(loc);
420 auto end = facet.put(os, os, Char(
' '), &time,
format, modifier);
424template <
typename Char,
typename OutputIt,
426auto write(OutputIt out,
const std::tm& time,
const std::locale& loc,
427 char format,
char modifier = 0) -> OutputIt {
428 auto&& buf = get_buffer<Char>(out);
429 do_write<Char>(buf, time, loc,
format, modifier);
433template <
typename Char,
typename OutputIt,
435auto write(OutputIt out,
const std::tm& time,
const std::locale& loc,
436 char format,
char modifier = 0) -> OutputIt {
438 do_write<char>(buf, time, loc,
format, modifier);
456 dispatcher(std::time_t t) : time_(t) {}
459 using namespace fmt::detail;
460 return handle(localtime_r(&time_, &tm_));
463 bool handle(std::tm* tm) {
return tm !=
nullptr; }
466 using namespace fmt::detail;
470 bool fallback(
int res) {
return res == 0; }
474 using namespace fmt::detail;
477 return tm !=
nullptr;
488 std::chrono::time_point<std::chrono::system_clock> time_point) {
489 return localtime(std::chrono::system_clock::to_time_t(time_point));
502 dispatcher(std::time_t t) : time_(t) {}
505 using namespace fmt::detail;
506 return handle(
gmtime_r(&time_, &tm_));
509 bool handle(std::tm* tm) {
return tm !=
nullptr; }
512 using namespace fmt::detail;
513 return fallback(
gmtime_s(&tm_, &time_));
516 bool fallback(
int res) {
return res == 0; }
522 return tm !=
nullptr;
533 std::chrono::time_point<std::chrono::system_clock> time_point) {
534 return gmtime(std::chrono::system_clock::to_time_t(time_point));
543 unsigned c,
char sep) {
544 unsigned long long digits =
545 a | (b << 24) | (static_cast<unsigned long long>(
c) << 48);
555 digits += (((
digits * 205) >> 11) & 0x000f00000f00000f) * 6;
558 ((
digits & 0x000f00000f00000f) << 8);
559 auto usep =
static_cast<unsigned long long>(sep);
561 digits |= 0x3030003030003030 | (usep << 16) | (usep << 40);
563 constexpr const size_t len = 8;
566 std::memcpy(tmp, &
digits, len);
567 std::reverse_copy(tmp, tmp + len, buf);
569 std::memcpy(buf, &
digits, len);
574 if (std::is_same<Period, std::atto>::value)
return "as";
575 if (std::is_same<Period, std::femto>::value)
return "fs";
576 if (std::is_same<Period, std::pico>::value)
return "ps";
577 if (std::is_same<Period, std::nano>::value)
return "ns";
578 if (std::is_same<Period, std::micro>::value)
return "µs";
579 if (std::is_same<Period, std::milli>::value)
return "ms";
580 if (std::is_same<Period, std::centi>::value)
return "cs";
581 if (std::is_same<Period, std::deci>::value)
return "ds";
582 if (std::is_same<Period, std::ratio<1>>
::value)
return "s";
583 if (std::is_same<Period, std::deca>::value)
return "das";
584 if (std::is_same<Period, std::hecto>::value)
return "hs";
585 if (std::is_same<Period, std::kilo>::value)
return "ks";
586 if (std::is_same<Period, std::mega>::value)
return "Ms";
587 if (std::is_same<Period, std::giga>::value)
return "Gs";
588 if (std::is_same<Period, std::tera>::value)
return "Ts";
589 if (std::is_same<Period, std::peta>::value)
return "Ps";
590 if (std::is_same<Period, std::exa>::value)
return "Es";
591 if (std::is_same<Period, std::ratio<60>>
::value)
return "m";
592 if (std::is_same<Period, std::ratio<3600>>
::value)
return "h";
603template <
typename Char,
typename Handler>
615 if (begin !=
ptr) handler.on_text(begin,
ptr);
621 handler.on_text(
ptr - 1,
ptr);
624 const Char newline[] = {
'\n'};
625 handler.on_text(newline, newline + 1);
629 const Char tab[] = {
'\t'};
630 handler.on_text(tab, tab + 1);
644 handler.on_iso_week_based_year();
647 handler.on_iso_week_based_short_year();
651 handler.on_abbr_weekday();
654 handler.on_full_weekday();
665 handler.on_abbr_month();
668 handler.on_full_month();
684 handler.on_day_of_year();
716 handler.on_us_date();
719 handler.on_iso_date();
722 handler.on_12_hour_time();
725 handler.on_24_hour_time();
728 handler.on_iso_time();
734 handler.on_duration_value();
737 handler.on_duration_unit();
740 handler.on_utc_offset();
743 handler.on_tz_name();
754 handler.on_offset_year();
825 if (begin !=
ptr) handler.on_text(begin,
ptr);
874 template <
typename Char>
913 static constexpr const char* full_name_list[] = {
914 "Sunday",
"Monday",
"Tuesday",
"Wednesday",
915 "Thursday",
"Friday",
"Saturday"};
916 return wday >= 0 && wday <= 6 ? full_name_list[wday] :
"?";
919 static constexpr const char* short_name_list[] = {
"Sun",
"Mon",
"Tue",
"Wed",
920 "Thu",
"Fri",
"Sat"};
921 return wday >= 0 && wday <= 6 ? short_name_list[wday] :
"???";
925 static constexpr const char* full_name_list[] = {
926 "January",
"February",
"March",
"April",
"May",
"June",
927 "July",
"August",
"September",
"October",
"November",
"December"};
928 return mon >= 0 && mon <= 11 ? full_name_list[mon] :
"?";
931 static constexpr const char* short_name_list[] = {
932 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
933 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
935 return mon >= 0 && mon <= 11 ? short_name_list[mon] :
"???";
938template <
typename T,
typename =
void>
944template <
typename T,
typename =
void>
951inline void tzset_once() {
952 static bool init = []() ->
bool {
960template <
typename OutputIt,
typename Char>
class tm_writer {
962 static constexpr int days_per_week = 7;
964 const std::locale& loc_;
965 const bool is_classic_;
969 auto tm_sec()
const noexcept ->
int {
970 FMT_ASSERT(tm_.tm_sec >= 0 && tm_.tm_sec <= 61,
"");
973 auto tm_min()
const noexcept ->
int {
974 FMT_ASSERT(tm_.tm_min >= 0 && tm_.tm_min <= 59,
"");
977 auto tm_hour()
const noexcept ->
int {
978 FMT_ASSERT(tm_.tm_hour >= 0 && tm_.tm_hour <= 23,
"");
981 auto tm_mday()
const noexcept ->
int {
982 FMT_ASSERT(tm_.tm_mday >= 1 && tm_.tm_mday <= 31,
"");
985 auto tm_mon()
const noexcept ->
int {
986 FMT_ASSERT(tm_.tm_mon >= 0 && tm_.tm_mon <= 11,
"");
989 auto tm_year()
const noexcept ->
long long {
return 1900ll + tm_.tm_year; }
990 auto tm_wday()
const noexcept ->
int {
991 FMT_ASSERT(tm_.tm_wday >= 0 && tm_.tm_wday <= 6,
"");
994 auto tm_yday()
const noexcept ->
int {
995 FMT_ASSERT(tm_.tm_yday >= 0 && tm_.tm_yday <= 365,
"");
999 auto tm_hour12()
const noexcept ->
int {
1000 const auto h = tm_hour();
1001 const auto z =
h < 12 ?
h :
h - 12;
1002 return z == 0 ? 12 : z;
1009 auto split_year_lower(
long long year)
const noexcept ->
int {
1010 auto l = year % 100;
1012 return static_cast<int>(l);
1017 auto iso_year_weeks(
long long curr_year)
const noexcept ->
int {
1018 const auto prev_year = curr_year - 1;
1020 (curr_year + curr_year / 4 - curr_year / 100 + curr_year / 400) %
1023 (prev_year + prev_year / 4 - prev_year / 100 + prev_year / 400) %
1025 return 52 + ((curr_p == 4 || prev_p == 3) ? 1 : 0);
1027 auto iso_week_num(
int tm_yday,
int tm_wday)
const noexcept ->
int {
1028 return (tm_yday + 11 - (tm_wday == 0 ? days_per_week : tm_wday)) /
1031 auto tm_iso_week_year()
const noexcept ->
long long {
1032 const auto year = tm_year();
1033 const auto w = iso_week_num(tm_yday(), tm_wday());
1034 if (w < 1)
return year - 1;
1035 if (w > iso_year_weeks(year))
return year + 1;
1038 auto tm_iso_week_of_year()
const noexcept ->
int {
1039 const auto year = tm_year();
1040 const auto w = iso_week_num(tm_yday(), tm_wday());
1041 if (w < 1)
return iso_year_weeks(year - 1);
1042 if (w > iso_year_weeks(year))
return 1;
1046 void write1(
int value) {
1049 void write2(
int value) {
1055 void write_year_extended(
long long year) {
1065 if (width > num_digits) out_ =
std::fill_n(out_, width - num_digits,
'0');
1066 out_ = format_decimal<Char>(out_, n, num_digits).end;
1068 void write_year(
long long year) {
1069 if (year >= 0 && year < 10000) {
1070 write2(
static_cast<int>(year / 100));
1071 write2(
static_cast<int>(year % 100));
1073 write_year_extended(year);
1077 void write_utc_offset(
long offset) {
1085 write2(
static_cast<int>(offset / 60));
1086 write2(
static_cast<int>(offset % 60));
1088 template <
typename T, FMT_ENABLE_IF(has_member_data_tm_gmtoff<T>::value)>
1089 void format_utc_offset_impl(
const T& tm) {
1090 write_utc_offset(tm.tm_gmtoff);
1092 template <
typename T, FMT_ENABLE_IF(!has_member_data_tm_gmtoff<T>::value)>
1093 void format_utc_offset_impl(
const T& tm) {
1094#if defined(_WIN32) && defined(_UCRT)
1099 _get_timezone(&offset);
1102 _get_dstbias(&dstbias);
1105 write_utc_offset(-offset);
1108 format_localized(
'z');
1112 template <
typename T, FMT_ENABLE_IF(has_member_data_tm_zone<T>::value)>
1113 void format_tz_name_impl(
const T& tm) {
1115 out_ = write_tm_str<Char>(out_, tm.tm_zone, loc_);
1117 format_localized(
'Z');
1119 template <
typename T, FMT_ENABLE_IF(!has_member_data_tm_zone<T>::value)>
1120 void format_tz_name_impl(
const T&) {
1121 format_localized(
'Z');
1124 void format_localized(
char format,
char modifier = 0) {
1125 out_ = write<Char>(out_, tm_, loc_,
format, modifier);
1135 OutputIt
out()
const {
return out_; }
1138 out_ = copy_str<Char>(begin,
end, out_);
1145 format_localized(
'a');
1151 format_localized(
'A');
1155 format_localized(
'w',
'O');
1159 auto wday = tm_wday();
1160 write1(wday == 0 ? days_per_week : wday);
1162 format_localized(
'u',
'O');
1170 format_localized(
'b');
1176 format_localized(
'B');
1211 out_ = copy_str<Char>(std::begin(buf),
std::end(buf), out_);
1214 auto year = tm_year();
1217 if (year >= 0 && year < 10000) {
1221 write_year_extended(year);
1227 out_ = copy_str<Char>(std::begin(buf) + offset,
std::end(buf), out_);
1235 return write_year(tm_year());
1236 format_localized(
'Y',
'E');
1240 return write2(split_year_lower(tm_year()));
1241 format_localized(
'y',
'O');
1244 if (is_classic_)
return write2(split_year_lower(tm_year()));
1245 format_localized(
'y',
'E');
1250 auto year = tm_year();
1251 auto upper = year / 100;
1252 if (year >= -99 && year < 0) {
1256 }
else if (upper >= 0 && upper < 100) {
1257 write2(
static_cast<int>(upper));
1259 out_ = write<Char>(out_, upper);
1262 format_localized(
'C',
'E');
1268 return write2(tm_mon() + 1);
1269 format_localized(
'm',
'O');
1274 return write2((tm_yday() + days_per_week - tm_wday()) / days_per_week);
1275 format_localized(
'U',
'O');
1279 auto wday = tm_wday();
1280 write2((tm_yday() + days_per_week -
1281 (wday == 0 ? (days_per_week - 1) : (wday - 1))) /
1284 format_localized(
'W',
'O');
1289 return write2(tm_iso_week_of_year());
1290 format_localized(
'V',
'O');
1295 write2(split_year_lower(tm_iso_week_year()));
1299 auto yday = tm_yday() + 1;
1305 format_localized(
'd',
'O');
1310 const char* d2 =
digits2(mday);
1311 *out_++ = mday < 10 ?
' ' : d2[0];
1314 format_localized(
'e',
'O');
1320 format_localized(
'H',
'O');
1324 return write2(tm_hour12());
1325 format_localized(
'I',
'O');
1329 format_localized(
'M',
'O');
1333 format_localized(
'S',
'O');
1341 out_ = copy_str<Char>(std::begin(buf),
std::end(buf), out_);
1345 format_localized(
'r');
1357 out_ = copy_str<Char>(std::begin(buf),
std::end(buf), out_);
1362 *out_++ = tm_hour() < 12 ?
'A' :
'P';
1365 format_localized(
'p');
1377 template <
typename Char>
1391template <
typename T, FMT_ENABLE_IF(std::is_
integral<T>::value)>
1397template <
typename T,
typename Int, FMT_ENABLE_IF(std::is_
integral<T>::value)>
1403 return static_cast<Int
>(
value);
1405template <
typename T,
typename Int, FMT_ENABLE_IF(!std::is_
integral<T>::value)>
1409 return static_cast<Int
>(
value);
1412template <
typename T, FMT_ENABLE_IF(std::is_
integral<T>::value)>
1414 return x %
static_cast<T
>(
y);
1416template <
typename T, FMT_ENABLE_IF(std::is_
floating_po
int<T>::value)>
1417inline T
mod(T x,
int y) {
1423template <typename T, bool INTEGRAL = std::is_integral<T>::value>
1432#if FMT_SAFE_DURATION_CAST
1434template <
typename To,
typename FromRep,
typename FromPeriod>
1437 To to = safe_duration_cast::safe_duration_cast<To>(
from, ec);
1443template <
typename Rep,
typename Period,
1446 std::chrono::duration<Rep, Period> d) {
1449#if FMT_SAFE_DURATION_CAST
1450 using CommonSecondsType =
1451 typename std::common_type<
decltype(d), std::chrono::seconds>
::type;
1452 const auto d_as_common = fmt_safe_duration_cast<CommonSecondsType>(d);
1453 const auto d_as_whole_seconds =
1454 fmt_safe_duration_cast<std::chrono::seconds>(d_as_common);
1456 const auto diff = d_as_common - d_as_whole_seconds;
1458 fmt_safe_duration_cast<std::chrono::duration<Rep, std::milli>>(diff);
1461 auto s = std::chrono::duration_cast<std::chrono::seconds>(d);
1462 return std::chrono::duration_cast<std::chrono::milliseconds>(d - s);
1469template <
long long Num,
long long Den,
int N = 0,
1470 bool Enabled = (N < 19) && (Num <= max_value<long long>() / 10)>
1478template <
long long Num,
long long Den,
int N>
1480 static constexpr int value = (Num % Den == 0) ? N : 6;
1484 return n == 0 ? 1 : 10 *
pow10(n - 1);
1487template <
class Rep,
class Period,
1489constexpr std::chrono::duration<Rep, Period>
abs(
1490 std::chrono::duration<Rep, Period> d) {
1497 return d.count() >= d.zero().count() ? d : -d;
1500template <
class Rep,
class Period,
1502constexpr std::chrono::duration<Rep, Period>
abs(
1503 std::chrono::duration<Rep, Period> d) {
1507template <
typename Char,
typename Rep,
typename OutputIt,
1510 return write<Char>(out, val);
1513template <
typename Char,
typename Rep,
typename OutputIt,
1517 specs.precision = precision;
1520 return write<Char>(out, val, specs);
1523template <
typename Char,
typename OutputIt>
1528template <
typename OutputIt>
1536template <
typename Char,
typename Period,
typename OutputIt>
1538 if (
const char* unit = get_units<Period>())
1541 out = write<Char>(out, Period::num);
1544 out = write<Char>(out, Period::den);
1556 bool has_locale_ =
false;
1561 ::new (&
locale_) std::locale(loc.template get<std::locale>());
1564 if (has_locale_)
locale_.~locale();
1566 operator const std::locale&()
const {
1571template <
typename FormatContext,
typename OutputIt,
typename Rep,
1592 std::chrono::duration<Rep, Period> d)
1597 if (d.count() < 0) {
1604#if FMT_SAFE_DURATION_CAST
1606 auto tmpval = std::chrono::duration<rep, Period>(
val);
1607 s = fmt_safe_duration_cast<seconds>(tmpval);
1609 s = std::chrono::duration_cast<seconds>(
1610 std::chrono::duration<rep, Period>(
val));
1632 Rep
hour()
const {
return static_cast<Rep
>(
mod((
s.count() / 3600), 24)); }
1635 Rep
hour =
static_cast<Rep
>(
mod((
s.count() / 3600), 12));
1639 Rep
minute()
const {
return static_cast<Rep
>(
mod((
s.count() / 60), 60)); }
1640 Rep
second()
const {
return static_cast<Rep
>(
mod(
s.count(), 60)); }
1643 auto time = std::tm();
1664 out = format_decimal<char_type>(
out, n, num_digits).end;
1668 FMT_ASSERT(!std::is_floating_point<typename Duration::rep>::value,
"");
1669 constexpr auto num_fractional_digits =
1671 Duration::period::den>
::value;
1673 using subsecond_precision = std::chrono::duration<
1674 typename std::common_type<
typename Duration::rep,
1675 std::chrono::seconds::rep>
::type,
1677 if (std::ratio_less<
typename subsecond_precision::period,
1678 std::chrono::seconds::period>
::value) {
1681 detail::abs(d) - std::chrono::duration_cast<std::chrono::seconds>(d);
1683 std::chrono::treat_as_floating_point<
1684 typename subsecond_precision::rep>
::value
1685 ? fractional.count()
1686 : std::chrono::duration_cast<subsecond_precision>(fractional)
1691 if (num_fractional_digits > num_digits)
1693 out = format_decimal<char_type>(
out, n, num_digits).end;
1701 template <
typename Callback,
typename... Args>
1773 if (std::is_floating_point<rep>::value) {
1774 constexpr auto num_fractional_digits =
1779 static_cast<rep>(Period::den),
1780 static_cast<rep>(60)),
1781 num_fractional_digits);
1783 if (buf.size() < 2 || buf[1] ==
'.') *
out++ =
'0';
1832 out = format_duration_unit<char_type, Period>(
out);
1838#if defined(__cpp_lib_chrono) && __cpp_lib_chrono >= 201907
1839using weekday = std::chrono::weekday;
1844 unsigned char value;
1849 :
value(
static_cast<unsigned char>(wd != 7 ? wd : 0)) {}
1859 bool localized =
false;
1863 ->
decltype(ctx.begin()) {
1864 auto begin = ctx.begin(),
end = ctx.end();
1865 if (begin !=
end && *begin ==
'L') {
1872 template <
typename FormatContext>
1874 auto time = std::tm();
1875 time.tm_wday =
static_cast<int>(wd.c_encoding());
1876 detail::get_locale loc(localized, ctx.locale());
1877 auto w = detail::tm_writer<
decltype(ctx.out()), Char>(loc, ctx.out(), time);
1878 w.on_abbr_weekday();
1883template <
typename Rep,
typename Period,
typename Char>
1888 using arg_ref_type = detail::arg_ref<Char>;
1889 arg_ref_type width_ref;
1890 arg_ref_type precision_ref;
1891 bool localized =
false;
1893 using duration = std::chrono::duration<Rep, Period>;
1895 struct spec_handler {
1900 template <
typename Id>
FMT_CONSTEXPR arg_ref_type make_arg_ref(Id arg_id) {
1902 return arg_ref_type(arg_id);
1907 return arg_ref_type(arg_id);
1916 f.specs.fill =
fill;
1919 FMT_CONSTEXPR void on_width(
int width) { f.specs.width = width; }
1921 f.precision = _precision;
1925 template <
typename Id>
FMT_CONSTEXPR void on_dynamic_width(Id arg_id) {
1926 f.width_ref = make_arg_ref(arg_id);
1929 template <
typename Id>
FMT_CONSTEXPR void on_dynamic_precision(Id arg_id) {
1930 f.precision_ref = make_arg_ref(arg_id);
1935 struct parse_range {
1942 if (begin ==
end || *begin ==
'}')
return {begin, begin};
1943 spec_handler handler{*
this, ctx, format_str};
1945 if (begin ==
end)
return {begin, begin};
1947 if (begin ==
end)
return {begin, begin};
1948 if (*begin ==
'.') {
1949 if (std::is_floating_point<Rep>::value)
1952 handler.on_error(
"precision not allowed for this argument type");
1954 if (begin !=
end && *begin ==
'L') {
1959 detail::chrono_format_checker());
1960 return {begin,
end};
1965 ->
decltype(ctx.
begin()) {
1966 auto range = do_parse(ctx);
1972 template <
typename FormatContext>
1973 auto format(
const duration& d, FormatContext& ctx)
const
1974 ->
decltype(ctx.out()) {
1975 auto specs_copy = specs;
1976 auto precision_copy = precision;
1977 auto begin = format_str.
begin(),
end = format_str.
end();
1981 auto out = std::back_inserter(buf);
1982 detail::handle_dynamic_spec<detail::width_checker>(specs_copy.width,
1984 detail::handle_dynamic_spec<detail::precision_checker>(precision_copy,
1985 precision_ref, ctx);
1986 if (begin ==
end || *begin ==
'}') {
1987 out = detail::format_duration_value<Char>(out, d.count(), precision_copy);
1988 detail::format_duration_unit<Char, Period>(out);
1990 detail::chrono_formatter<FormatContext,
decltype(out), Rep, Period> f(
1992 f.precision = precision_copy;
1993 f.localized = localized;
2001template <
typename Char,
typename Duration>
2002struct formatter<
std::chrono::time_point<std::chrono::system_clock, Duration>,
2007 this->do_parse(default_specs.
begin(), default_specs.
end());
2010 template <
typename FormatContext>
2011 auto format(std::chrono::time_point<std::chrono::system_clock> val,
2012 FormatContext& ctx)
const ->
decltype(ctx.out()) {
2024 spec spec_ = spec::unknown;
2029 if (begin !=
end && *begin ==
':') ++begin;
2038 ->
decltype(ctx.
begin()) {
2039 auto end = this->do_parse(ctx.
begin(), ctx.
end());
2041 if (specs.
size() == 2 && specs[0] == Char(
'%')) {
2042 if (specs[1] == Char(
'F'))
2043 spec_ = spec::year_month_day;
2044 else if (specs[1] == Char(
'T'))
2045 spec_ = spec::hh_mm_ss;
2050 template <
typename FormatContext>
2051 auto format(
const std::tm& tm, FormatContext& ctx)
const
2052 ->
decltype(ctx.out()) {
2053 const auto loc_ref = ctx.locale();
2054 detail::get_locale loc(
static_cast<bool>(loc_ref), loc_ref);
2055 auto w = detail::tm_writer<
decltype(ctx.out()), Char>(loc, ctx.out(), tm);
2056 if (spec_ == spec::year_month_day)
2058 else if (spec_ == spec::hh_mm_ss)
and restrictions which apply to each piece of software is included later in this file and or inside of the individual applicable source files The disclaimer of warranty in the WPILib license above applies to all code in and nothing in any of the other licenses gives permission to use the names of FIRST nor the names of the WPILib contributors to endorse or promote products derived from this software The following pieces of software have additional or alternate and or Google Inc All rights reserved Redistribution and use in source and binary with or without are permitted provided that the following conditions are this list of conditions and the following disclaimer *Redistributions in binary form must reproduce the above copyright this list of conditions and the following disclaimer in the documentation and or other materials provided with the distribution *Neither the name of Google Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY OR CONSEQUENTIAL WHETHER IN STRICT OR EVEN IF ADVISED OF THE POSSIBILITY OF SUCH January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable from
Definition: ThirdPartyNotices.txt:128
\rst Parsing context consisting of a format string range being parsed and an argument counter for aut...
Definition: core.h:654
FMT_CONSTEXPR void check_arg_id(int id)
Reports an error if using the automatic argument indexing; otherwise switches to the manual indexing.
Definition: core.h:706
constexpr auto end() const noexcept -> iterator
Returns an iterator past the end of the format string range being parsed.
Definition: core.h:681
typename basic_string_view< Char >::iterator iterator
Definition: core.h:663
FMT_CONSTEXPR auto next_arg_id() -> int
Reports an error if using the manual argument indexing; otherwise returns the next argument index and...
Definition: core.h:692
constexpr auto begin() const noexcept -> iterator
Returns an iterator to the beginning of the format string range being parsed.
Definition: core.h:674
\rst A dynamically growing memory buffer for trivially copyable/constructible types with the first SI...
Definition: format.h:819
constexpr auto end() const noexcept -> iterator
Definition: core.h:478
constexpr auto size() const noexcept -> size_t
Returns the string size.
Definition: core.h:475
constexpr auto begin() const noexcept -> iterator
Definition: core.h:477
Definition: chrono.h:1551
get_locale(bool localized, locale_ref loc)
Definition: chrono.h:1559
std::locale locale_
Definition: chrono.h:1554
~get_locale()
Definition: chrono.h:1563
void on_am_pm()
Definition: chrono.h:1360
void on_duration_value()
Definition: chrono.h:1370
void on_datetime(numeric_system ns)
Definition: chrono.h:1179
void on_abbr_weekday()
Definition: chrono.h:1141
void on_dec1_weekday(numeric_system ns)
Definition: chrono.h:1157
tm_writer(const std::locale &loc, OutputIt out, const std::tm &tm)
Definition: chrono.h:1129
void on_minute(numeric_system ns)
Definition: chrono.h:1327
void on_day_of_month_space(numeric_system ns)
Definition: chrono.h:1307
void on_tz_name()
Definition: chrono.h:1231
void on_year(numeric_system ns)
Definition: chrono.h:1233
FMT_CONSTEXPR void on_text(const Char *begin, const Char *end)
Definition: chrono.h:1137
void on_duration_unit()
Definition: chrono.h:1371
void on_iso_time()
Definition: chrono.h:1353
void on_dec_month(numeric_system ns)
Definition: chrono.h:1266
void on_iso_week_based_year()
Definition: chrono.h:1293
void on_loc_time(numeric_system ns)
Definition: chrono.h:1200
void on_offset_year()
Definition: chrono.h:1243
void on_second(numeric_system ns)
Definition: chrono.h:1331
OutputIt out() const
Definition: chrono.h:1135
void on_iso_week_based_short_year()
Definition: chrono.h:1294
void on_dec1_week_of_year(numeric_system ns)
Definition: chrono.h:1277
void on_abbr_month()
Definition: chrono.h:1166
void on_dec0_weekday(numeric_system ns)
Definition: chrono.h:1153
void on_24_hour(numeric_system ns)
Definition: chrono.h:1318
void on_iso_date()
Definition: chrono.h:1213
void on_day_of_year()
Definition: chrono.h:1298
void on_iso_week_of_year(numeric_system ns)
Definition: chrono.h:1287
void on_24_hour_time()
Definition: chrono.h:1348
void on_full_weekday()
Definition: chrono.h:1147
void on_us_date()
Definition: chrono.h:1206
void on_full_month()
Definition: chrono.h:1172
void on_12_hour_time()
Definition: chrono.h:1336
void on_short_year(numeric_system ns)
Definition: chrono.h:1238
void on_dec0_week_of_year(numeric_system ns)
Definition: chrono.h:1272
void on_loc_date(numeric_system ns)
Definition: chrono.h:1194
void on_utc_offset()
Definition: chrono.h:1230
void on_century(numeric_system ns)
Definition: chrono.h:1248
void on_12_hour(numeric_system ns)
Definition: chrono.h:1322
void on_day_of_month(numeric_system ns)
Definition: chrono.h:1303
Definition: format.h:1282
auto size() const -> size_t
Definition: format.h:1289
auto c_str() const -> const wchar_t *
Definition: format.h:1290
Definition: chrono.h:1842
constexpr weekday(unsigned wd) noexcept
Definition: chrono.h:1848
constexpr unsigned c_encoding() const noexcept
Definition: chrono.h:1850
Definition: chrono.h:1853
constexpr FMT_INLINE auto const_check(T value) -> T
Definition: core.h:356
#define FMT_ASSERT(condition, message)
Definition: core.h:369
basic_string_view< char > string_view
Definition: core.h:520
align::type align_t
Definition: core.h:2084
#define FMT_END_DETAIL_NAMESPACE
Definition: core.h:227
#define FMT_MODULE_EXPORT_BEGIN
Definition: core.h:224
FMT_CONSTEXPR auto parse_precision(const Char *begin, const Char *end, Handler &&handler) -> const Char *
Definition: core.h:2484
constexpr auto count() -> size_t
Definition: core.h:1204
#define FMT_CONSTEXPR
Definition: core.h:106
FMT_CONSTEXPR auto parse_width(const Char *begin, const Char *end, Handler &&handler) -> const Char *
Definition: core.h:2450
type
Definition: core.h:575
#define FMT_BEGIN_NAMESPACE
Definition: core.h:214
#define FMT_BEGIN_DETAIL_NAMESPACE
Definition: core.h:226
FMT_BEGIN_DETAIL_NAMESPACE FMT_CONSTEXPR void ignore_unused(const T &...)
Definition: core.h:343
constexpr auto is_utf8() -> bool
Definition: core.h:415
#define FMT_ENABLE_IF(...)
Definition: core.h:335
void void_t
Definition: core.h:1682
FMT_CONSTEXPR auto to_unsigned(Int value) -> typename std::make_unsigned< Int >::type
Definition: core.h:407
#define FMT_NORETURN
Definition: core.h:163
typename std::conditional< B, T, F >::type conditional_t
Definition: core.h:300
#define FMT_END_NAMESPACE
Definition: core.h:217
#define FMT_MODULE_EXPORT_END
Definition: core.h:225
FMT_CONSTEXPR auto parse_align(const Char *begin, const Char *end, Handler &&handler) -> const Char *
Definition: core.h:2367
constexpr common_return_t< T1, T2 > fmod(const T1 x, const T2 y) noexcept
Compile-time remainder of division function.
Definition: fmod.hpp:64
constexpr long long pow10(std::uint32_t n)
Definition: chrono.h:1483
To fmt_safe_duration_cast(std::chrono::duration< FromRep, FromPeriod > from)
Definition: chrono.h:1435
const char * tm_mon_full_name(int mon)
Definition: chrono.h:924
constexpr std::chrono::duration< Rep, Period > abs(std::chrono::duration< Rep, Period > d)
Definition: chrono.h:1489
FMT_CONSTEXPR const Char * parse_chrono_format(const Char *begin, const Char *end, Handler &&handler)
Definition: chrono.h:604
numeric_system
Definition: chrono.h:596
OutputIt copy_unit(string_view unit, OutputIt out, Char)
Definition: chrono.h:1524
OutputIt format_duration_value(OutputIt out, Rep val, int)
Definition: chrono.h:1509
FMT_MODULE_EXPORT_BEGIN std::tm localtime(std::time_t time)
Converts given time since epoch as std::time_t value into calendar time, expressed in local time.
Definition: chrono.h:451
std::chrono::duration< Rep, std::milli > get_milliseconds(std::chrono::duration< Rep, Period > d)
Definition: chrono.h:1445
OutputIt format_duration_unit(OutputIt out)
Definition: chrono.h:1537
const char * tm_wday_full_name(int wday)
Definition: chrono.h:912
std::tm gmtime(std::time_t time)
Converts given time since epoch as std::time_t value into calendar time, expressed in Coordinated Uni...
Definition: chrono.h:497
bool isfinite(T)
Definition: chrono.h:1392
const char * tm_wday_short_name(int wday)
Definition: chrono.h:918
const char * tm_mon_short_name(int mon)
Definition: chrono.h:930
FMT_CONSTEXPR const char * get_units()
Definition: chrono.h:573
T mod(T x, int y)
Definition: chrono.h:1413
Int to_nonnegative_int(T value, Int upper)
Definition: chrono.h:1398
FMT_BEGIN_DETAIL_NAMESPACE void write_digit2_separated(char *buf, unsigned a, unsigned b, unsigned c, char sep)
Definition: chrono.h:542
constexpr common_t< T1, T2 > max(const T1 x, const T2 y) noexcept
Compile-time pairwise maximum function.
Definition: max.hpp:35
constexpr common_t< T1, T2 > min(const T1 x, const T2 y) noexcept
Compile-time pairwise minimum function.
Definition: min.hpp:35
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool() isinf(const bfloat16 &a)
Definition: BFloat16.h:476
const Scalar & y
Definition: MathFunctions.h:821
::uint32_t uint32_t
Definition: Meta.h:56
static EIGEN_DEPRECATED const end_t end
Definition: IndexedViewHelper.h:181
Definition: format-inl.h:32
null gmtime_s(...)
Definition: chrono.h:308
auto write(OutputIt out, const std::tm &time, const std::locale &loc, char format, char modifier=0) -> OutputIt
Definition: chrono.h:426
auto is_big_endian() -> bool
Definition: format.h:307
auto write_encoded_tm_str(OutputIt out, string_view in, const std::locale &loc) -> OutputIt
Definition: chrono.h:343
void do_write(buffer< Char > &buf, const std::tm &time, const std::locale &loc, char format, char modifier)
Definition: chrono.h:413
null localtime_r FMT_NOMACRO(...)
Definition: chrono.h:305
null gmtime_r(...)
Definition: chrono.h:307
OutputIterator copy(const RangeT &range, OutputIterator out)
Definition: ranges.h:26
FMT_CONSTEXPR auto fill_n(OutputIt out, Size count, const T &value) -> OutputIt
Definition: format.h:560
const std::locale & get_classic_locale()
Definition: chrono.h:310
null localtime_s(...)
Definition: chrono.h:306
auto write_tm_str(OutputIt out, string_view sv, const std::locale &loc) -> OutputIt
Definition: chrono.h:398
void write_codecvt(codecvt_result< CodeUnit > &out, string_view in_buf, const std::locale &loc)
Definition: chrono.h:324
Definition: format.h:2563
result
Definition: format.h:2564
typename std::common_type< T... >::type common_t
Definition: gcem_options.hpp:80
To safe_duration_cast(std::chrono::duration< FromRep, FromPeriod > from, int &ec)
safe duration cast between integral durations
Definition: chrono.h:173
FMT_CONSTEXPR To safe_float_conversion(const From from, int &ec)
converts From to To if possible, otherwise ec is set.
Definition: chrono.h:139
FMT_CONSTEXPR To lossless_integral_conversion(const From from, int &ec)
converts From to To, without loss.
Definition: chrono.h:57
Definition: BFloat16.h:88
static constexpr const unit_t< compound_unit< energy::joule, time::seconds > > h(6.626070040e-34)
Planck constant.
static constexpr const unit_t< compound_unit< charge::coulomb, inverse< substance::mol > > > F(N_A *e)
Faraday constant.
static constexpr const velocity::meters_per_second_t c(299792458.0)
Speed of light in vacuum.
Definition: chrono.h:1479
Definition: chrono.h:1471
static constexpr const size_t max_size
Definition: chrono.h:316
CodeUnit * end
Definition: chrono.h:318
CodeUnit buf[max_size]
Definition: chrono.h:317
typename std::make_unsigned< T >::type type
Definition: chrono.h:1429
Definition: chrono.h:1424
T type
Definition: chrono.h:1425
FMT_CONSTEXPR void on_datetime(numeric_system)
Definition: chrono.h:856
FMT_CONSTEXPR void on_offset_year()
Definition: chrono.h:835
FMT_CONSTEXPR void on_full_month()
Definition: chrono.h:844
FMT_CONSTEXPR void on_day_of_month_space(numeric_system)
Definition: chrono.h:851
FMT_CONSTEXPR void on_second(numeric_system)
Definition: chrono.h:855
FMT_CONSTEXPR void on_abbr_month()
Definition: chrono.h:843
FMT_CONSTEXPR void on_dec1_week_of_year(numeric_system)
Definition: chrono.h:847
FMT_CONSTEXPR void on_short_year(numeric_system)
Definition: chrono.h:834
FMT_CONSTEXPR void on_us_date()
Definition: chrono.h:859
FMT_CONSTEXPR void on_am_pm()
Definition: chrono.h:864
FMT_CONSTEXPR void on_dec0_weekday(numeric_system)
Definition: chrono.h:841
FMT_CONSTEXPR void on_abbr_weekday()
Definition: chrono.h:839
FMT_CONSTEXPR void on_utc_offset()
Definition: chrono.h:867
FMT_CONSTEXPR void on_iso_date()
Definition: chrono.h:860
FMT_CONSTEXPR void on_day_of_month(numeric_system)
Definition: chrono.h:850
FMT_CONSTEXPR void on_duration_unit()
Definition: chrono.h:866
FMT_CONSTEXPR void on_24_hour(numeric_system)
Definition: chrono.h:852
FMT_CONSTEXPR void on_dec_month(numeric_system)
Definition: chrono.h:845
FMT_CONSTEXPR void on_dec0_week_of_year(numeric_system)
Definition: chrono.h:846
FMT_CONSTEXPR void on_iso_week_based_year()
Definition: chrono.h:837
FMT_CONSTEXPR void on_12_hour(numeric_system)
Definition: chrono.h:853
FMT_CONSTEXPR void on_full_weekday()
Definition: chrono.h:840
FMT_CONSTEXPR void on_day_of_year()
Definition: chrono.h:849
FMT_CONSTEXPR void unsupported()
Definition: chrono.h:830
FMT_CONSTEXPR void on_duration_value()
Definition: chrono.h:865
FMT_CONSTEXPR void on_12_hour_time()
Definition: chrono.h:861
FMT_CONSTEXPR void on_loc_date(numeric_system)
Definition: chrono.h:857
FMT_CONSTEXPR void on_iso_time()
Definition: chrono.h:863
FMT_CONSTEXPR void on_dec1_weekday(numeric_system)
Definition: chrono.h:842
FMT_CONSTEXPR void on_century(numeric_system)
Definition: chrono.h:836
FMT_CONSTEXPR void on_24_hour_time()
Definition: chrono.h:862
FMT_CONSTEXPR void on_year(numeric_system)
Definition: chrono.h:833
FMT_CONSTEXPR void on_loc_time(numeric_system)
Definition: chrono.h:858
FMT_CONSTEXPR void on_iso_week_based_short_year()
Definition: chrono.h:838
FMT_CONSTEXPR void on_minute(numeric_system)
Definition: chrono.h:854
FMT_CONSTEXPR void on_tz_name()
Definition: chrono.h:868
FMT_CONSTEXPR void on_iso_week_of_year(numeric_system)
Definition: chrono.h:848
auto format(wformat_string< T... > fmt, T &&... args) -> std::wstring
Definition: xchar.h:87
auto format_to(OutputIt out, const S &fmt, Args &&... args) -> OutputIt
Definition: xchar.h:136
auto runtime(wstring_view s) -> basic_runtime< wchar_t >
Definition: xchar.h:36