[systemd-commits] man/systemd.time.xml src/shared src/test

Lennart Poettering lennart at kemper.freedesktop.org
Mon Mar 24 20:09:01 PDT 2014


 man/systemd.time.xml      |   16 +++++++++++-----
 src/shared/calendarspec.c |    1 -
 src/shared/time-util.c    |    9 ++++++---
 src/test/test-date.c      |    1 +
 4 files changed, 18 insertions(+), 9 deletions(-)

New commits:
commit 5ba6e0949cef1a5b947dd59665bad1ca5066619d
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Mar 25 04:08:16 2014 +0100

    time: support @ syntax for denoting times since the UNIX epoch 1970-1-1

diff --git a/man/systemd.time.xml b/man/systemd.time.xml
index a837f23..0706cdf 100644
--- a/man/systemd.time.xml
+++ b/man/systemd.time.xml
@@ -153,14 +153,19 @@
                 <para>When parsing, systemd will also accept relative
                 time specifications. A time span (see above) that is
                 prefixed with <literal>+</literal> is evaluated to the
-                current time plus the specified
-                time span. Correspondingly, a time span that is prefixed
+                current time plus the specified time
+                span. Correspondingly, a time span that is prefixed
                 with <literal>-</literal> is evaluated to the current
                 time minus the specified time span. Instead of
-                prefixing the time span with <literal>-</literal>, it
-                may also be suffixed with a space and the word
+                prefixing the time span with <literal>+</literal> or
+                <literal>-</literal>, it may also be suffixed with a
+                space and the word <literal>left</literal> or
                 <literal>ago</literal>.</para>
 
+                <para>Finally, a timespan prefixed with
+                <literal>@</literal> is evaluated relative to the UNIX
+                time epoch 1st Jan, 1970, 00:00.</para>
+
                 <para>Examples for valid timestamps and their
                 normalized form (assuming the current time was
                 2012-11-23 18:15:22):</para>
@@ -177,7 +182,8 @@
                tomorrow → Fri 2012-11-24 00:00:00
                +3h30min → Fri 2012-11-23 21:45:22
                     -5s → Fri 2012-11-23 18:15:17
-              11min ago → Fri 2012-11-23 18:04:22</programlisting>
+              11min ago → Fri 2012-11-23 18:04:22
+            @1395716396 → Tue 2014-03-25 03:59:56</programlisting>
 
                 <para>Note that timestamps printed by systemd will not
                 be parsed correctly by systemd, as the timezone
diff --git a/src/shared/calendarspec.c b/src/shared/calendarspec.c
index 7075159..69b7427 100644
--- a/src/shared/calendarspec.c
+++ b/src/shared/calendarspec.c
@@ -938,7 +938,6 @@ int calendar_spec_next_usec(const CalendarSpec *spec, usec_t usec, usec_t *next)
         if (t == (time_t) -1)
                 return -EINVAL;
 
-
         *next = (usec_t) t * USEC_PER_SEC;
         return 0;
 }
diff --git a/src/shared/time-util.c b/src/shared/time-util.c
index faa3418..eb5c1ae 100644
--- a/src/shared/time-util.c
+++ b/src/shared/time-util.c
@@ -432,6 +432,7 @@ int parse_timestamp(const char *t, usec_t *usec) {
          *   tomorrow             (time is set to 00:00:00)
          *   +5min
          *   -5days
+         *   @2147483647          (seconds since epoch)
          *
          */
 
@@ -460,21 +461,23 @@ int parse_timestamp(const char *t, usec_t *usec) {
                 goto finish;
 
         } else if (t[0] == '+') {
-
                 r = parse_sec(t+1, &plus);
                 if (r < 0)
                         return r;
 
                 goto finish;
-        } else if (t[0] == '-') {
 
+        } else if (t[0] == '-') {
                 r = parse_sec(t+1, &minus);
                 if (r < 0)
                         return r;
 
                 goto finish;
 
-        } else if (endswith(t, " ago")) {
+        } else if (t[0] == '@')
+                return parse_sec(t + 1, usec);
+
+        else if (endswith(t, " ago")) {
                 _cleanup_free_ char *z;
 
                 z = strndup(t, strlen(t) - 4);
diff --git a/src/test/test-date.c b/src/test/test-date.c
index 40ffc17..0586b78 100644
--- a/src/test/test-date.c
+++ b/src/test/test-date.c
@@ -56,6 +56,7 @@ int main(int argc, char *argv[]) {
         test_one("+2d");
         test_one("+2y 4d");
         test_one("5months ago");
+        test_one("@1395716396");
 
         return 0;
 }



More information about the systemd-commits mailing list