summaryrefslogtreecommitdiff
path: root/src/test/test-time-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-03-13 03:47:45 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-03-13 04:43:51 +0900
commitcfacd245e798282fcb9b3231bd6e857abfe124fc (patch)
tree32e61dadfc56025ca65191fad0129b2e0d304f60 /src/test/test-time-util.c
parent37c6a3dc1a91e413ab6f949dc1d87f7749e63fb5 (diff)
downloadsystemd-cfacd245e798282fcb9b3231bd6e857abfe124fc.tar.gz
test-time-util: do not fail on DST change
Diffstat (limited to 'src/test/test-time-util.c')
-rw-r--r--src/test/test-time-util.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/src/test/test-time-util.c b/src/test/test-time-util.c
index e5a4cb6515..e0386d4ec5 100644
--- a/src/test/test-time-util.c
+++ b/src/test/test-time-util.c
@@ -636,12 +636,30 @@ static void test_parse_timestamp_one(const char *str, usec_t max_diff, usec_t ex
int r;
r = parse_timestamp(str, &usec);
- log_debug("/* %s(%s): max_diff="USEC_FMT", expected="USEC_FMT", result="USEC_FMT"*/", __func__, str, max_diff, expected, usec);
+ log_debug("/* %s(%s): max_diff="USEC_FMT", expected="USEC_FMT", result="USEC_FMT" */", __func__, str, max_diff, expected, usec);
assert_se(r >= 0);
assert_se(usec >= expected);
assert_se(usec_sub_unsigned(usec, expected) <= max_diff);
}
+static bool time_is_zero(usec_t usec) {
+ const char *s;
+
+ s = FORMAT_TIMESTAMP(usec);
+ return strstr(s, " 00:00:00 ");
+}
+
+static bool timezone_equal(usec_t today, usec_t target) {
+ const char *s, *t, *sz, *tz;
+
+ s = FORMAT_TIMESTAMP(today);
+ t = FORMAT_TIMESTAMP(target);
+ assert_se(sz = strrchr(s, ' '));
+ assert_se(tz = strrchr(t, ' '));
+ log_debug("%s("USEC_FMT", "USEC_FMT") -> %s, %s", __func__, today, target, s, t);
+ return streq(sz, tz);
+}
+
static void test_parse_timestamp_impl(const char *tz) {
usec_t today, now_usec;
@@ -823,12 +841,17 @@ static void test_parse_timestamp_impl(const char *tz) {
/* without date */
assert_se(parse_timestamp("today", &today) == 0);
- test_parse_timestamp_one("00:01", 0, today + USEC_PER_MINUTE);
- test_parse_timestamp_one("00:00:01", 0, today + USEC_PER_SEC);
- test_parse_timestamp_one("00:00:01.001", 0, today + USEC_PER_SEC + 1000);
- test_parse_timestamp_one("00:00:01.0010", 0, today + USEC_PER_SEC + 1000);
- test_parse_timestamp_one("tomorrow", 0, today + USEC_PER_DAY);
- test_parse_timestamp_one("yesterday", 0, today - USEC_PER_DAY);
+ if (time_is_zero(today)) {
+ test_parse_timestamp_one("00:01", 0, today + USEC_PER_MINUTE);
+ test_parse_timestamp_one("00:00:01", 0, today + USEC_PER_SEC);
+ test_parse_timestamp_one("00:00:01.001", 0, today + USEC_PER_SEC + 1000);
+ test_parse_timestamp_one("00:00:01.0010", 0, today + USEC_PER_SEC + 1000);
+
+ if (timezone_equal(today, today + USEC_PER_DAY) && time_is_zero(today + USEC_PER_DAY))
+ test_parse_timestamp_one("tomorrow", 0, today + USEC_PER_DAY);
+ if (timezone_equal(today, today - USEC_PER_DAY) && time_is_zero(today - USEC_PER_DAY))
+ test_parse_timestamp_one("yesterday", 0, today - USEC_PER_DAY);
+ }
/* relative */
assert_se(parse_timestamp("now", &now_usec) == 0);