diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-11-23 22:20:15 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-11-23 22:20:15 +0100 |
commit | decad9103eab4c5f24dbc55dc7d2cdabce87a302 (patch) | |
tree | f11788b4d9ddb44b51dc39dcabdd15fe05fb37d4 /src | |
parent | bbb8486e1709ee297a1eb803f88041e1da1fa436 (diff) |
util: teach parse_timestamp() to parse results of format_timestamp_relative()
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/time-util.c | 13 | ||||
-rw-r--r-- | src/test/test-date.c | 3 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/shared/time-util.c b/src/shared/time-util.c index 3d00b20eec..7f477100b3 100644 --- a/src/shared/time-util.c +++ b/src/shared/time-util.c @@ -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; diff --git a/src/test/test-date.c b/src/test/test-date.c index 57f8b371d3..7e14d196c6 100644 --- a/src/test/test-date.c +++ b/src/test/test-date.c @@ -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; } |