diff --git a/test/clock_cast_test/custom_clock.pass.cpp b/test/clock_cast_test/custom_clock.pass.cpp index 8d3ccba..fe3b05a 100644 --- a/test/clock_cast_test/custom_clock.pass.cpp +++ b/test/clock_cast_test/custom_clock.pass.cpp @@ -56,6 +56,23 @@ struct mil_clock return res(tp - epoch); } + template + static + std::chrono::time_point::type> + to_local(std::chrono::time_point const& tp) + { + return date::clock_cast(to_sys(tp)); + } + + template + static + std::chrono::time_point::type> + from_local(std::chrono::time_point const& tp) + { + return from_sys(date::clock_cast(tp)); + } + + static time_point now() { return from_sys(std::chrono::system_clock::now()); @@ -127,6 +144,15 @@ main() assert(clock_cast(mt) == mt); } + // mil <-> local + { + local_days lt(1997_y/dec/12); + auto mt = mil_clock::from_local(lt); + + assert(clock_cast(lt) == mt); + assert(clock_cast(mt) == lt); + } + // mil <-> sys { sys_days st(1997_y/dec/12); diff --git a/test/clock_cast_test/local_time_conversion.pass.cpp b/test/clock_cast_test/local_t.pass.cpp similarity index 95% rename from test/clock_cast_test/local_time_conversion.pass.cpp rename to test/clock_cast_test/local_t.pass.cpp index 59bcdbf..b6a33bb 100644 --- a/test/clock_cast_test/local_time_conversion.pass.cpp +++ b/test/clock_cast_test/local_t.pass.cpp @@ -7,6 +7,12 @@ main() using namespace date; using namespace std::chrono; + // self + { + auto ls = local_days{1970_y/01/01_d}; + assert(clock_cast(ls) == ls); + } + /// sys epoch { auto ls = local_days{1970_y/01/01_d}; diff --git a/test/clock_cast_test/noncastable.pass.cpp b/test/clock_cast_test/noncastable.pass.cpp index b81139e..6a91f57 100644 --- a/test/clock_cast_test/noncastable.pass.cpp +++ b/test/clock_cast_test/noncastable.pass.cpp @@ -194,6 +194,8 @@ main() //steady_clock (must be different that sys_clock) static_assert(is_clock_castable::value, "steady_clock -> steady_clock"); + static_assert(!is_clock_castable::value, "steady_clock -> local_t"); + static_assert(!is_clock_castable::value, "local_t -> steady_clock"); static_assert(!is_clock_castable::value, "steady_clock -> sys_clock"); static_assert(!is_clock_castable::value, "sys_clock -> steady_clock"); static_assert(!is_clock_castable::value, "steady_clock -> utc_clock"); @@ -203,6 +205,8 @@ main() //steady_based_clock (unrelated to sys_clock and utc_clocks) static_assert(is_clock_castable::value, "steady_based_clock -> steady_based_clock"); + static_assert(!is_clock_castable::value, "steady_based_clock -> local_t"); + static_assert(!is_clock_castable::value, "local_t -> steady_based_clock"); static_assert(!is_clock_castable::value, "steady_based_clock -> sys_clock"); static_assert(!is_clock_castable::value, "sys_clock -> steady_based_clock"); static_assert(!is_clock_castable::value, "steady_based_clock -> utc_clock");