]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common/ceph_time: do not handle negative case
authorKefu Chai <kchai@redhat.com>
Sun, 29 Sep 2019 17:08:52 +0000 (01:08 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 30 Sep 2019 08:25:01 +0000 (16:25 +0800)
this change partially reverts 353a0e5f, unlike `signedspan`,
`timespan::rep` is unsigned. so no need to handle negative case.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/ceph_time.cc

index c44b2eac14da727a564611afd67252f868b55379..bb708bb4675646d467ff0fe4ab5033997c63901f 100644 (file)
@@ -97,24 +97,19 @@ namespace ceph {
                           const std::chrono::time_point<Clock>& t) {
     return m << std::fixed << std::chrono::duration<double>(
                t.time_since_epoch()).count()
-            << "s";
+            << 's';
   }
 
   std::ostream& operator<<(std::ostream& m, const timespan& t) {
-    int64_t ns = t.count();
-    if (ns < 0) {
-      ns = -ns;
-      m << "-";
-    }
-    m << (ns / 1000000000ll);
-    ns %= 1000000000ll;
-    if (ns) {
+    static_assert(std::is_unsigned_v<timespan::rep>);
+    m << std::chrono::duration_cast<std::chrono::seconds>(t).count();
+    if (auto ns = (t % 1s).count(); ns > 0) {
       char oldfill = m.fill();
       m.fill('0');
       m << '.' << std::setw(9) << ns;
       m.fill(oldfill);
     }
-    return m << "s";
+    return m << 's';
   }
 
   template<typename Clock,