forked from fmtlib/fmt
Don't error on min time_point
This commit is contained in:
@@ -2155,27 +2155,26 @@ struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
|
|||||||
template <typename FormatContext>
|
template <typename FormatContext>
|
||||||
auto format(std::chrono::time_point<std::chrono::system_clock, Duration> val,
|
auto format(std::chrono::time_point<std::chrono::system_clock, Duration> val,
|
||||||
FormatContext& ctx) const -> decltype(ctx.out()) {
|
FormatContext& ctx) const -> decltype(ctx.out()) {
|
||||||
|
std::tm tm = gmtime(val);
|
||||||
using period = typename Duration::period;
|
using period = typename Duration::period;
|
||||||
if (detail::const_check(
|
if (detail::const_check(
|
||||||
period::num != 1 || period::den != 1 ||
|
period::num == 1 && period::den == 1 &&
|
||||||
std::is_floating_point<typename Duration::rep>::value)) {
|
!std::is_floating_point<typename Duration::rep>::value)) {
|
||||||
const auto epoch = val.time_since_epoch();
|
return formatter<std::tm, Char>::format(tm, ctx);
|
||||||
auto subsecs = detail::fmt_duration_cast<Duration>(
|
}
|
||||||
|
Duration epoch = val.time_since_epoch();
|
||||||
|
Duration subsecs = detail::fmt_duration_cast<Duration>(
|
||||||
epoch - detail::fmt_duration_cast<std::chrono::seconds>(epoch));
|
epoch - detail::fmt_duration_cast<std::chrono::seconds>(epoch));
|
||||||
|
|
||||||
if (subsecs.count() < 0) {
|
if (subsecs.count() < 0) {
|
||||||
auto second =
|
auto second =
|
||||||
detail::fmt_duration_cast<Duration>(std::chrono::seconds(1));
|
detail::fmt_duration_cast<Duration>(std::chrono::seconds(1));
|
||||||
if (epoch.count() < ((Duration::min)() + second).count())
|
if (tm.tm_sec != 0)
|
||||||
FMT_THROW(format_error("duration is too small"));
|
--tm.tm_sec;
|
||||||
subsecs += second;
|
else
|
||||||
val -= second;
|
tm = gmtime(val - second);
|
||||||
|
subsecs += detail::fmt_duration_cast<Duration>(std::chrono::seconds(1));
|
||||||
}
|
}
|
||||||
|
return formatter<std::tm, Char>::do_format(tm, ctx, &subsecs);
|
||||||
return formatter<std::tm, Char>::do_format(gmtime(val), ctx, &subsecs);
|
|
||||||
}
|
|
||||||
|
|
||||||
return formatter<std::tm, Char>::format(gmtime(val), ctx);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user