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 for (; *argv; argv++) {
28 parse_date(*argv, result, sizeof(result));
29 if (sscanf(result, "%lu %d", &t, &tz) == 2)
31 *argv, show_date(t, tz, DATE_ISO8601));
33 printf("%s -> bad\n", *argv);
37 static void parse_approxidate(char **argv, struct timeval *now)
39 for (; *argv; argv++) {
41 t = approxidate_relative(*argv, now);
42 printf("%s -> %s\n", *argv, show_date(t, 0, DATE_ISO8601));
46 int main(int argc, char **argv)
51 x = getenv("TEST_DATE_NOW");
57 gettimeofday(&now, NULL);
62 if (!strcmp(*argv, "show"))
63 show_dates(argv+1, &now);
64 else if (!strcmp(*argv, "parse"))
65 parse_dates(argv+1, &now);
66 else if (!strcmp(*argv, "approxidate"))
67 parse_approxidate(argv+1, &now);