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 " test-date time_t-is64bit\n";
11 static void show_relative_dates(const char **argv
, struct timeval
*now
)
13 struct strbuf buf
= STRBUF_INIT
;
15 for (; *argv
; argv
++) {
16 time_t t
= atoi(*argv
);
17 show_date_relative(t
, 0, now
, &buf
);
18 printf("%s -> %s\n", *argv
, buf
.buf
);
23 static void show_dates(const char **argv
, const char *format
)
25 struct date_mode mode
;
27 parse_date_format(format
, &mode
);
28 for (; *argv
; argv
++) {
34 * Do not use our normal timestamp parsing here, as the point
35 * is to test the formatting code in isolation.
37 t
= parse_timestamp(*argv
, &arg
, 10);
42 printf("%s -> %s\n", *argv
, show_date(t
, tz
, &mode
));
46 static void parse_dates(const char **argv
, struct timeval
*now
)
48 struct strbuf result
= STRBUF_INIT
;
50 for (; *argv
; argv
++) {
54 strbuf_reset(&result
);
55 parse_date(*argv
, &result
);
56 if (sscanf(result
.buf
, "%"PRItime
" %d", &t
, &tz
) == 2)
58 *argv
, show_date(t
, tz
, DATE_MODE(ISO8601
)));
60 printf("%s -> bad\n", *argv
);
62 strbuf_release(&result
);
65 static void parse_approxidate(const char **argv
, struct timeval
*now
)
67 for (; *argv
; argv
++) {
69 t
= approxidate_relative(*argv
, now
);
70 printf("%s -> %s\n", *argv
, show_date(t
, 0, DATE_MODE(ISO8601
)));
74 int cmd_main(int argc
, const char **argv
)
79 x
= getenv("TEST_DATE_NOW");
85 gettimeofday(&now
, NULL
);
90 if (!strcmp(*argv
, "relative"))
91 show_relative_dates(argv
+1, &now
);
92 else if (skip_prefix(*argv
, "show:", &x
))
93 show_dates(argv
+1, x
);
94 else if (!strcmp(*argv
, "parse"))
95 parse_dates(argv
+1, &now
);
96 else if (!strcmp(*argv
, "approxidate"))
97 parse_approxidate(argv
+1, &now
);
98 else if (!strcmp(*argv
, "is64bit"))
99 return sizeof(timestamp_t
) == 8 ? 0 : 1;
100 else if (!strcmp(*argv
, "time_t-is64bit"))
101 return sizeof(time_t) == 8 ? 0 : 1;