4 static const char *usage_msg
= "\n"
5 " test-tool date relative [time_t]...\n"
6 " test-tool date human [time_t]...\n"
7 " test-tool date show:<format> [time_t]...\n"
8 " test-tool date parse [date]...\n"
9 " test-tool date approxidate [date]...\n"
10 " test-tool date timestamp [date]...\n"
11 " test-tool date getnanos [start-nanos]\n"
12 " test-tool date is64bit\n"
13 " test-tool date time_t-is64bit\n";
15 static void show_relative_dates(const char **argv
)
17 struct strbuf buf
= STRBUF_INIT
;
19 for (; *argv
; argv
++) {
20 time_t t
= atoi(*argv
);
21 show_date_relative(t
, &buf
);
22 printf("%s -> %s\n", *argv
, buf
.buf
);
27 static void show_human_dates(const char **argv
)
29 for (; *argv
; argv
++) {
30 time_t t
= atoi(*argv
);
31 printf("%s -> %s\n", *argv
, show_date(t
, 0, DATE_MODE(HUMAN
)));
35 static void show_dates(const char **argv
, const char *format
)
37 struct date_mode mode
;
39 parse_date_format(format
, &mode
);
40 for (; *argv
; argv
++) {
46 * Do not use our normal timestamp parsing here, as the point
47 * is to test the formatting code in isolation.
49 t
= parse_timestamp(*argv
, &arg
, 10);
54 printf("%s -> %s\n", *argv
, show_date(t
, tz
, &mode
));
58 static void parse_dates(const char **argv
)
60 struct strbuf result
= STRBUF_INIT
;
62 for (; *argv
; argv
++) {
66 strbuf_reset(&result
);
67 parse_date(*argv
, &result
);
68 if (sscanf(result
.buf
, "%"PRItime
" %d", &t
, &tz
) == 2)
70 *argv
, show_date(t
, tz
, DATE_MODE(ISO8601
)));
72 printf("%s -> bad\n", *argv
);
74 strbuf_release(&result
);
77 static void parse_approxidate(const char **argv
)
79 for (; *argv
; argv
++) {
81 t
= approxidate_relative(*argv
);
82 printf("%s -> %s\n", *argv
, show_date(t
, 0, DATE_MODE(ISO8601
)));
86 static void parse_approx_timestamp(const char **argv
)
88 for (; *argv
; argv
++) {
90 t
= approxidate_relative(*argv
);
91 printf("%s -> %"PRItime
"\n", *argv
, t
);
95 static void getnanos(const char **argv
)
97 double seconds
= getnanotime() / 1.0e9
;
100 seconds
-= strtod(*argv
, NULL
);
101 printf("%lf\n", seconds
);
104 int cmd__date(int argc
, const char **argv
)
111 if (!strcmp(*argv
, "relative"))
112 show_relative_dates(argv
+1);
113 else if (!strcmp(*argv
, "human"))
114 show_human_dates(argv
+1);
115 else if (skip_prefix(*argv
, "show:", &x
))
116 show_dates(argv
+1, x
);
117 else if (!strcmp(*argv
, "parse"))
119 else if (!strcmp(*argv
, "approxidate"))
120 parse_approxidate(argv
+1);
121 else if (!strcmp(*argv
, "timestamp"))
122 parse_approx_timestamp(argv
+1);
123 else if (!strcmp(*argv
, "getnanos"))
125 else if (!strcmp(*argv
, "is64bit"))
126 return sizeof(timestamp_t
) == 8 ? 0 : 1;
127 else if (!strcmp(*argv
, "time_t-is64bit"))
128 return sizeof(time_t) == 8 ? 0 : 1;