Cleanup chrono detail

This commit is contained in:
Victor Zverovich
2025-04-06 09:54:47 -07:00
parent b3d45e1d3f
commit 5f2e61fdd5

View File

@ -505,26 +505,28 @@ auto to_time_t(sys_time<Duration> time_point) -> std::time_t {
} }
namespace tz { namespace tz {
// DEPRECATED!
struct time_zone { struct time_zone {
template <typename Duration, typename T> template <typename Duration, typename LocalTime>
auto to_sys(T) auto to_sys(LocalTime) -> sys_time<Duration> {
-> std::chrono::time_point<std::chrono::system_clock, Duration> {
return {}; return {};
} }
}; };
template <typename... T> inline auto current_zone(T...) -> time_zone* { template <typename... T> auto current_zone(T...) -> time_zone* {
return nullptr; return nullptr;
} }
template <typename... T> inline void _tzset(T...) {} template <typename... T> void _tzset(T...) {}
} // namespace tz } // namespace tz
// Workaround a bug in libstdc++ which sets __cpp_lib_chrono to 201907 without inline void tzset_once() {
// providing current_zone(): https://github.com/fmtlib/fmt/issues/4160. static bool init = []() {
template <typename T> FMT_CONSTEXPR auto has_current_zone() -> bool { using namespace tz;
using namespace std::chrono; _tzset();
using namespace tz; return false;
return !std::is_same<decltype(current_zone()), tz::time_zone*>::value; }();
ignore_unused(init);
} }
} // namespace detail } // namespace detail
@ -535,7 +537,7 @@ FMT_BEGIN_EXPORT
* expressed in local time. Unlike `std::localtime`, this function is * expressed in local time. Unlike `std::localtime`, this function is
* thread-safe on most platforms. * thread-safe on most platforms.
*/ */
inline auto localtime(std::time_t time) -> std::tm { FMT_DEPRECATED inline auto localtime(std::time_t time) -> std::tm {
struct dispatcher { struct dispatcher {
std::time_t time_; std::time_t time_;
std::tm tm_; std::tm tm_;
@ -572,9 +574,8 @@ inline auto localtime(std::time_t time) -> std::tm {
} }
#if FMT_USE_LOCAL_TIME #if FMT_USE_LOCAL_TIME
template <typename Duration, template <typename Duration>
FMT_ENABLE_IF(detail::has_current_zone<Duration>())> FMT_DEPRECATED auto localtime(std::chrono::local_time<Duration> time)
FMT_DEPRECATED inline auto localtime(std::chrono::local_time<Duration> time)
-> std::tm { -> std::tm {
using namespace std::chrono; using namespace std::chrono;
using namespace detail::tz; using namespace detail::tz;
@ -1003,15 +1004,6 @@ template <typename T>
struct has_member_data_tm_zone<T, void_t<decltype(T::tm_zone)>> struct has_member_data_tm_zone<T, void_t<decltype(T::tm_zone)>>
: std::true_type {}; : std::true_type {};
inline void tzset_once() {
static bool init = []() {
using namespace tz;
_tzset();
return false;
}();
ignore_unused(init);
}
// Converts value to Int and checks that it's in the range [0, upper). // Converts value to Int and checks that it's in the range [0, upper).
template <typename T, typename Int, FMT_ENABLE_IF(std::is_integral<T>::value)> template <typename T, typename Int, FMT_ENABLE_IF(std::is_integral<T>::value)>
inline auto to_nonnegative_int(T value, Int upper) -> Int { inline auto to_nonnegative_int(T value, Int upper) -> Int {