From 1139c9b64fe3e1866069901de75616a89bb75c99 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Tue, 13 Jun 2017 23:00:54 -0400 Subject: [PATCH] Allow zoned_time with coarser precision than seconds * This gives greater interoperability with the deduction for class templates language feature. * time_points output from zoned_time still have at least seconds precision. --- tz.h | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tz.h b/tz.h index b011026..70c16d7 100644 --- a/tz.h +++ b/tz.h @@ -273,8 +273,12 @@ class time_zone; template class zoned_time { +public: + using duration = typename std::common_type::type; + +private: const time_zone* zone_; - sys_time tp_; + sys_time tp_; public: zoned_time(const sys_time& st); @@ -310,12 +314,12 @@ public: zoned_time& operator=(const sys_time& st); zoned_time& operator=(const local_time& ut); - operator sys_time() const; - explicit operator local_time() const; + operator sys_time() const; + explicit operator local_time() const; const time_zone* get_time_zone() const; - local_time get_local_time() const; - sys_time get_sys_time() const; + local_time get_local_time() const; + sys_time get_sys_time() const; sys_info get_info() const; template @@ -330,9 +334,6 @@ public: private: template friend class zoned_time; - - static_assert(std::is_convertible::value, - "zoned_time must have a precision of seconds or finer"); }; using zoned_seconds = zoned_time; @@ -971,14 +972,14 @@ zoned_time::operator=(const local_time& ut) template inline -zoned_time::operator local_time() const +zoned_time::operator local_time() const { return get_local_time(); } template inline -zoned_time::operator sys_time() const +zoned_time::operator sys_time() const { return get_sys_time(); } @@ -993,7 +994,7 @@ zoned_time::get_time_zone() const template inline -local_time +local_time::duration> zoned_time::get_local_time() const { return zone_->to_local(tp_); @@ -1001,7 +1002,7 @@ zoned_time::get_local_time() const template inline -sys_time +sys_time::duration> zoned_time::get_sys_time() const { return tp_;