Minor cleanups in the clocks

This commit is contained in:
Howard Hinnant
2016-10-09 20:11:11 -04:00
parent 2ba541b684
commit fab89b205b

52
tz.h
View File

@@ -1013,7 +1013,7 @@ public:
using rep = duration::rep; using rep = duration::rep;
using period = duration::period; using period = duration::period;
using time_point = std::chrono::time_point<utc_clock>; using time_point = std::chrono::time_point<utc_clock>;
static CONSTDATA bool is_steady = true; static CONSTDATA bool is_steady = false;
static time_point now() NOEXCEPT; static time_point now() NOEXCEPT;
}; };
@@ -1104,7 +1104,7 @@ public:
using rep = duration::rep; using rep = duration::rep;
using period = duration::period; using period = duration::period;
using time_point = std::chrono::time_point<tai_clock>; using time_point = std::chrono::time_point<tai_clock>;
static const bool is_steady = true; static const bool is_steady = false;
static time_point now() NOEXCEPT; static time_point now() NOEXCEPT;
}; };
@@ -1136,12 +1136,20 @@ to_tai_time(utc_time<Duration> t)
(sys_days{year{1970}/jan/1} - sys_days{year{1958}/jan/1} + seconds{10}); (sys_days{year{1970}/jan/1} - sys_days{year{1958}/jan/1} + seconds{10});
} }
template <class Duration>
inline
tai_time<typename std::common_type<Duration, std::chrono::seconds>::type>
to_tai_time(sys_time<Duration> t)
{
return to_tai_time(to_utc_time(t));
}
inline inline
tai_clock::time_point tai_clock::time_point
tai_clock::now() NOEXCEPT tai_clock::now() NOEXCEPT
{ {
using namespace std::chrono; using namespace std::chrono;
return to_tai_time(utc_clock::now()); return to_tai_time(system_clock::now());
} }
template <class CharT, class Traits, class Duration> template <class CharT, class Traits, class Duration>
@@ -1164,7 +1172,7 @@ public:
using rep = duration::rep; using rep = duration::rep;
using period = duration::period; using period = duration::period;
using time_point = std::chrono::time_point<gps_clock>; using time_point = std::chrono::time_point<gps_clock>;
static const bool is_steady = true; static const bool is_steady = false;
static time_point now() NOEXCEPT; static time_point now() NOEXCEPT;
}; };
@@ -1196,12 +1204,20 @@ to_gps_time(utc_time<Duration> t)
(sys_days{year{1980}/jan/sun[1]} - sys_days{year{1970}/jan/1} + seconds{9}); (sys_days{year{1980}/jan/sun[1]} - sys_days{year{1970}/jan/1} + seconds{9});
} }
template <class Duration>
inline
gps_time<typename std::common_type<Duration, std::chrono::seconds>::type>
to_gps_time(sys_time<Duration> t)
{
return to_gps_time(to_utc_time(t));
}
inline inline
gps_clock::time_point gps_clock::time_point
gps_clock::now() NOEXCEPT gps_clock::now() NOEXCEPT
{ {
using namespace std::chrono; using namespace std::chrono;
return to_gps_time(utc_clock::now()); return to_gps_time(system_clock::now());
} }
template <class CharT, class Traits, class Duration> template <class CharT, class Traits, class Duration>
@@ -1231,28 +1247,15 @@ to_sys_time(gps_time<Duration> t)
return to_sys_time(to_utc_time(t)); return to_sys_time(to_utc_time(t));
} }
template <class Duration>
inline
tai_time<typename std::common_type<Duration, std::chrono::seconds>::type>
to_tai_time(sys_time<Duration> t)
{
return to_tai_time(to_utc_time(t));
}
template <class Duration> template <class Duration>
inline inline
tai_time<typename std::common_type<Duration, std::chrono::seconds>::type> tai_time<typename std::common_type<Duration, std::chrono::seconds>::type>
to_tai_time(gps_time<Duration> t) to_tai_time(gps_time<Duration> t)
{ {
return to_tai_time(to_utc_time(t)); using namespace std::chrono;
} using duration = typename std::common_type<Duration, seconds>::type;
return tai_time<duration>{t.time_since_epoch()} +
template <class Duration> (sys_days{year{1980}/jan/sun[1]} - sys_days{year{1958}/jan/1} + seconds{19});
inline
gps_time<typename std::common_type<Duration, std::chrono::seconds>::type>
to_gps_time(sys_time<Duration> t)
{
return to_gps_time(to_utc_time(t));
} }
template <class Duration> template <class Duration>
@@ -1260,7 +1263,10 @@ inline
gps_time<typename std::common_type<Duration, std::chrono::seconds>::type> gps_time<typename std::common_type<Duration, std::chrono::seconds>::type>
to_gps_time(tai_time<Duration> t) to_gps_time(tai_time<Duration> t)
{ {
return to_gps_time(to_utc_time(t)); using namespace std::chrono;
using duration = typename std::common_type<Duration, seconds>::type;
return gps_time<duration>{t.time_since_epoch()} -
(sys_days{year{1980}/jan/sun[1]} - sys_days{year{1958}/jan/1} + seconds{19});
} }
// format // format