From 9f1c4b0110cb714f099ed3b04fd2d51577a9603d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kami=C5=84ski?= Date: Tue, 28 Nov 2017 15:20:45 +0100 Subject: [PATCH] Implemented clock_cast for local_time. Implemented clock_time_conversion calling D::from_local and clock_time_conversion calling S::to_local. To avoid ambiguities addes: * clock_time_conversion - idenitity * clock_time_conversion - same as default (utc_clock::to_local) * clock_time_conversion - same as default (utc_clock::from_local) In addition, as std::chrono::system_clock cannot be edited, added: * clock_time_conversion - assumes same epoch * clock_time_conversion - assumes same epoch They will be required to resolve amibiguity anyway. --- include/date/tz.h | 117 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 1 deletion(-) diff --git a/include/date/tz.h b/include/date/tz.h index 2befd92..8603c86 100644 --- a/include/date/tz.h +++ b/include/date/tz.h @@ -2293,6 +2293,17 @@ struct clock_time_conversion } }; +template<> +struct clock_time_conversion +{ + template + local_time + operator()(const local_time& lt) const + { + return lt; + } +}; + template <> struct clock_time_conversion { @@ -2315,7 +2326,51 @@ struct clock_time_conversion } }; -template +template<> +struct clock_time_conversion +{ + template + local_time + operator()(const sys_time& st) const + { + return local_time{st.time_since_epoch()}; + } +}; + +template<> +struct clock_time_conversion +{ + template + sys_time + operator()(const local_time& lt) const + { + return sys_time{lt.time_sine_epoch()}; + } +}; + +template<> +struct clock_time_conversion +{ + template + utc_time::type> + operator()(const local_time& lt) const + { + return utc_clock::from_local(lt); + } +}; + +template<> +struct clock_time_conversion +{ + template + local_time::type> + operator()(const utc_time& ut) const + { + return utc_clock::to_local(ut); + } +}; + +template struct clock_time_conversion { template @@ -2421,6 +2476,44 @@ struct return_from_utc > {}; +// Similiar to above +template +struct return_to_local +{}; + +template +struct return_to_local + < + Clock, Duration, + decltype(Clock::to_local(declval const&>()), + void()) + > + : return_clock_time + < + local_t, + decltype(Clock::to_local(declval const&>())) + > +{}; + +// Similiar to above +template +struct return_from_local +{}; + +template +struct return_from_local + < + Clock, Duration, + decltype(Clock::from_local(declval const&>()), + void()) + > + : return_clock_time + < + Clock, + decltype(Clock::from_local(declval const&>())) + > +{}; + } // namespace ctc_detail template @@ -2467,6 +2560,28 @@ struct clock_time_conversion } }; +template +struct clock_time_conversion +{ + template + typename ctc_detail::return_to_local::type + operator()(const std::chrono::time_point& tp) const + { + return SrcClock::to_local(tp); + } +}; + +template +struct clock_time_conversion +{ + template + typename ctc_detail::return_from_local::type + operator()(const local_time& lt) const + { + return DstClock::from_local(lt); + } +}; + namespace clock_cast_detail {