Вы можете лучше обслуживать предикаты -cmin
и -mmin
Да, это сделает интерполяцию под-дня и под-часа:
parser.c, строка 3243
/* Get a timestamp and comparison type.
STR is the ASCII representation.
Set *NUM_DAYS to the number of days/minutes/whatever, taken as being
relative to ORIGIN (usually the current moment or midnight).
Thus the sense of the comparison type appears to be reversed.
Set *COMP_TYPE to the kind of comparison that is requested.
Issue OVERFLOWMESSAGE if overflow occurs.
Return true if all okay, false if input error.
Used by -atime, -ctime and -mtime (parsers) to
get the appropriate information for a time predicate processor. */
static boolean
get_relative_timestamp (const char *str,
struct time_val *result,
struct timespec origin,
double sec_per_unit,
const char *overflowmessage)
{
double offset, seconds, nanosec;
static const long nanosec_per_sec = 1000000000;
if (get_comp_type(&str, &result->kind))
{
/* Invert the sense of the comparison */
switch (result->kind)
{
case COMP_LT: result->kind = COMP_GT; break;
case COMP_GT: result->kind = COMP_LT; break;
default: break;
}
/* Convert the ASCII number into floating-point. */
if (xstrtod(str, NULL, &offset, strtod))
{
/* Separate the floating point number the user specified
* (which is a number of days, or minutes, etc) into an
* integral number of seconds (SECONDS) and a fraction (NANOSEC).
*/
nanosec = modf(offset * sec_per_unit, &seconds);
nanosec *= 1.0e9; /* convert from fractional seconds to ns. */
assert (nanosec < nanosec_per_sec);
/* Perform the subtraction, and then check for overflow.
* On systems where signed aritmetic overflow does not
* wrap, this check may be unreliable. The C standard
* does not require this approach to work, but I am aware
* of no platforms where it fails.
*/
result->ts.tv_sec = origin.tv_sec - seconds;
if ((origin.tv_sec < result->ts.tv_sec) != (seconds < 0))
{
/* an overflow has occurred. */
error (1, 0, overflowmessage, str);
}
result->ts.tv_nsec = origin.tv_nsec - nanosec;
if (origin.tv_nsec < nanosec)
{
/* Perform a carry operation */
result->ts.tv_nsec += nanosec_per_sec;
result->ts.tv_sec -= 1;
}
return true;
}
else
{
/* Conversion from ASCII to double failed. */
return false;
}
}
else
{
return false;
}
}
пред.с, строка 237:
/* Returns ts1 - ts2 */
static double ts_difference(struct timespec ts1,
struct timespec ts2)
{
double d = difftime(ts1.tv_sec, ts2.tv_sec)
+ (1.0e-9 * (ts1.tv_nsec - ts2.tv_nsec));
return d;
}