]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include/utime: allow legacy rendering of timestamp
authorSage Weil <sage@redhat.com>
Thu, 6 Feb 2020 23:33:40 +0000 (17:33 -0600)
committerSage Weil <sage@redhat.com>
Fri, 7 Feb 2020 22:44:18 +0000 (16:44 -0600)
In 79d8d761cf8fb6a5679d1925f92889c950dc2be4 and
ec3ddcb9886e3c74b78aa8521bc05e695f6aeeab
we switched to a strict ISO8660 rendering for timestamps.  In some cases,
we need to render the timestamp in the legacy form: ' ' instead of 'T',
and no time zone suffix.

Signed-off-by: Sage Weil <sage@redhat.com>
src/include/utime.h

index 04a4945b7051ba05706607389400626a1bbff286..5e58f1b149e4a14e92efaa49511926740d3ca9cb 100644 (file)
@@ -239,7 +239,7 @@ public:
   }
 
   // output
-  std::ostream& gmtime(std::ostream& out) const {
+  std::ostream& gmtime(std::ostream& out, bool legacy_form=false) const {
     out.setf(std::ios::right);
     char oldfill = out.fill();
     out.fill('0');
@@ -254,9 +254,13 @@ public:
       gmtime_r(&tt, &bdt);
       out << 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_mday;
+      if (legacy_form) {
+       out << ' ';
+      } else {
+       out << 'T';
+      }
+      out << std::setw(2) << bdt.tm_hour
          << ':' << std::setw(2) << bdt.tm_min
          << ':' << std::setw(2) << bdt.tm_sec;
       out << "." << std::setw(6) << usec();
@@ -322,7 +326,7 @@ public:
     return out;
   }
 
-  std::ostream& localtime(std::ostream& out) const {
+  std::ostream& localtime(std::ostream& out, bool legacy_form=false) const {
     out.setf(std::ios::right);
     char oldfill = out.fill();
     out.fill('0');
@@ -337,15 +341,21 @@ public:
       localtime_r(&tt, &bdt);
       out << 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_mday;
+      if (legacy_form) {
+       out << ' ';
+      } else {
+       out << 'T';
+      }
+      out << std::setw(2) << bdt.tm_hour
          << ':' << std::setw(2) << bdt.tm_min
          << ':' << std::setw(2) << bdt.tm_sec;
       out << "." << std::setw(6) << usec();
-      char buf[32] = { 0 };
-      strftime(buf, sizeof(buf), "%z", &bdt);
-      out << buf;
+      if (!legacy_form) {
+       char buf[32] = { 0 };
+       strftime(buf, sizeof(buf), "%z", &bdt);
+       out << buf;
+      }
     }
     out.fill(oldfill);
     out.unsetf(std::ios::right);