// The MIT License (MIT) // // Copyright (c) 2019 nanoric // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. #include "tz.h" #include #include struct const_clock { using duration = typename std::common_type::type; using rep = duration::rep; using period = duration::period; using time_point = std::chrono::time_point; static constexpr date::sys_days epoch { date::days { 1000 } }; template static std::chrono::time_point::type> CONSTCD11 to_sys(std::chrono::time_point const& tp) { return epoch + tp.time_since_epoch(); } template static std::chrono::time_point::type> CONSTCD11 from_sys( std::chrono::time_point const& tp) { using res = std::chrono::time_point::type>; return res(tp - epoch); } }; int main() { using namespace date; using namespace std::chrono; using const_days = time_point; CONSTCD14 sys_days sys { days { 1024 } }; static_assert(sys.time_since_epoch().count() == 1024, ""); CONSTCD14 const_days c {clock_cast(sys)}; CONSTCD14 sys_days sys2 {clock_cast(c)}; CONSTCD14 sys_days sys3 { clock_cast(const_days(days(48))) }; #if __cplusplus >= 201402L static_assert(c.time_since_epoch().count() == 24, ""); static_assert(sys2.time_since_epoch().count() == 1024, ""); static_assert(sys3.time_since_epoch().count() == 1048, ""); #endif }