Localize FMT_USE_LOCAL_TIME

This commit is contained in:
Victor Zverovich 2022-12-21 14:51:23 -08:00
parent 8c56919bd2
commit 6a186bcd66

View File

@ -462,7 +462,6 @@ auto write(OutputIt out, const std::tm& time, const std::locale& loc,
FMT_MODULE_EXPORT_BEGIN
#if FMT_USE_LOCAL_TIME
/**
Converts given time since epoch as ``std::time_t`` value into calendar time,
expressed in local time. Unlike ``std::localtime``, this function is
@ -504,10 +503,11 @@ inline std::tm localtime(std::time_t time) {
return lt.tm_;
}
template<class Duration>
inline std::tm localtime(
std::chrono::local_time<Duration> time_point) {
return localtime(std::chrono::system_clock::to_time_t(std::chrono::current_zone()->to_sys(time_point)));
#if FMT_USE_LOCAL_TIME
template <class Duration>
inline auto localtime(std::chrono::local_time<Duration> time) -> std::tm {
return localtime(std::chrono::system_clock::to_time_t(
std::chrono::current_zone()->to_sys(time)));
}
#endif
@ -2124,20 +2124,19 @@ struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
epoch - std::chrono::duration_cast<std::chrono::seconds>(epoch));
return formatter<std::tm, Char>::do_format(
gmtime(std::chrono::time_point_cast<std::chrono::seconds>(val)),
ctx, &subsecs);
gmtime(std::chrono::time_point_cast<std::chrono::seconds>(val)), ctx,
&subsecs);
}
return formatter<std::tm, Char>::format(
gmtime(std::chrono::time_point_cast<std::chrono::seconds>(val)),
ctx);
gmtime(std::chrono::time_point_cast<std::chrono::seconds>(val)), ctx);
}
};
#if FMT_USE_LOCAL_TIME
template <typename Char, typename Duration>
struct formatter<std::chrono::local_time<Duration>,
Char> : formatter<std::tm, Char> {
struct formatter<std::chrono::local_time<Duration>, Char>
: formatter<std::tm, Char> {
FMT_CONSTEXPR formatter() {
basic_string_view<Char> default_specs =
detail::string_literal<Char, '%', 'F', ' ', '%', 'T'>{};
@ -2145,8 +2144,8 @@ struct formatter<std::chrono::local_time<Duration>,
}
template <typename FormatContext>
auto format(std::chrono::local_time<Duration> val,
FormatContext& ctx) const -> decltype(ctx.out()) {
auto format(std::chrono::local_time<Duration> val, FormatContext& ctx) const
-> decltype(ctx.out()) {
using period = typename Duration::period;
if (period::num != 1 || period::den != 1 ||
std::is_floating_point<typename Duration::rep>::value) {