3 static const char *usage_msg = "\n"
4 " test-date relative [time_t]...\n"
5 " test-date show:<format> [time_t]...\n"
6 " test-date parse [date]...\n"
7 " test-date approxidate [date]...\n";
9 static void show_relative_dates(char **argv, struct timeval *now)
11 struct strbuf buf = STRBUF_INIT;
13 for (; *argv; argv++) {
14 time_t t = atoi(*argv);
15 show_date_relative(t, 0, now, &buf);
16 printf("%s -> %s\n", *argv, buf.buf);
21 static void show_dates(char **argv, const char *format)
23 struct date_mode mode;
25 parse_date_format(format, &mode);
26 for (; *argv; argv++) {
32 * Do not use our normal timestamp parsing here, as the point
33 * is to test the formatting code in isolation.
35 t = strtol(arg, &arg, 10);
40 printf("%s -> %s\n", *argv, show_date(t, tz, &mode));
44 static void parse_dates(char **argv, struct timeval *now)
46 struct strbuf result = STRBUF_INIT;
48 for (; *argv; argv++) {
52 strbuf_reset(&result);
53 parse_date(*argv, &result);
54 if (sscanf(result.buf, "%lu %d", &t, &tz) == 2)
56 *argv, show_date(t, tz, DATE_MODE(ISO8601)));
58 printf("%s -> bad\n", *argv);
60 strbuf_release(&result);
63 static void parse_approxidate(char **argv, struct timeval *now)
65 for (; *argv; argv++) {
67 t = approxidate_relative(*argv, now);
68 printf("%s -> %s\n", *argv, show_date(t, 0, DATE_MODE(ISO8601)));
72 int main(int argc, char **argv)
77 x = getenv("TEST_DATE_NOW");
83 gettimeofday(&now, NULL);
88 if (!strcmp(*argv, "relative"))
89 show_relative_dates(argv+1, &now);
90 else if (skip_prefix(*argv, "show:", &x))
91 show_dates(argv+1, x);
92 else if (!strcmp(*argv, "parse"))
93 parse_dates(argv+1, &now);
94 else if (!strcmp(*argv, "approxidate"))
95 parse_approxidate(argv+1, &now);