From bc9df6c60c7d2346aa89674b3b7ba26b5d3e97ad Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Mon, 3 Jun 2013 23:49:06 +0200 Subject: [PATCH] time: fix -older t for relative times to current time (thanks arisawa for pointing out) from test(1): f -older t True if file f is older than (modified before) time t. If t is a integer followed by the letters y(years), M(months), d(days), h(hours), m(minutes), or s(seconds), it represents current time minus the specified time. If there is no letter, it represents seconds since epoch. You can also concatenate mixed units. For example, 3d12h means three days and twelve hours ago. this means *without* [y M d h m s] unit, t is *absolute* time in seconds since epoch. --- sys/src/cmd/test.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sys/src/cmd/test.c b/sys/src/cmd/test.c index 42318075d..52ff667df 100644 --- a/sys/src/cmd/test.c +++ b/sys/src/cmd/test.c @@ -338,11 +338,13 @@ isolder(char *pin, char *f) /* parse time */ n = 0; + r = 1; while(*p){ m = strtoul(p, &p, 0); switch(*p){ case 0: n = m; + r = 0; break; case 'y': m *= 12; @@ -368,7 +370,9 @@ isolder(char *pin, char *f) } } - r = dir->mtime + n < time(0); + if (r != 0) + n = time(0) - n; + r = dir->mtime < n; free(dir); return r; }