mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-29 00:35:03 +00:00
Localize FMT_USE_LOCAL_TIME
This commit is contained in:
parent
8c56919bd2
commit
6a186bcd66
@ -462,7 +462,6 @@ auto write(OutputIt out, const std::tm& time, const std::locale& loc,
|
|||||||
|
|
||||||
FMT_MODULE_EXPORT_BEGIN
|
FMT_MODULE_EXPORT_BEGIN
|
||||||
|
|
||||||
#if FMT_USE_LOCAL_TIME
|
|
||||||
/**
|
/**
|
||||||
Converts given time since epoch as ``std::time_t`` value into calendar time,
|
Converts given time since epoch as ``std::time_t`` value into calendar time,
|
||||||
expressed in local time. Unlike ``std::localtime``, this function is
|
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_;
|
return lt.tm_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Duration>
|
#if FMT_USE_LOCAL_TIME
|
||||||
inline std::tm localtime(
|
template <class Duration>
|
||||||
std::chrono::local_time<Duration> time_point) {
|
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_point)));
|
return localtime(std::chrono::system_clock::to_time_t(
|
||||||
|
std::chrono::current_zone()->to_sys(time)));
|
||||||
}
|
}
|
||||||
#endif
|
#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));
|
epoch - std::chrono::duration_cast<std::chrono::seconds>(epoch));
|
||||||
|
|
||||||
return formatter<std::tm, Char>::do_format(
|
return formatter<std::tm, Char>::do_format(
|
||||||
gmtime(std::chrono::time_point_cast<std::chrono::seconds>(val)),
|
gmtime(std::chrono::time_point_cast<std::chrono::seconds>(val)), ctx,
|
||||||
ctx, &subsecs);
|
&subsecs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return formatter<std::tm, Char>::format(
|
return formatter<std::tm, Char>::format(
|
||||||
gmtime(std::chrono::time_point_cast<std::chrono::seconds>(val)),
|
gmtime(std::chrono::time_point_cast<std::chrono::seconds>(val)), ctx);
|
||||||
ctx);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#if FMT_USE_LOCAL_TIME
|
#if FMT_USE_LOCAL_TIME
|
||||||
template <typename Char, typename Duration>
|
template <typename Char, typename Duration>
|
||||||
struct formatter<std::chrono::local_time<Duration>,
|
struct formatter<std::chrono::local_time<Duration>, Char>
|
||||||
Char> : formatter<std::tm, Char> {
|
: formatter<std::tm, Char> {
|
||||||
FMT_CONSTEXPR formatter() {
|
FMT_CONSTEXPR formatter() {
|
||||||
basic_string_view<Char> default_specs =
|
basic_string_view<Char> default_specs =
|
||||||
detail::string_literal<Char, '%', 'F', ' ', '%', 'T'>{};
|
detail::string_literal<Char, '%', 'F', ' ', '%', 'T'>{};
|
||||||
@ -2145,8 +2144,8 @@ struct formatter<std::chrono::local_time<Duration>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename FormatContext>
|
template <typename FormatContext>
|
||||||
auto format(std::chrono::local_time<Duration> val,
|
auto format(std::chrono::local_time<Duration> val, FormatContext& ctx) const
|
||||||
FormatContext& ctx) const -> decltype(ctx.out()) {
|
-> decltype(ctx.out()) {
|
||||||
using period = typename Duration::period;
|
using period = typename Duration::period;
|
||||||
if (period::num != 1 || period::den != 1 ||
|
if (period::num != 1 || period::den != 1 ||
|
||||||
std::is_floating_point<typename Duration::rep>::value) {
|
std::is_floating_point<typename Duration::rep>::value) {
|
||||||
|
Loading…
Reference in New Issue
Block a user