From: Sage Weil Date: Thu, 6 Feb 2020 23:33:40 +0000 (-0600) Subject: include/utime: allow legacy rendering of timestamp X-Git-Tag: v15.1.1~494^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=64fdf60d649647f850efa8f0a12b31d56be629e9;p=ceph.git include/utime: allow legacy rendering of timestamp 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 --- diff --git a/src/include/utime.h b/src/include/utime.h index 04a4945b7051..5e58f1b149e4 100644 --- a/src/include/utime.h +++ b/src/include/utime.h @@ -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);