diff --git a/tz.h b/tz.h index 8dce041..5b001b5 100644 --- a/tz.h +++ b/tz.h @@ -1016,17 +1016,6 @@ public: static CONSTDATA bool is_steady = true; static time_point now() NOEXCEPT; - - template - static - std::chrono::time_point::type> - sys_to_utc(sys_time t); - - template - static - sys_time::type> - utc_to_sys(std::chrono::time_point t); }; template @@ -1034,33 +1023,27 @@ template using utc_seconds = utc_time; +template inline -utc_clock::time_point -utc_clock::now() NOEXCEPT -{ - using namespace std::chrono; - return sys_to_utc(system_clock::now()); -} - -template utc_time::type> -utc_clock::sys_to_utc(sys_time t) +to_utc_time(sys_time st) { using namespace std::chrono; using duration = typename std::common_type::type; auto const& leaps = get_tzdb().leaps; - auto const lt = std::upper_bound(leaps.begin(), leaps.end(), t); - return utc_time{t.time_since_epoch() + seconds{lt-leaps.begin()}}; + auto const lt = std::upper_bound(leaps.begin(), leaps.end(), st); + return utc_time{st.time_since_epoch() + seconds{lt-leaps.begin()}}; } template +inline sys_time::type> -utc_clock::utc_to_sys(utc_time t) +to_sys_time(utc_time ut) { using namespace std::chrono; using duration = typename std::common_type::type; auto const& leaps = get_tzdb().leaps; - auto tp = sys_time{t.time_since_epoch()}; + auto tp = sys_time{ut.time_since_epoch()}; if (tp >= leaps.front()) { auto const lt = std::upper_bound(leaps.begin(), leaps.end(), tp); @@ -1076,20 +1059,12 @@ utc_clock::utc_to_sys(utc_time t) return tp; } -template inline -sys_time::type> -to_sys_time(utc_time ut) +utc_clock::time_point +utc_clock::now() NOEXCEPT { - return utc_clock::utc_to_sys(ut); -} - -template -inline -utc_time::type> -to_utc_time(sys_time st) -{ - return utc_clock::sys_to_utc(st); + using namespace std::chrono; + return to_utc_time(system_clock::now()); } template @@ -1132,17 +1107,6 @@ public: static const bool is_steady = true; static time_point now() NOEXCEPT; - - template - static - std::chrono::time_point::type> - utc_to_tai(utc_time t); - - template - static - utc_time::type> - tai_to_utc(std::chrono::time_point t); }; template @@ -1151,18 +1115,9 @@ template using tai_seconds = tai_time; template -tai_time::type> -tai_clock::utc_to_tai(utc_time t) -{ - using namespace std::chrono; - using duration = typename std::common_type::type; - return tai_time{t.time_since_epoch()} + - (sys_days{year{1970}/jan/1} - sys_days{year{1958}/jan/1} + seconds{10}); -} - -template +inline utc_time::type> -tai_clock::tai_to_utc(tai_time t) +to_utc_time(tai_time t) { using namespace std::chrono; using duration = typename std::common_type::type; @@ -1170,20 +1125,15 @@ tai_clock::tai_to_utc(tai_time t) (sys_days{year{1970}/jan/1} - sys_days{year{1958}/jan/1} + seconds{10}); } -template -inline -utc_time::type> -to_utc_time(tai_time t) -{ - return tai_clock::tai_to_utc(t); -} - template inline tai_time::type> to_tai_time(utc_time t) { - return tai_clock::utc_to_tai(t); + using namespace std::chrono; + using duration = typename std::common_type::type; + return tai_time{t.time_since_epoch()} + + (sys_days{year{1970}/jan/1} - sys_days{year{1958}/jan/1} + seconds{10}); } inline @@ -1217,17 +1167,6 @@ public: static const bool is_steady = true; static time_point now() NOEXCEPT; - - template - static - std::chrono::time_point::type> - utc_to_gps(utc_time t); - - template - static - utc_time::type> - gps_to_utc(std::chrono::time_point t); }; template @@ -1236,18 +1175,9 @@ template using gps_seconds = gps_time; template -gps_time::type> -gps_clock::utc_to_gps(utc_time t) -{ - using namespace std::chrono; - using duration = typename std::common_type::type; - return gps_time{t.time_since_epoch()} - - (sys_days{year{1980}/jan/sun[1]} - sys_days{year{1970}/jan/1} + seconds{9}); -} - -template +inline utc_time::type> -gps_clock::gps_to_utc(gps_time t) +to_utc_time(gps_time t) { using namespace std::chrono; using duration = typename std::common_type::type; @@ -1255,20 +1185,15 @@ gps_clock::gps_to_utc(gps_time t) (sys_days{year{1980}/jan/sun[1]} - sys_days{year{1970}/jan/1} + seconds{9}); } -template -inline -utc_time::type> -to_utc_time(gps_time t) -{ - return gps_clock::gps_to_utc(t); -} - template inline gps_time::type> to_gps_time(utc_time t) { - return gps_clock::utc_to_gps(t); + using namespace std::chrono; + using duration = typename std::common_type::type; + return gps_time{t.time_since_epoch()} - + (sys_days{year{1980}/jan/sun[1]} - sys_days{year{1970}/jan/1} + seconds{9}); } inline