]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/common/ceph_time.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / common / ceph_time.cc
index 2fd5aa1a909e2e5c8634702ac54457be9f7e4c09..bb708bb4675646d467ff0fe4ab5033997c63901f 100644 (file)
@@ -97,11 +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) {
-    return m << std::chrono::duration<double>(t).count() << "s";
+    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';
   }
 
   template<typename Clock,
@@ -112,19 +120,22 @@ namespace ceph {
     char oldfill = m.fill();
     m.fill('0');
     // localtime.  this looks like an absolute time.
-    //  aim for http://en.wikipedia.org/wiki/ISO_8601
+    //  conform to http://en.wikipedia.org/wiki/ISO_8601
     struct tm bdt;
     time_t tt = Clock::to_time_t(t);
     localtime_r(&tt, &bdt);
+    char tz[32] = { 0 };
+    strftime(tz, sizeof(tz), "%z", &bdt);
     m << std::setw(4) << (bdt.tm_year+1900)  // 2007 -> '07'
       << '-' << std::setw(2) << (bdt.tm_mon+1)
       << '-' << std::setw(2) << bdt.tm_mday
-      << ' '
+      << 'T'
       << std::setw(2) << bdt.tm_hour
       << ':' << std::setw(2) << bdt.tm_min
       << ':' << std::setw(2) << bdt.tm_sec
       << "." << std::setw(6) << duration_cast<microseconds>(
-       t.time_since_epoch() % seconds(1));
+       t.time_since_epoch() % seconds(1)).count()
+      << tz;
     m.fill(oldfill);
     m.unsetf(std::ios::right);
     return m;