3 static const char *usage_msg = "\n"
4 " test-date show [time_t]...\n"
5 " test-date parse [date]...\n"
6 " test-date approxidate [date]...\n";
8 static void show_dates(char **argv, struct timeval *now)
10 struct strbuf buf = STRBUF_INIT;
12 for (; *argv; argv++) {
13 time_t t = atoi(*argv);
14 show_date_relative(t, 0, now, &buf);
15 printf("%s -> %s\n", *argv, buf.buf);
20 static void parse_dates(char **argv, struct timeval *now)
22 struct strbuf result = STRBUF_INIT;
24 for (; *argv; argv++) {
28 strbuf_reset(&result);
29 parse_date(*argv, &result);
30 if (sscanf(result.buf, "%lu %d", &t, &tz) == 2)
32 *argv, show_date(t, tz, DATE_MODE(ISO8601)));
34 printf("%s -> bad\n", *argv);
36 strbuf_release(&result);
39 static void parse_approxidate(char **argv, struct timeval *now)
41 for (; *argv; argv++) {
43 t = approxidate_relative(*argv, now);
44 printf("%s -> %s\n", *argv, show_date(t, 0, DATE_MODE(ISO8601)));
48 int main(int argc, char **argv)
53 x = getenv("TEST_DATE_NOW");
59 gettimeofday(&now, NULL);
64 if (!strcmp(*argv, "show"))
65 show_dates(argv+1, &now);
66 else if (!strcmp(*argv, "parse"))
67 parse_dates(argv+1, &now);
68 else if (!strcmp(*argv, "approxidate"))
69 parse_approxidate(argv+1, &now);