1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 09:21:26 +03:00

util: teach parse_timestamp() to parse results of format_timestamp_relative()

This commit is contained in:
Lennart Poettering 2012-11-23 22:20:15 +01:00
parent bbb8486e17
commit decad9103e
2 changed files with 16 additions and 0 deletions

View File

@ -344,6 +344,19 @@ int parse_timestamp(const char *t, usec_t *usec) {
return r;
goto finish;
} else if (endswith(t, " ago")) {
_cleanup_free_ char *z;
z = strndup(t, strlen(t) - 4);
if (!z)
return -ENOMEM;
r = parse_usec(z, &minus);
if (r < 0)
return r;
goto finish;
}
copy = tm;

View File

@ -65,5 +65,8 @@ int main(int argc, char *argv[]) {
assert_se(parse_timestamp("+2y 4d", &t) >= 0);
log_info("%s", format_timestamp(buf, sizeof(buf), t));
assert_se(parse_timestamp("5months ago", &t) >= 0);
log_info("%s", format_timestamp(buf, sizeof(buf), t));
return 0;
}