]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/timeutils: parse_timestamp: allow fixed reference time
authorThomas Weißschuh <thomas@t-8ch.de>
Fri, 20 Jan 2023 02:06:04 +0000 (02:06 +0000)
committerThomas Weißschuh <thomas@t-8ch.de>
Mon, 23 Jan 2023 13:21:54 +0000 (13:21 +0000)
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
lib/timeutils.c

index 4eaef9533ab2696c766f0477d7be3362d3ba0f66..c474d750cb64fc49403881729b0f003bcc9664a4 100644 (file)
@@ -147,7 +147,7 @@ static int parse_sec(const char *t, usec_t *usec)
        return 0;
 }
 
-int parse_timestamp(const char *t, usec_t *usec)
+static int parse_timestamp_reference(time_t x, const char *t, usec_t *usec)
 {
        static const struct {
                const char *name;
@@ -171,7 +171,6 @@ int parse_timestamp(const char *t, usec_t *usec)
 
        const char *k;
        struct tm tm, copy;
-       time_t x;
        usec_t plus = 0, minus = 0, ret;
        int r, weekday = -1;
        unsigned i;
@@ -198,7 +197,6 @@ int parse_timestamp(const char *t, usec_t *usec)
        assert(t);
        assert(usec);
 
-       x = time(NULL);
        localtime_r(&x, &tm);
        tm.tm_isdst = -1;
 
@@ -354,6 +352,11 @@ int parse_timestamp(const char *t, usec_t *usec)
        return 0;
 }
 
+int parse_timestamp(const char *t, usec_t *usec)
+{
+       return parse_timestamp_reference(time(NULL), t, usec);
+}
+
 /* Returns the difference in seconds between its argument and GMT. If if TP is
  * invalid or no DST information is available default to UTC, that is, zero.
  * tzset is called so, for example, 'TZ="UTC" hwclock' will work as expected.