2 * This file is part of DisOrder.
3 * Copyright (C) 2008, 2009 Richard Kettlewell
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "dateparse.h"
22 static void check_date(time_t when
,
24 struct tm
*(*convert
)(const time_t *)) {
28 strftime(buffer
, sizeof buffer
, fmt
, convert(&when
));
29 parsed
= dateparse(buffer
);
30 check_integer(parsed
, when
);
32 fprintf(stderr
, "format=%s formatted=%s\n", fmt
, buffer
);
35 static void test_dateparse(void) {
36 time_t now
= xtime(0);
37 check_date(now
, "%Y-%m-%d %H:%M:%S", localtime
);
38 #if 0 /* see dateparse.c */
39 check_date(now
, "%Y-%m-%d %H:%M:%S %Z", localtime
);
40 check_date(now
, "%Y-%m-%d %H:%M:%S %Z", gmtime
);
42 check_date(now
, "%c", localtime
);
43 check_date(now
, "%Ec", localtime
);
44 check_date(now
, "%X", localtime
);
45 check_date(now
, "%EX", localtime
);
46 check_date(now
, "%H:%M:%S", localtime
);
47 /* This one needs a bodge: */
48 check_date(now
- now
% 60, "%H:%M", localtime
);
49 /* Reject invalid formats */
50 check_fatal(dateparse("12"));
51 check_fatal(dateparse("12:34:56:23"));
52 /* Reject invalid values */
53 check_fatal(dateparse("25:34"));
54 check_fatal(dateparse("23:61"));
55 check_fatal(dateparse("23:23:62"));