diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-10-25 22:58:00 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-10-25 22:58:00 +0100 |
commit | 46f190483facaccf6f8f2bfba453f7c7dd231b22 (patch) | |
tree | 127e8577554cbd3a173b7dd47b29b98b9ae99965 | |
parent | f739078599ee9b1e00f643b5b4c45a0d57938fe1 (diff) | |
parent | b4ae407d3ed6701df4e079d65b8fc3607437c569 (diff) |
Merge pull request #1673 from mustrumr/date-fixes
Date fixes
-rw-r--r-- | man/systemd.time.xml | 12 | ||||
-rw-r--r-- | src/basic/calendarspec.c | 9 | ||||
-rw-r--r-- | src/basic/time-util.c | 12 | ||||
-rw-r--r-- | src/test/test-date.c | 9 |
4 files changed, 26 insertions, 16 deletions
diff --git a/man/systemd.time.xml b/man/systemd.time.xml index 826e9fc5a5..df7e1ecfb9 100644 --- a/man/systemd.time.xml +++ b/man/systemd.time.xml @@ -117,12 +117,12 @@ <refsect1> <title>Parsing Timestamps</title> - <para>When parsing systemd will accept a similar syntax, but expects - no timezone specification, unless it is given as the literal string - "UTC". In this case the time is considered in UTC time, otherwise in - the local timezone. The weekday specification is optional, but when - the weekday is specified it must either be in the abbreviated - (<literal>Wed</literal>) or non-abbreviated + <para>When parsing systemd will accept a similar syntax, but + expects no timezone specification, unless it is given as the + literal string "UTC". In this case the time is considered in UTC, + otherwise in the local timezone. The weekday specification is + optional, but when the weekday is specified it must either be in + the abbreviated (<literal>Wed</literal>) or non-abbreviated (<literal>Wednesday</literal>) English language form (case does not matter), and is not subject to the locale choice of the user. Either the date, or the time part may be omitted, in which case diff --git a/src/basic/calendarspec.c b/src/basic/calendarspec.c index 987ca81910..50328e4187 100644 --- a/src/basic/calendarspec.c +++ b/src/basic/calendarspec.c @@ -650,6 +650,7 @@ fail: int calendar_spec_from_string(const char *p, CalendarSpec **spec) { CalendarSpec *c; int r; + const char *utc; assert(p); assert(spec); @@ -661,9 +662,11 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) { if (!c) return -ENOMEM; - c->utc = endswith_no_case(p, "UTC"); - if (c->utc) - p = strndupa(p, strlen(p) - strlen(" UTC")); + utc = endswith_no_case(p, " UTC"); + if (utc) { + c->utc = true; + p = strndupa(p, utc - p); + } if (strcaseeq(p, "minutely")) { r = const_chain(0, &c->second); diff --git a/src/basic/time-util.c b/src/basic/time-util.c index d117380d52..b348ed4204 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -479,7 +479,7 @@ int parse_timestamp(const char *t, usec_t *usec) { }; const char *k; - bool utc; + const char *utc; struct tm tm, copy; time_t x; usec_t x_usec, plus = 0, minus = 0, ret; @@ -529,8 +529,8 @@ int parse_timestamp(const char *t, usec_t *usec) { goto finish; - } else if (endswith(t, " ago")) { - t = strndupa(t, strlen(t) - strlen(" ago")); + } else if ((k = endswith(t, " ago"))) { + t = strndupa(t, k - t); r = parse_sec(t, &minus); if (r < 0) @@ -538,8 +538,8 @@ int parse_timestamp(const char *t, usec_t *usec) { goto finish; - } else if (endswith(t, " left")) { - t = strndupa(t, strlen(t) - strlen(" left")); + } else if ((k = endswith(t, " left"))) { + t = strndupa(t, k - t); r = parse_sec(t, &plus); if (r < 0) @@ -550,7 +550,7 @@ int parse_timestamp(const char *t, usec_t *usec) { utc = endswith_no_case(t, " UTC"); if (utc) - t = strndupa(t, strlen(t) - strlen(" UTC")); + t = strndupa(t, utc - t); x = ret / USEC_PER_SEC; x_usec = 0; diff --git a/src/test/test-date.c b/src/test/test-date.c index 8d78ab89d0..e1c6ecb2ef 100644 --- a/src/test/test-date.c +++ b/src/test/test-date.c @@ -43,6 +43,12 @@ static void test_should_pass(const char *p) { assert_se(parse_timestamp(buf, &q) >= 0); } +static void test_should_parse(const char *p) { + usec_t t; + + assert_se(parse_timestamp(p, &t) >= 0); +} + static void test_should_fail(const char *p) { usec_t t; @@ -86,7 +92,8 @@ int main(int argc, char *argv[]) { test_one_noutc("+2y 4d"); test_one_noutc("5months ago"); test_one_noutc("@1395716396"); - test_one_noutc("today UTC"); + test_should_parse("today UTC"); + test_should_fail("today UTC UTC"); return 0; } |