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.
This commit is contained in:
parent
b099f734b6
commit
bc9df6c60c
1 changed files with 5 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue