chiark / gitweb /
util: teach parse_timestamp() to parse results of format_timestamp_relative()
authorLennart Poettering <lennart@poettering.net>
Fri, 23 Nov 2012 21:20:15 +0000 (22:20 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 23 Nov 2012 21:20:15 +0000 (22:20 +0100)
src/shared/time-util.c
src/test/test-date.c

index 3d00b20..7f47710 100644 (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;
index 57f8b37..7e14d19 100644 (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;
 }