From 64ce680b4eec86e1287dc5f9209464fd5ed4306b Mon Sep 17 00:00:00 2001 From: sageweil Date: Mon, 16 Jul 2007 18:03:43 +0000 Subject: [PATCH] decompose utime_t when printing git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1503 29311d96-e01e-0410-9327-a35deaab8ce9 --- branches/sage/cephmds2/include/utime.h | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/branches/sage/cephmds2/include/utime.h b/branches/sage/cephmds2/include/utime.h index 5103d2801cf57..ee44cf8b7d16e 100644 --- a/branches/sage/cephmds2/include/utime.h +++ b/branches/sage/cephmds2/include/utime.h @@ -16,7 +16,7 @@ #define __UTIME_H #include - +#include // -------- // utime_t @@ -119,15 +119,28 @@ inline bool operator<(const utime_t& a, const utime_t& b) // ostream inline std::ostream& operator<<(std::ostream& out, const utime_t& t) { - //return out << t.sec() << "." << t.usec(); - out << (long)t.sec() << "."; out.setf(std::ios::right); out.fill('0'); + if (t.sec() < ((time_t)(60*60*24*365*10))) { + // raw seconds. this looks like a relative time. + out << (long)t.sec(); + } else { + // localtime. this looks like an absolute time. + struct tm bdt; + time_t tt = t.sec(); + localtime_r(&tt, &bdt); + out << std::setw(2) << (bdt.tm_year-100) // 2007 -> '07' + << std::setw(2) << bdt.tm_mon + << std::setw(2) << bdt.tm_mday + << "." + << std::setw(2) << bdt.tm_hour + << std::setw(2) << bdt.tm_min + << std::setw(2) << bdt.tm_sec; + } + out << "."; out << std::setw(6) << t.usec(); out.unsetf(std::ios::right); return out; - - //return out << (long)t.sec << "." << ios::setf(ios::right) << ios::fill('0') << t.usec() << ios::usetf(); } #endif -- 2.39.5