Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 68 lines (58 sloc) 1.358 kb
8996702 Make the date parsing accept pretty much any random crap.
Linus Torvalds authored
1 #include "cache.h"
2
4f6552e Jeff King refactor test-date interface
peff authored
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";
7
8 static void show_dates(char **argv, struct timeval *now)
8996702 Make the date parsing accept pretty much any random crap.
Linus Torvalds authored
9 {
4f6552e Jeff King refactor test-date interface
peff authored
10 char buf[128];
11
12 for (; *argv; argv++) {
13 time_t t = atoi(*argv);
14 show_date_relative(t, 0, now, buf, sizeof(buf));
15 printf("%s -> %s\n", *argv, buf);
16 }
17 }
8996702 Make the date parsing accept pretty much any random crap.
Linus Torvalds authored
18
4f6552e Jeff King refactor test-date interface
peff authored
19 static void parse_dates(char **argv, struct timeval *now)
20 {
21 for (; *argv; argv++) {
8996702 Make the date parsing accept pretty much any random crap.
Linus Torvalds authored
22 char result[100];
23 time_t t;
24
4f6552e Jeff King refactor test-date interface
peff authored
25 result[0] = 0;
26 parse_date(*argv, result, sizeof(result));
8996702 Make the date parsing accept pretty much any random crap.
Linus Torvalds authored
27 t = strtoul(result, NULL, 0);
4f6552e Jeff King refactor test-date interface
peff authored
28 printf("%s -> %s\n", *argv,
29 t ? show_date(t, 0, DATE_ISO8601) : "bad");
30 }
31 }
f30c95d Add approxidate test calls.
Junio C Hamano authored
32
4f6552e Jeff King refactor test-date interface
peff authored
33 static void parse_approxidate(char **argv, struct timeval *now)
34 {
35 for (; *argv; argv++) {
36 time_t t;
37 t = approxidate_relative(*argv, now);
38 printf("%s -> %s\n", *argv, show_date(t, 0, DATE_ISO8601));
39 }
40 }
41
42 int main(int argc, char **argv)
43 {
44 struct timeval now;
45 const char *x;
46
47 x = getenv("TEST_DATE_NOW");
48 if (x) {
49 now.tv_sec = atoi(x);
50 now.tv_usec = 0;
8996702 Make the date parsing accept pretty much any random crap.
Linus Torvalds authored
51 }
4f6552e Jeff King refactor test-date interface
peff authored
52 else
53 gettimeofday(&now, NULL);
54
55 argv++;
56 if (!*argv)
57 usage(usage_msg);
58 if (!strcmp(*argv, "show"))
59 show_dates(argv+1, &now);
60 else if (!strcmp(*argv, "parse"))
61 parse_dates(argv+1, &now);
62 else if (!strcmp(*argv, "approxidate"))
63 parse_approxidate(argv+1, &now);
64 else
65 usage(usage_msg);
8996702 Make the date parsing accept pretty much any random crap.
Linus Torvalds authored
66 return 0;
67 }
Something went wrong with that request. Please try again.