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"
8 " test-date timestamp [date]...\n"
10 " test-date time_t-is64bit\n";
12 static void show_relative_dates(const char **argv, struct timeval *now)
14 struct strbuf buf = STRBUF_INIT;
16 for (; *argv; argv++) {
17 time_t t = atoi(*argv);
18 show_date_relative(t, 0, now, &buf);
19 printf("%s -> %s\n", *argv, buf.buf);
24 static void show_dates(const char **argv, const char *format)
26 struct date_mode mode;
28 parse_date_format(format, &mode);
29 for (; *argv; argv++) {
35 * Do not use our normal timestamp parsing here, as the point
36 * is to test the formatting code in isolation.
38 t = parse_timestamp(*argv, &arg, 10);
43 printf("%s -> %s\n", *argv, show_date(t, tz, &mode));
47 static void parse_dates(const char **argv, struct timeval *now)
49 struct strbuf result = STRBUF_INIT;
51 for (; *argv; argv++) {
55 strbuf_reset(&result);
56 parse_date(*argv, &result);
57 if (sscanf(result.buf, "%"PRItime" %d", &t, &tz) == 2)
59 *argv, show_date(t, tz, DATE_MODE(ISO8601)));
61 printf("%s -> bad\n", *argv);
63 strbuf_release(&result);
66 static void parse_approxidate(const char **argv, struct timeval *now)
68 for (; *argv; argv++) {
70 t = approxidate_relative(*argv, now);
71 printf("%s -> %s\n", *argv, show_date(t, 0, DATE_MODE(ISO8601)));
75 static void parse_approx_timestamp(const char **argv, struct timeval *now)
77 for (; *argv; argv++) {
79 t = approxidate_relative(*argv, now);
80 printf("%s -> %"PRItime"\n", *argv, t);
84 int cmd_main(int argc, const char **argv)
89 x = getenv("TEST_DATE_NOW");
95 gettimeofday(&now, NULL);
100 if (!strcmp(*argv, "relative"))
101 show_relative_dates(argv+1, &now);
102 else if (skip_prefix(*argv, "show:", &x))
103 show_dates(argv+1, x);
104 else if (!strcmp(*argv, "parse"))
105 parse_dates(argv+1, &now);
106 else if (!strcmp(*argv, "approxidate"))
107 parse_approxidate(argv+1, &now);
108 else if (!strcmp(*argv, "timestamp"))
109 parse_approx_timestamp(argv+1, &now);
110 else if (!strcmp(*argv, "is64bit"))
111 return sizeof(timestamp_t) == 8 ? 0 : 1;
112 else if (!strcmp(*argv, "time_t-is64bit"))
113 return sizeof(time_t) == 8 ? 0 : 1;