From 8f5e5e41105a4d4675c640945ec46f55099677c2 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Wed, 8 Jun 2016 20:49:19 -0400 Subject: [PATCH] Add convenience converts among sys_time, utc_time, tai_time, and gps_time. --- tz.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/tz.h b/tz.h index 5501d12..713508f 100644 --- a/tz.h +++ b/tz.h @@ -1237,7 +1237,7 @@ 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{1980_y/jan/6} - sys_days{1970_y/jan/1} + 9s); + (sys_days{1980_y/jan/sun[1]} - sys_days{1970_y/jan/1} + 9s); } template @@ -1247,7 +1247,7 @@ gps_clock::gps_to_utc(gps_time t) using namespace std::chrono; using duration = typename std::common_type::type; return utc_time{t.time_since_epoch()} + - (sys_days{1980_y/jan/6} - sys_days{1970_y/jan/1} + 9s); + (sys_days{1980_y/jan/sun[1]} - sys_days{1970_y/jan/1} + 9s); } template @@ -1281,10 +1281,58 @@ operator<<(std::basic_ostream& os, const gps_time& t) using namespace std::chrono; using duration = typename std::common_type::type; auto tp = sys_time{t.time_since_epoch()} + - (sys_days{1980_y/jan/6} - sys_days{1970_y/jan/1}); + (sys_days{1980_y/jan/sun[1]} - sys_days{1970_y/jan/1}); return os << tp; } +template +inline +sys_time::type> +to_sys_time(tai_time t) +{ + return to_sys_time(to_utc_time(t)); +} + +template +inline +sys_time::type> +to_sys_time(gps_time t) +{ + return to_sys_time(to_utc_time(t)); +} + +template +inline +tai_time::type> +to_tai_time(sys_time t) +{ + return to_tai_time(to_utc_time(t)); +} + +template +inline +tai_time::type> +to_tai_time(gps_time t) +{ + return to_tai_time(to_utc_time(t)); +} + +template +inline +gps_time::type> +to_gps_time(sys_time t) +{ + return to_gps_time(to_utc_time(t)); +} + +template +inline +gps_time::type> +to_gps_time(tai_time t) +{ + return to_gps_time(to_utc_time(t)); +} + // format namespace detail