]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-date.c
path-util: when parsing a timestamp we don't know the timezone
[thirdparty/systemd.git] / src / test / test-date.c
CommitLineData
cfbc22ab
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2012 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#include "util.h"
23
24int main(int argc, char *argv[]) {
25
26 usec_t t;
27 char buf[FORMAT_TIMESTAMP_MAX];
28
29 assert_se(parse_timestamp("17:41", &t) >= 0);
30 log_info("%s", format_timestamp(buf, sizeof(buf), t));
31
32 assert_se(parse_timestamp("18:42:44", &t) >= 0);
33 log_info("%s", format_timestamp(buf, sizeof(buf), t));
34
35 assert_se(parse_timestamp("12-10-02 12:13:14", &t) >= 0);
36 log_info("%s", format_timestamp(buf, sizeof(buf), t));
37
38 assert_se(parse_timestamp("12-10-2 12:13:14", &t) >= 0);
39 log_info("%s", format_timestamp(buf, sizeof(buf), t));
40
41 assert_se(parse_timestamp("12-10-03 12:13", &t) >= 0);
42 log_info("%s", format_timestamp(buf, sizeof(buf), t));
43
44 assert_se(parse_timestamp("2012-12-30 18:42", &t) >= 0);
45 log_info("%s", format_timestamp(buf, sizeof(buf), t));
46
47 assert_se(parse_timestamp("2012-10-02", &t) >= 0);
48 log_info("%s", format_timestamp(buf, sizeof(buf), t));
49
50 assert_se(parse_timestamp("now", &t) >= 0);
51 log_info("%s", format_timestamp(buf, sizeof(buf), t));
52
53 assert_se(parse_timestamp("yesterday", &t) >= 0);
54 log_info("%s", format_timestamp(buf, sizeof(buf), t));
55
56 assert_se(parse_timestamp("today", &t) >= 0);
57 log_info("%s", format_timestamp(buf, sizeof(buf), t));
58
59 assert_se(parse_timestamp("tomorrow", &t) >= 0);
60 log_info("%s", format_timestamp(buf, sizeof(buf), t));
61
62 assert_se(parse_timestamp("+2d", &t) >= 0);
63 log_info("%s", format_timestamp(buf, sizeof(buf), t));
64
65 assert_se(parse_timestamp("+2y 4d", &t) >= 0);
66 log_info("%s", format_timestamp(buf, sizeof(buf), t));
67
decad910
LP
68 assert_se(parse_timestamp("5months ago", &t) >= 0);
69 log_info("%s", format_timestamp(buf, sizeof(buf), t));
70
cfbc22ab
LP
71 return 0;
72}