From 5e9eb843f6ccadfb47fa603260783425da9e7805 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 10 Dec 2014 10:20:26 +0200 Subject: Add rules g++-4.9 -std=c++11 -g -I.. -o bd bd.cxx target.cxx native.cxx rule.cxx cxx/rule.cxx cxx/target.cxx process.cxx timestamp.cxx path.cxx --- build/timestamp.cxx | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'build/timestamp.cxx') diff --git a/build/timestamp.cxx b/build/timestamp.cxx index db8efb2..0ad3f3f 100644 --- a/build/timestamp.cxx +++ b/build/timestamp.cxx @@ -41,10 +41,10 @@ namespace build constexpr int nsec (...) {return 0;} timestamp - path_timestamp (const std::string& p) + path_mtime (const path& p) { struct stat s; - if (stat (p.c_str (), &s) != 0) + if (stat (p.string ().c_str (), &s) != 0) { if (errno == ENOENT || errno == ENOTDIR) return timestamp_nonexistent; @@ -108,18 +108,37 @@ namespace build time_t t (system_clock::to_time_t (ts)); const char* fmt (nullptr); + const char* unt ("nanoseconds"); if (t >= 365 * 12 * 24 * 60 * 60) + { fmt = "%Y-%m-%d %H:%M:%S"; + unt = "years"; + } else if (t >= 12 * 24 * 60* 60) + { fmt = "%m-%d %H:%M:%S"; + unt = "months"; + } else if (t >= 24 * 60* 60) + { fmt = "%d %H:%M:%S"; + unt = "days"; + } else if (t >= 60 * 60) + { fmt = "%H:%M:%S"; + unt = "hours"; + } else if (t >= 60) + { fmt = "%M:%S"; + unt = "minutes"; + } else if (t >= 1) + { fmt = "%S"; + unt = "seconds"; + } if (fmt != nullptr) { @@ -129,7 +148,7 @@ namespace build char buf[20]; // YYYY-MM-DD HH:MM:SS\0 if (strftime (buf, sizeof (buf), fmt, &tm) == 0) - return os << ""; + return os << ""; os << buf; } @@ -141,10 +160,14 @@ namespace build if (ns != nanoseconds::zero ()) { - os << '.'; - os.width (9); - os.fill ('0'); - os << ns.count (); + if (fmt != nullptr) + { + os << '.'; + os.width (9); + os.fill ('0'); + } + + os << ns.count () << ' ' << unt; } else if (fmt == 0) os << '0'; -- cgit v1.1