19 #include <type_traits>
26 #ifndef FMT_USE_LOCAL_TIME
27 # ifdef __cpp_lib_chrono
28 # define FMT_USE_LOCAL_TIME (__cpp_lib_chrono >= 201907L)
30 # define FMT_USE_LOCAL_TIME 0
35 #ifndef FMT_USE_UTC_TIME
36 # ifdef __cpp_lib_chrono
37 # define FMT_USE_UTC_TIME (__cpp_lib_chrono >= 201907L)
39 # define FMT_USE_UTC_TIME 0
46 # if FMT_HAS_INCLUDE("winapifamily.h")
47 # include <winapifamily.h>
49 # if defined(_WIN32) && (!defined(WINAPI_FAMILY) || \
50 (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP))
51 # define FMT_USE_TZSET 1
53 # define FMT_USE_TZSET 0
58 #ifndef FMT_SAFE_DURATION_CAST
59 # define FMT_SAFE_DURATION_CAST 1
61 #if FMT_SAFE_DURATION_CAST
71 template <
typename To,
typename From,
77 using F = std::numeric_limits<From>;
78 using T = std::numeric_limits<To>;
93 return static_cast<To
>(from);
100 template <
typename To,
typename From,
106 using F = std::numeric_limits<From>;
107 using T = std::numeric_limits<To>;
119 from > static_cast<From>(detail::max_value<To>())) {
126 F::digits >= T::digits) &&
127 from > static_cast<From>(detail::max_value<To>())) {
131 return static_cast<To
>(from);
134 template <
typename To,
typename From,
155 template <
typename To,
typename From,
159 using T = std::numeric_limits<To>;
164 if (std::isfinite(from)) {
165 if (from >= T::lowest() && from <= (
T::max)()) {
166 return static_cast<To
>(from);
174 return static_cast<To
>(from);
177 template <
typename To,
typename From,
188 template <
typename To,
typename FromRep,
typename FromPeriod,
193 using From = std::chrono::duration<FromRep, FromPeriod>;
198 : std::ratio_divide<typename From::period, typename To::period> {};
200 static_assert(Factor::num > 0,
"num must be positive");
201 static_assert(Factor::den > 0,
"den must be positive");
207 using IntermediateRep =
208 typename std::common_type<
typename From::rep,
typename To::rep,
209 decltype(Factor::num)>
::type;
212 IntermediateRep
count =
213 lossless_integral_conversion<IntermediateRep>(from.count(), ec);
217 const auto max1 = detail::max_value<IntermediateRep>() / Factor::num;
229 count *= Factor::num;
233 auto tocount = lossless_integral_conversion<typename To::rep>(count, ec);
234 return ec ? To() : To(tocount);
240 template <
typename To,
typename FromRep,
typename FromPeriod,
245 using From = std::chrono::duration<FromRep, FromPeriod>;
247 if (std::isnan(from.count())) {
249 return To{std::numeric_limits<typename To::rep>::quiet_NaN()};
255 if (std::isinf(from.count())) {
256 return To{from.count()};
262 : std::ratio_divide<typename From::period, typename To::period> {};
264 static_assert(Factor::num > 0,
"num must be positive");
265 static_assert(Factor::den > 0,
"den must be positive");
271 using IntermediateRep =
272 typename std::common_type<
typename From::rep,
typename To::rep,
273 decltype(Factor::num)>
::type;
277 IntermediateRep
count =
278 safe_float_conversion<IntermediateRep>(from.count(), ec);
285 constexpr
auto max1 = detail::max_value<IntermediateRep>() /
286 static_cast<IntermediateRep>(Factor::num);
291 constexpr
auto min1 = std::numeric_limits<IntermediateRep>::lowest() /
292 static_cast<IntermediateRep
>(Factor::num);
297 count *=
static_cast<IntermediateRep
>(Factor::num);
303 count /=
static_cast<common_t
>(Factor::den);
307 using ToRep =
typename To::rep;
309 const ToRep tocount = safe_float_conversion<ToRep>(count, ec);
323 template <
typename T =
void>
struct null {};
330 static const auto&
locale = std::locale::classic();
339 template <
typename CodeUnit>
342 template <
typename CodeUnit>
345 #if FMT_CLANG_VERSION
346 # pragma clang diagnostic push
347 # pragma clang diagnostic ignored "-Wdeprecated"
348 auto&
f = std::use_facet<std::codecvt<CodeUnit, char, std::mbstate_t>>(loc);
349 # pragma clang diagnostic pop
351 auto&
f = std::use_facet<std::codecvt<CodeUnit, char, std::mbstate_t>>(loc);
353 auto mb = std::mbstate_t();
354 const char* from_next =
nullptr;
357 if (
result != std::codecvt_base::ok)
361 template <
typename OutputIt>
367 #if FMT_MSC_VERSION != 0 || \
368 (defined(__GLIBCXX__) && !defined(_GLIBCXX_USE_DUAL_ABI))
371 using code_unit = wchar_t;
373 using code_unit = char32_t;
384 return copy_str<char>(u.c_str(), u.c_str() + u.size(), out);
386 return copy_str<char>(
in.data(),
in.data() +
in.size(), out);
389 template <
typename Char,
typename OutputIt,
395 return copy_str<Char>(unit.
buf, unit.
end, out);
398 template <
typename Char,
typename OutputIt,
405 template <
typename Char>
407 const std::locale& loc,
char format,
char modifier) {
409 auto&& os = std::basic_ostream<Char>(&format_buf);
411 using iterator = std::ostreambuf_iterator<Char>;
412 const auto& facet = std::use_facet<std::time_put<Char, iterator>>(loc);
413 auto end = facet.put(os, os, Char(
' '), &time, format, modifier);
417 template <
typename Char,
typename OutputIt,
419 auto write(OutputIt out,
const std::tm&
time,
const std::locale& loc,
420 char format,
char modifier = 0) -> OutputIt {
421 auto&&
buf = get_buffer<Char>(out);
426 template <
typename Char,
typename OutputIt,
428 auto write(OutputIt out,
const std::tm&
time,
const std::locale& loc,
429 char format,
char modifier = 0) -> OutputIt {
449 dispatcher(std::time_t
t) : time_(t) {}
452 using namespace fmt::detail;
453 return handle(localtime_r(&time_, &tm_));
456 bool handle(std::tm* tm) {
return tm !=
nullptr; }
459 using namespace fmt::detail;
463 bool fallback(
int res) {
return res == 0; }
467 using namespace fmt::detail;
470 return tm !=
nullptr;
480 #if FMT_USE_LOCAL_TIME
481 template <
typename Duration>
482 inline auto localtime(std::chrono::local_time<Duration> time) -> std::tm {
483 return localtime(std::chrono::system_clock::to_time_t(
484 std::chrono::current_zone()->to_sys(time)));
493 inline std::tm
gmtime(std::time_t time) {
498 dispatcher(std::time_t
t) : time_(t) {}
501 using namespace fmt::detail;
502 return handle(
gmtime_r(&time_, &tm_));
505 bool handle(std::tm* tm) {
return tm !=
nullptr; }
508 using namespace fmt::detail;
509 return fallback(
gmtime_s(&tm_, &time_));
512 bool fallback(
int res) {
return res == 0; }
518 return tm !=
nullptr;
529 std::chrono::time_point<std::chrono::system_clock> time_point) {
530 return gmtime(std::chrono::system_clock::to_time_t(time_point));
536 template <
typename Char>
540 auto align = align::none;
552 align = align::center;
555 if (align != align::none) {
558 if (
c ==
'}')
return begin;
569 }
else if (p ==
begin) {
582 unsigned c,
char sep) {
583 unsigned long long digits =
594 digits += (((digits * 205) >> 11) & 0x000f00000f00000f) * 6;
596 digits = ((digits & 0x00f00000f00000f0) >> 4) |
597 ((digits & 0x000f00000f00000f) << 8);
598 auto usep =
static_cast<unsigned long long>(sep);
600 digits |= 0x3030003030003030 | (usep << 16) | (usep << 40);
602 constexpr
const size_t len = 8;
605 std::memcpy(tmp, &digits, len);
606 std::reverse_copy(tmp, tmp + len, buf);
608 std::memcpy(buf, &digits, len);
621 if (std::is_same<Period, std::ratio<1>>::
value)
return "s";
630 if (std::is_same<Period, std::ratio<60>>::
value)
return "m";
631 if (std::is_same<Period, std::ratio<3600>>::
value)
return "h";
653 template <
typename OutputIt>
659 template <
typename OutputIt>
666 template <
typename Char,
typename Handler>
670 if (begin == end || *begin ==
'}')
return begin;
681 if (begin !=
ptr) handler.on_text(begin,
ptr);
703 handler.on_text(
ptr - 1,
ptr);
706 const Char newline[] = {
'\n'};
707 handler.on_text(newline, newline + 1);
711 const Char tab[] = {
'\t'};
712 handler.on_text(tab, tab + 1);
726 handler.on_iso_week_based_year();
729 handler.on_iso_week_based_short_year();
733 handler.on_abbr_weekday();
736 handler.on_full_weekday();
747 handler.on_abbr_month();
750 handler.on_full_month();
766 handler.on_day_of_year();
798 handler.on_us_date();
801 handler.on_iso_date();
804 handler.on_12_hour_time();
807 handler.on_24_hour_time();
810 handler.on_iso_time();
816 handler.on_duration_value();
819 handler.on_duration_unit();
825 handler.on_tz_name();
836 handler.on_offset_year();
913 if (begin !=
ptr) handler.on_text(begin,
ptr);
919 static_cast<Derived*
>(
this)->unsupported();
962 template <
typename Char>
1001 static constexpr
const char* full_name_list[] = {
1002 "Sunday",
"Monday",
"Tuesday",
"Wednesday",
1003 "Thursday",
"Friday",
"Saturday"};
1004 return wday >= 0 && wday <= 6 ? full_name_list[wday] :
"?";
1007 static constexpr
const char* short_name_list[] = {
"Sun",
"Mon",
"Tue",
"Wed",
1008 "Thu",
"Fri",
"Sat"};
1009 return wday >= 0 && wday <= 6 ? short_name_list[wday] :
"???";
1013 static constexpr
const char* full_name_list[] = {
1014 "January",
"February",
"March",
"April",
"May",
"June",
1015 "July",
"August",
"September",
"October",
"November",
"December"};
1016 return mon >= 0 && mon <= 11 ? full_name_list[mon] :
"?";
1019 static constexpr
const char* short_name_list[] = {
1020 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
1021 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
1023 return mon >= 0 && mon <= 11 ? short_name_list[mon] :
"???";
1026 template <
typename T,
typename =
void>
1028 template <
typename T>
1030 : std::true_type {};
1032 template <
typename T,
typename =
void>
1034 template <
typename T>
1036 : std::true_type {};
1039 inline void tzset_once() {
1040 static bool init = []() ->
bool {
1065 return n == 0 ? 1 : 10 *
pow10(n - 1);
1071 template <
long long Num,
long long Den,
int N = 0,
1072 bool Enabled = (N < 19) && (Num <= max_value<long long>() / 10)>
1074 static constexpr
int value =
1080 template <
long long Num,
long long Den,
int N>
1082 static constexpr
int value = (Num % Den == 0) ?
N : 6;
1087 template <
typename Char,
typename OutputIt,
typename Duration>
1089 constexpr
auto num_fractional_digits =
1091 Duration::period::den>
::value;
1093 using subsecond_precision = std::chrono::duration<
1094 typename std::common_type<
typename Duration::rep,
1095 std::chrono::seconds::rep>
::type,
1096 std::ratio<1, detail::pow10(num_fractional_digits)>>;
1098 const auto fractional =
1099 d - std::chrono::duration_cast<std::chrono::seconds>(d);
1100 const auto subseconds =
1101 std::chrono::treat_as_floating_point<
1102 typename subsecond_precision::rep>::value
1103 ? fractional.count()
1104 : std::chrono::duration_cast<subsecond_precision>(fractional).
count();
1108 int leading_zeroes = (
std::max)(0, num_fractional_digits - num_digits);
1111 if (std::ratio_less<
typename subsecond_precision::period,
1112 std::chrono::seconds::period>::value) {
1115 out = format_decimal<Char>(out,
n, num_digits).
end;
1121 int remaining =
precision - leading_zeroes;
1122 if (remaining != 0 && remaining < num_digits) {
1124 out = format_decimal<Char>(out,
n, remaining).
end;
1127 out = format_decimal<Char>(out,
n, num_digits).
end;
1128 remaining -= num_digits;
1136 template <
typename Duration>
1138 int num_fractional_digits = -1) {
1139 using rep =
typename Duration::rep;
1142 auto val = duration.count();
1144 if (num_fractional_digits < 0) {
1147 using namespace std;
1148 num_fractional_digits =
1150 Duration::period::den>
::value;
1151 if (num_fractional_digits < 6 && static_cast<rep>(
round(
val)) !=
val)
1152 num_fractional_digits = 6;
1156 std::fmod(
val * static_cast<rep>(Duration::period::num) /
1157 static_cast<rep>(Duration::period::den),
1158 static_cast<rep>(60)),
1159 num_fractional_digits);
1162 template <
typename OutputIt,
typename Char,
1163 typename Duration = std::chrono::seconds>
1166 static constexpr
int days_per_week = 7;
1168 const std::locale& loc_;
1169 const bool is_classic_;
1171 const Duration* subsecs_;
1174 auto tm_sec()
const noexcept ->
int {
1175 FMT_ASSERT(tm_.tm_sec >= 0 && tm_.tm_sec <= 61,
"");
1178 auto tm_min()
const noexcept ->
int {
1179 FMT_ASSERT(tm_.tm_min >= 0 && tm_.tm_min <= 59,
"");
1182 auto tm_hour()
const noexcept ->
int {
1183 FMT_ASSERT(tm_.tm_hour >= 0 && tm_.tm_hour <= 23,
"");
1186 auto tm_mday()
const noexcept ->
int {
1187 FMT_ASSERT(tm_.tm_mday >= 1 && tm_.tm_mday <= 31,
"");
1190 auto tm_mon()
const noexcept ->
int {
1191 FMT_ASSERT(tm_.tm_mon >= 0 && tm_.tm_mon <= 11,
"");
1194 auto tm_year()
const noexcept ->
long long {
return 1900ll + tm_.tm_year; }
1195 auto tm_wday()
const noexcept ->
int {
1196 FMT_ASSERT(tm_.tm_wday >= 0 && tm_.tm_wday <= 6,
"");
1199 auto tm_yday()
const noexcept ->
int {
1200 FMT_ASSERT(tm_.tm_yday >= 0 && tm_.tm_yday <= 365,
"");
1204 auto tm_hour12()
const noexcept ->
int {
1205 const auto h = tm_hour();
1206 const auto z =
h < 12 ?
h :
h - 12;
1207 return z == 0 ? 12 :
z;
1214 auto split_year_lower(
long long year)
const noexcept ->
int {
1215 auto l = year % 100;
1217 return static_cast<int>(l);
1222 auto iso_year_weeks(
long long curr_year)
const noexcept ->
int {
1223 const auto prev_year = curr_year - 1;
1225 (curr_year + curr_year / 4 - curr_year / 100 + curr_year / 400) %
1228 (prev_year + prev_year / 4 - prev_year / 100 + prev_year / 400) %
1230 return 52 + ((curr_p == 4 || prev_p == 3) ? 1 : 0);
1232 auto iso_week_num(
int tm_yday,
int tm_wday)
const noexcept ->
int {
1233 return (tm_yday + 11 - (tm_wday == 0 ? days_per_week : tm_wday)) /
1236 auto tm_iso_week_year()
const noexcept ->
long long {
1237 const auto year = tm_year();
1238 const auto w = iso_week_num(tm_yday(), tm_wday());
1239 if (
w < 1)
return year - 1;
1240 if (
w > iso_year_weeks(year))
return year + 1;
1243 auto tm_iso_week_of_year()
const noexcept ->
int {
1244 const auto year = tm_year();
1245 const auto w = iso_week_num(tm_yday(), tm_wday());
1246 if (
w < 1)
return iso_year_weeks(year - 1);
1247 if (
w > iso_year_weeks(year))
return 1;
1251 void write1(
int value) {
1252 *out_++ =
static_cast<char>(
'0' +
to_unsigned(value) % 10);
1254 void write2(
int value) {
1267 *out_++ =
static_cast<char>(
'0' +
v);
1271 void write_year_extended(
long long year) {
1281 if (width > num_digits) out_ =
std::fill_n(out_, width - num_digits,
'0');
1282 out_ = format_decimal<Char>(out_,
n, num_digits).
end;
1284 void write_year(
long long year) {
1285 if (year >= 0 && year < 10000) {
1286 write2(static_cast<int>(year / 100));
1287 write2(static_cast<int>(year % 100));
1289 write_year_extended(year);
1301 write2(static_cast<int>(offset / 60));
1303 write2(static_cast<int>(offset % 60));
1307 write_utc_offset(tm.tm_gmtoff, ns);
1311 #if defined(_WIN32) && defined(_UCRT)
1316 _get_timezone(&offset);
1319 _get_dstbias(&dstbias);
1322 write_utc_offset(-offset, ns);
1328 std::time_t gt = std::mktime(>m);
1329 std::tm ltm =
gmtime(gt);
1330 std::time_t lt = std::mktime(<m);
1331 long offset = gt - lt;
1332 write_utc_offset(offset, ns);
1337 void format_tz_name_impl(
const T& tm) {
1339 out_ = write_tm_str<Char>(out_, tm.tm_zone, loc_);
1341 format_localized(
'Z');
1344 void format_tz_name_impl(
const T&) {
1345 format_localized(
'Z');
1348 void format_localized(
char format,
char modifier = 0) {
1349 out_ = write<Char>(out_, tm_, loc_,
format, modifier);
1353 tm_writer(
const std::locale& loc, OutputIt out,
const std::tm& tm,
1354 const Duration* subsecs =
nullptr)
1361 OutputIt
out()
const {
return out_; }
1364 out_ = copy_str<Char>(
begin,
end, out_);
1371 format_localized(
'a');
1377 format_localized(
'A');
1381 format_localized(
'w',
'O');
1385 auto wday = tm_wday();
1386 write1(wday == 0 ? days_per_week : wday);
1388 format_localized(
'u',
'O');
1396 format_localized(
'b');
1402 format_localized(
'B');
1440 auto year = tm_year();
1443 if (year >= 0 && year < 10000) {
1447 write_year_extended(year);
1461 return write_year(tm_year());
1462 format_localized(
'Y',
'E');
1466 return write2(split_year_lower(tm_year()));
1467 format_localized(
'y',
'O');
1470 if (is_classic_)
return write2(split_year_lower(tm_year()));
1471 format_localized(
'y',
'E');
1476 auto year = tm_year();
1477 auto upper = year / 100;
1478 if (year >= -99 && year < 0) {
1482 }
else if (upper >= 0 && upper < 100) {
1483 write2(static_cast<int>(upper));
1485 out_ = write<Char>(out_,
upper);
1488 format_localized(
'C',
'E');
1494 return write2(tm_mon() + 1);
1495 format_localized(
'm',
'O');
1500 return write2((tm_yday() + days_per_week - tm_wday()) / days_per_week);
1501 format_localized(
'U',
'O');
1505 auto wday = tm_wday();
1506 write2((tm_yday() + days_per_week -
1507 (wday == 0 ? (days_per_week - 1) : (wday - 1))) /
1510 format_localized(
'W',
'O');
1515 return write2(tm_iso_week_of_year());
1516 format_localized(
'V',
'O');
1521 write2(split_year_lower(tm_iso_week_year()));
1525 auto yday = tm_yday() + 1;
1531 format_localized(
'd',
'O');
1536 const char* d2 =
digits2(mday);
1537 *out_++ = mday < 10 ?
' ' : d2[0];
1540 format_localized(
'e',
'O');
1546 return write2(tm_hour(), pad);
1547 format_localized(
'H',
'O');
1551 return write2(tm_hour12(), pad);
1552 format_localized(
'I',
'O');
1556 return write2(tm_min(), pad);
1557 format_localized(
'M',
'O');
1562 write2(tm_sec(), pad);
1567 if (buf.
size() > 1) {
1572 write_fractional_seconds<Char>(out_, *subsecs_);
1577 format_localized(
'S',
'O');
1590 format_localized(
'r');
1606 *out_++ = tm_hour() < 12 ?
'A' :
'P';
1609 format_localized(
'p');
1619 bool has_precision_integral =
false;
1623 template <
typename Char>
1634 if (has_precision_integral) {
1641 template <
typename T,
1649 return x %
static_cast<T>(
y);
1652 inline T mod(
T x,
int y) {
1667 #if FMT_SAFE_DURATION_CAST
1669 template <
typename To,
typename FromRep,
typename FromPeriod>
1678 template <
typename Rep,
typename Period,
1681 std::chrono::duration<Rep, Period> d) {
1684 #if FMT_SAFE_DURATION_CAST
1685 using CommonSecondsType =
1688 const auto d_as_whole_seconds =
1691 const auto diff = d_as_common - d_as_whole_seconds;
1696 auto s = std::chrono::duration_cast<std::chrono::seconds>(d);
1697 return std::chrono::duration_cast<std::chrono::milliseconds>(d -
s);
1701 template <
typename Char,
typename Rep,
typename OutputIt,
1704 return write<Char>(out,
val);
1707 template <
typename Char,
typename Rep,
typename OutputIt,
1714 return write<Char>(out,
val, specs);
1717 template <
typename Char,
typename OutputIt>
1722 template <
typename OutputIt>
1730 template <
typename Char,
typename Period,
typename OutputIt>
1732 if (
const char*
unit = get_units<Period>())
1735 out = write<Char>(out, Period::num);
1738 out = write<Char>(out, Period::den);
1750 bool has_locale_ =
false;
1753 get_locale(
bool localized, locale_ref loc) : has_locale_(localized) {
1755 ::new (&locale_) std::locale(loc.template get<std::locale>());
1758 if (has_locale_) locale_.~locale();
1760 operator const std::locale&()
const {
1765 template <
typename FormatContext,
typename OutputIt,
typename Rep,
1771 bool localized =
false;
1786 std::chrono::duration<Rep, Period> d)
1789 val(static_cast<
rep>(d.count())),
1791 if (d.count() < 0) {
1798 #if FMT_SAFE_DURATION_CAST
1800 auto tmpval = std::chrono::duration<rep, Period>(
val);
1803 s = std::chrono::duration_cast<
seconds>(
1804 std::chrono::duration<rep, Period>(
val));
1826 Rep
hour()
const {
return static_cast<Rep
>(
mod((
s.count() / 3600), 24)); }
1829 Rep hour =
static_cast<Rep
>(
mod((
s.count() / 3600), 12));
1830 return hour <= 0 ? 12 : hour;
1833 Rep
minute()
const {
return static_cast<Rep
>(
mod((
s.count() / 60), 60)); }
1834 Rep
second()
const {
return static_cast<Rep
>(
mod(
s.count(), 60)); }
1837 auto time = std::tm();
1853 if (
isnan(value))
return write_nan();
1857 if (width > num_digits) {
1860 out = format_decimal<char_type>(out,
n, num_digits).
end;
1867 template <
typename Callback,
typename... Args>
1869 if (
isnan(
val))
return write_nan();
1909 if (handle_nan_inf())
return;
1914 format_tm(time, &tm_writer_type::on_24_hour, ns, pad);
1918 if (handle_nan_inf())
return;
1923 format_tm(time, &tm_writer_type::on_12_hour, ns, pad);
1927 if (handle_nan_inf())
return;
1932 format_tm(time, &tm_writer_type::on_minute, ns, pad);
1936 if (handle_nan_inf())
return;
1944 if (buf.
size() < 2 || buf[1] ==
'.') {
1949 write(second(), 2, pad);
1950 write_fractional_seconds<char_type>(
1951 out, std::chrono::duration<rep, Period>(
val),
precision);
1957 format_tm(time, &tm_writer_type::on_second, ns, pad);
1961 if (handle_nan_inf())
return;
1962 format_tm(
time(), &tm_writer_type::on_12_hour_time);
1966 if (handle_nan_inf()) {
1980 if (handle_nan_inf())
return;
1985 if (handle_nan_inf())
return;
1986 format_tm(
time(), &tm_writer_type::on_am_pm);
1990 if (handle_nan_inf())
return;
1992 out = format_duration_value<char_type>(out,
val,
precision);
1996 out = format_duration_unit<char_type, Period>(out);
2002 #if defined(__cpp_lib_chrono) && __cpp_lib_chrono >= 201907
2003 using weekday = std::chrono::weekday;
2008 unsigned char value;
2011 weekday() =
default;
2013 :
value(static_cast<unsigned char>(wd != 7 ? wd : 0)) {}
2023 bool localized =
false;
2027 -> decltype(ctx.begin()) {
2028 auto begin = ctx.begin(),
end = ctx.end();
2036 template <
typename FormatContext>
2037 auto format(weekday wd, FormatContext& ctx)
const -> decltype(ctx.out()) {
2038 auto time = std::tm();
2039 time.tm_wday =
static_cast<int>(wd.c_encoding());
2040 detail::get_locale loc(localized, ctx.locale());
2041 auto w = detail::tm_writer<decltype(ctx.out()), Char>(loc, ctx.out(),
time);
2042 w.on_abbr_weekday();
2047 template <
typename Rep,
typename Period,
typename Char>
2048 struct formatter<std::chrono::duration<Rep, Period>, Char> {
2055 bool localized =
false;
2057 using duration = std::chrono::duration<Rep, Period>;
2060 struct parse_range {
2075 auto checker = detail::chrono_format_checker();
2076 if (*
begin ==
'.') {
2091 -> decltype(ctx.
begin()) {
2092 auto range = do_parse(ctx);
2098 template <
typename FormatContext>
2099 auto format(
const duration& d, FormatContext& ctx)
const
2100 -> decltype(ctx.out()) {
2101 auto specs_copy = specs;
2103 auto begin = format_str.begin(),
end = format_str.end();
2107 auto out = std::back_inserter(buf);
2108 detail::handle_dynamic_spec<detail::width_checker>(specs_copy.width,
2110 detail::handle_dynamic_spec<detail::precision_checker>(precision_copy,
2111 precision_ref, ctx);
2113 out = detail::format_duration_value<Char>(out, d.count(), precision_copy);
2114 detail::format_duration_unit<Char, Period>(out);
2116 detail::chrono_formatter<FormatContext, decltype(out), Rep, Period>
f(
2118 f.precision = precision_copy;
2119 f.localized = localized;
2127 template <
typename Char,
typename Duration>
2128 struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
2134 template <
typename FormatContext>
2135 auto format(std::chrono::time_point<std::chrono::system_clock, Duration>
val,
2136 FormatContext& ctx)
const -> decltype(ctx.out()) {
2137 using period =
typename Duration::period;
2138 if (period::num != 1 || period::den != 1 ||
2140 const auto epoch =
val.time_since_epoch();
2141 auto subsecs = std::chrono::duration_cast<Duration>(
2142 epoch - std::chrono::duration_cast<std::chrono::seconds>(epoch));
2144 if (subsecs.count() < 0) {
2145 auto second = std::chrono::seconds(1);
2153 gmtime(std::chrono::time_point_cast<std::chrono::seconds>(
val)), ctx,
2158 gmtime(std::chrono::time_point_cast<std::chrono::seconds>(
val)), ctx);
2162 #if FMT_USE_LOCAL_TIME
2163 template <
typename Char,
typename Duration>
2164 struct formatter<std::chrono::local_time<Duration>, Char>
2170 template <
typename FormatContext>
2171 auto format(std::chrono::local_time<Duration>
val, FormatContext& ctx)
const
2172 -> decltype(ctx.out()) {
2173 using period =
typename Duration::period;
2174 if (period::num != 1 || period::den != 1 ||
2176 const auto epoch =
val.time_since_epoch();
2177 const auto subsecs = std::chrono::duration_cast<Duration>(
2178 epoch - std::chrono::duration_cast<std::chrono::seconds>(epoch));
2181 localtime(std::chrono::time_point_cast<std::chrono::seconds>(
val)),
2186 localtime(std::chrono::time_point_cast<std::chrono::seconds>(
val)),
2192 #if FMT_USE_UTC_TIME
2193 template <
typename Char,
typename Duration>
2194 struct formatter<std::chrono::time_point<std::chrono::utc_clock, Duration>,
2196 :
formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
2198 template <
typename FormatContext>
2199 auto format(std::chrono::time_point<std::chrono::utc_clock, Duration>
val,
2200 FormatContext& ctx)
const -> decltype(ctx.out()) {
2202 std::chrono::time_point<std::chrono::system_clock, Duration>,
2203 Char>
::format(std::chrono::utc_clock::to_sys(
val), ctx);
2217 -> decltype(ctx.
begin()) {
2233 template <
typename FormatContext,
typename Duration>
2235 const Duration* subsecs)
const -> decltype(ctx.out()) {
2236 auto specs_copy = specs;
2238 auto out = std::back_inserter(buf);
2239 detail::handle_dynamic_spec<detail::width_checker>(specs_copy.width,
2242 const auto loc_ref = ctx.locale();
2243 detail::get_locale loc(static_cast<bool>(loc_ref), loc_ref);
2245 detail::tm_writer<decltype(out), Char, Duration>(loc, out, tm, subsecs);
2253 -> decltype(ctx.
begin()) {
2254 return this->do_parse(ctx);
2257 template <
typename FormatContext>
2258 auto format(
const std::tm& tm, FormatContext& ctx)
const
2259 -> decltype(ctx.out()) {
2260 return do_format<FormatContext, std::chrono::seconds>(tm, ctx,
nullptr);
2267 #endif // FMT_CHRONO_H_
FMT_CONSTEXPR void on_iso_week_based_short_year()
FMT_NORETURN FMT_API void throw_format_error(const char *message)
FMT_CONSTEXPR void on_day_of_month(numeric_system)
#define FMT_ENABLE_IF(...)
FMT_CONSTEXPR void on_am_pm()
GLenum GLuint GLenum GLsizei const GLchar * buf
std::string upper(string_view a)
Return an all-upper case version of a (locale-independent).
FMT_CONSTEXPR To lossless_integral_conversion(const From from, int &ec)
SYS_API double fmod(double x, double y)
void on_dec0_week_of_year(numeric_system ns)
void write_fractional_seconds(OutputIt &out, Duration d, int precision=-1)
FMT_BEGIN_DETAIL_NAMESPACE FMT_CONSTEXPR auto parse_align(const Char *begin, const Char *end, format_specs< Char > &specs) -> const Char *
bool_constant< is_integral< T >::value &&!std::is_same< T, bool >::value &&!std::is_same< T, char >::value &&!std::is_same< T, wchar_t >::value > is_integer
constexpr weekday(unsigned wd) noexcept
OutputIt format_duration_value(OutputIt out, Rep val, int)
void write_digit2_separated(char *buf, unsigned a, unsigned b, unsigned c, char sep)
void on_century(numeric_system ns)
FMT_CONSTEXPR void on_text(const Char *begin, const Char *end)
FMT_CONSTEXPR auto data() noexcept-> T *
FMT_INLINE auto end() noexcept-> T *
T negative(const T &val)
Return the unary negation of the given value.
FMT_CONSTEXPR void on_duration_value()
GT_API const UT_StringHolder time
typename std::conditional< B, T, F >::type conditional_t
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
To safe_duration_cast(std::chrono::duration< FromRep, FromPeriod > from, int &ec)
void on_dec1_week_of_year(numeric_system ns)
FMT_CONSTEXPR void ignore_unused(const T &...)
GLsizei const GLfloat * value
FMT_CONSTEXPR void on_tz_name()
FMT_INLINE auto begin() noexcept-> T *
tm_writer(const std::locale &loc, OutputIt out, const std::tm &tm, const Duration *subsecs=nullptr)
GLdouble GLdouble GLdouble z
auto write_encoded_tm_str(OutputIt out, string_view in, const std::locale &loc) -> OutputIt
FMT_CONSTEXPR void on_12_hour_time()
void write_floating_seconds(memory_buffer &buf, Duration duration, int num_fractional_digits=-1)
FMT_CONSTEXPR const char * get_units()
const std::locale & get_classic_locale()
std::tm gmtime(std::time_t time)
GLboolean GLboolean GLboolean GLboolean a
void on_second(numeric_system ns, pad_type pad)
FMT_CONSTEXPR auto to_unsigned(Int value) -> typename std::make_unsigned< Int >::type
auto c_str() const -> const wchar_t *
get_locale(bool localized, locale_ref loc)
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
void on_loc_date(numeric_system ns)
void on_year(numeric_system ns)
typename std::make_unsigned< T >::type type
ImageBuf OIIO_API checker(int width, int height, int depth, cspan< float > color1, cspan< float > color2, int xoffset, int yoffset, int zoffset, ROI roi, int nthreads=0)
**But if you need a result
FMT_CONSTEXPR void on_year(numeric_system)
FMT_CONSTEXPR void on_day_of_year()
FMT_CONSTEXPR auto fill_n(OutputIt out, Size count, const T &value) -> OutputIt
void on_minute(numeric_system ns, pad_type pad)
static constexpr const size_t max_size
FMT_CONSTEXPR void on_abbr_month()
FMT_CONSTEXPR void on_full_month()
constexpr auto in(type t, int set) -> bool
FMT_CONSTEXPR void on_iso_date()
FMT_INLINE auto get_iterator(Buf &buf, OutputIt) -> decltype(buf.out())
#define FMT_END_NAMESPACE
FMT_CONSTEXPR auto parse_precision(const Char *begin, const Char *end, int &value, arg_ref< Char > &ref, basic_format_parse_context< Char > &ctx) -> const Char *
basic_string_view< char > string_view
constexpr auto end() const noexcept-> iterator
FMT_CONSTEXPR void on_loc_date(numeric_system)
FMT_CONSTEXPR void on_iso_week_based_year()
FMT_CONSTEXPR void on_second(numeric_system)
FMT_CONSTEXPR void on_dec1_week_of_year(numeric_system)
FMT_CONSTEXPR void on_24_hour(numeric_system)
Int to_nonnegative_int(T value, Int upper)
OutputIt copy_unit(string_view unit, OutputIt out, Char)
const char * tm_wday_full_name(int wday)
void write_codecvt(codecvt_result< CodeUnit > &out, string_view in_buf, const std::locale &loc)
constexpr auto end() const noexcept-> iterator
const char * tm_mon_full_name(int mon)
FMT_CONSTEXPR void on_duration_unit()
FMT_CONSTEXPR void on_iso_time()
const char * tm_mon_short_name(int mon)
auto size() const -> size_t
FMT_CONSTEXPR void on_dec1_weekday(numeric_system)
FMT_CONSTEXPR void on_iso_week_of_year(numeric_system)
GLint GLint GLsizei GLint GLenum format
void on_iso_week_of_year(numeric_system ns)
FMT_CONSTEXPR auto parse_align(char c) -> align_t
FMT_CONSTEXPR void on_abbr_weekday()
FMT_CONSTEXPR void on_24_hour_time()
FMT_CONSTEXPR void on_utc_offset(numeric_system)
FMT_CONSTEXPR auto code_point_length(const Char *begin) -> int
void on_loc_time(numeric_system ns)
png_const_structrp png_const_inforp int * unit
FMT_CONSTEXPR void on_dec0_weekday(numeric_system)
OutputIt format_duration_unit(OutputIt out)
constexpr auto size() const noexcept-> size_t
vfloat4 round(const vfloat4 &a)
GLboolean GLboolean GLboolean b
void on_24_hour(numeric_system ns, pad_type pad)
FMT_CONSTEXPR void on_full_weekday()
FMT_CONSTEXPR void on_minute(numeric_system)
void on_dec0_weekday(numeric_system ns)
FMT_CONSTEXPR void on_day_of_month_space(numeric_system)
FMT_CONSTEXPR void unsupported()
FMT_CONSTEXPR void on_dec0_week_of_year(numeric_system)
FMT_CONSTEXPR void on_12_hour(numeric_system)
void on_short_year(numeric_system ns)
GLenum GLint GLint * precision
FMT_CONSTEXPR void on_short_year(numeric_system)
null localtime_r FMT_NOMACRO(...)
GLfloat GLfloat GLfloat GLfloat h
FMT_CONSTEXPR To safe_float_conversion(const From from, int &ec)
FMT_CONSTEXPR void on_loc_time(numeric_system)
std::integral_constant< bool, std::numeric_limits< T >::is_signed||std::is_same< T, int128_opt >::value > is_signed
FMT_CONSTEXPR const Char * parse_chrono_format(const Char *begin, const Char *end, Handler &&handler)
typename pvt::make_void< Ts...>::type void_t
void on_dec1_weekday(numeric_system ns)
void on_iso_week_based_year()
FMT_CONSTEXPR auto parse_dynamic_spec(const Char *begin, const Char *end, int &value, arg_ref< Char > &ref, basic_format_parse_context< Char > &ctx) -> const Char *
FMT_CONSTEXPR void on_century(numeric_system)
auto write_tm_str(OutputIt out, string_view sv, const std::locale &loc) -> OutputIt
void on_day_of_month(numeric_system ns)
void do_write(buffer< Char > &buf, const std::tm &time, const std::locale &loc, char format, char modifier)
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GA_API const UT_StringHolder N
FMT_INLINE auto format_to(OutputIt out, format_string< T...> fmt, T &&...args) -> OutputIt
void on_iso_week_based_short_year()
void on_day_of_month_space(numeric_system ns)
**If you just want to fire and args
auto write_padding(OutputIt out, pad_type pad, int width) -> OutputIt
constexpr unsigned c_encoding() const noexcept
To fmt_safe_duration_cast(std::chrono::duration< FromRep, FromPeriod > from)
auto write(OutputIt out, const std::tm &time, const std::locale &loc, char format, char modifier=0) -> OutputIt
FMT_CONSTEXPR void on_offset_year()
GLubyte GLubyte GLubyte GLubyte w
FMT_CONSTEXPR void on_datetime(numeric_system)
FMT_CONSTEXPR void on_dec_month(numeric_system)
FMT_CONSTEXPR auto is_utf8() -> bool
constexpr long long pow10(std::uint32_t n)
constexpr auto begin() const noexcept-> iterator
#define FMT_ASSERT(condition, message)
#define FMT_BEGIN_NAMESPACE
constexpr auto to_ascii(Char c) -> char
constexpr FMT_INLINE auto const_check(T value) -> T
constexpr auto begin() const noexcept-> iterator
auto is_big_endian() -> bool
const char * tm_wday_short_name(int wday)
void on_dec_month(numeric_system ns)
std::chrono::duration< Rep, std::milli > get_milliseconds(std::chrono::duration< Rep, Period > d)
bool convert(basic_string_view< WChar > s)
void on_datetime(numeric_system ns)
void on_utc_offset(numeric_system ns)
FMT_BEGIN_EXPORT std::tm localtime(std::time_t time)
void on_12_hour(numeric_system ns, pad_type pad)
FMT_CONSTEXPR void on_us_date()
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.