]> git.proxmox.com Git - systemd.git/blame - src/test/test-date.c
Imported Upstream version 217
[systemd.git] / src / test / test-date.c
CommitLineData
663996b3
MS
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 <string.h>
23
24#include "util.h"
25
26static void test_one(const char *p) {
27 usec_t t, q;
28 char buf[FORMAT_TIMESTAMP_MAX], buf_relative[FORMAT_TIMESTAMP_RELATIVE_MAX];
29
30 assert_se(parse_timestamp(p, &t) >= 0);
5eef597e
MP
31 format_timestamp(buf, sizeof(buf), t);
32 log_info("%s", buf);
663996b3
MS
33
34 /* Chop off timezone */
35 *strrchr(buf, ' ') = 0;
36
37 assert_se(parse_timestamp(buf, &q) >= 0);
38 assert_se(q == t);
39
5eef597e
MP
40 format_timestamp_relative(buf_relative, sizeof(buf_relative), t);
41 log_info("%s", strna(buf_relative));
663996b3
MS
42 assert_se(parse_timestamp(buf, &q) >= 0);
43}
44
45int main(int argc, char *argv[]) {
46 test_one("17:41");
47 test_one("18:42:44");
48 test_one("12-10-02 12:13:14");
49 test_one("12-10-2 12:13:14");
50 test_one("12-10-03 12:13");
51 test_one("2012-12-30 18:42");
52 test_one("2012-10-02");
53 test_one("Tue 2012-10-02");
54 test_one("now");
55 test_one("yesterday");
56 test_one("today");
57 test_one("tomorrow");
58 test_one("+2d");
59 test_one("+2y 4d");
60 test_one("5months ago");
60f067b4 61 test_one("@1395716396");
663996b3
MS
62
63 return 0;
64}