aboutsummaryrefslogtreecommitdiff
path: root/build/timestamp.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-12-10 10:20:26 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2014-12-10 10:20:26 +0200
commit5e9eb843f6ccadfb47fa603260783425da9e7805 (patch)
tree3778f76de37f5258a07a8fae0e58a843b8a49f1d /build/timestamp.cxx
parent20e3aedeb7df742c38276fb41cae8f3eb027b6dd (diff)
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
Diffstat (limited to 'build/timestamp.cxx')
-rw-r--r--build/timestamp.cxx37
1 files changed, 30 insertions, 7 deletions
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 << "<beyond 9999 years>";
+ return os << "<beyond 9999>";
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';