2005-04-30 22:19:56 +02:00
|
|
|
#include "cache.h"
|
|
|
|
|
2009-08-31 04:26:46 +02:00
|
|
|
static const char *usage_msg = "\n"
|
|
|
|
" test-date show [time_t]...\n"
|
|
|
|
" test-date parse [date]...\n"
|
|
|
|
" test-date approxidate [date]...\n";
|
|
|
|
|
|
|
|
static void show_dates(char **argv, struct timeval *now)
|
2005-04-30 22:19:56 +02:00
|
|
|
{
|
2012-04-23 14:30:23 +02:00
|
|
|
struct strbuf buf = STRBUF_INIT;
|
2009-08-31 04:26:46 +02:00
|
|
|
|
|
|
|
for (; *argv; argv++) {
|
|
|
|
time_t t = atoi(*argv);
|
2012-04-23 14:30:23 +02:00
|
|
|
show_date_relative(t, 0, now, &buf);
|
|
|
|
printf("%s -> %s\n", *argv, buf.buf);
|
2009-08-31 04:26:46 +02:00
|
|
|
}
|
2012-04-23 14:30:23 +02:00
|
|
|
strbuf_release(&buf);
|
2009-08-31 04:26:46 +02:00
|
|
|
}
|
2005-04-30 22:19:56 +02:00
|
|
|
|
2009-08-31 04:26:46 +02:00
|
|
|
static void parse_dates(char **argv, struct timeval *now)
|
|
|
|
{
|
|
|
|
for (; *argv; argv++) {
|
2005-04-30 22:19:56 +02:00
|
|
|
char result[100];
|
2010-07-06 09:54:33 +02:00
|
|
|
unsigned long t;
|
2010-07-04 12:48:35 +02:00
|
|
|
int tz;
|
2005-04-30 22:19:56 +02:00
|
|
|
|
2009-08-31 04:26:46 +02:00
|
|
|
result[0] = 0;
|
|
|
|
parse_date(*argv, result, sizeof(result));
|
2010-07-06 09:54:33 +02:00
|
|
|
if (sscanf(result, "%lu %d", &t, &tz) == 2)
|
2010-07-04 12:48:35 +02:00
|
|
|
printf("%s -> %s\n",
|
|
|
|
*argv, show_date(t, tz, DATE_ISO8601));
|
|
|
|
else
|
|
|
|
printf("%s -> bad\n", *argv);
|
2009-08-31 04:26:46 +02:00
|
|
|
}
|
|
|
|
}
|
2005-11-15 09:07:04 +01:00
|
|
|
|
2009-08-31 04:26:46 +02:00
|
|
|
static void parse_approxidate(char **argv, struct timeval *now)
|
|
|
|
{
|
|
|
|
for (; *argv; argv++) {
|
|
|
|
time_t t;
|
|
|
|
t = approxidate_relative(*argv, now);
|
|
|
|
printf("%s -> %s\n", *argv, show_date(t, 0, DATE_ISO8601));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct timeval now;
|
|
|
|
const char *x;
|
|
|
|
|
|
|
|
x = getenv("TEST_DATE_NOW");
|
|
|
|
if (x) {
|
|
|
|
now.tv_sec = atoi(x);
|
|
|
|
now.tv_usec = 0;
|
2005-04-30 22:19:56 +02:00
|
|
|
}
|
2009-08-31 04:26:46 +02:00
|
|
|
else
|
|
|
|
gettimeofday(&now, NULL);
|
|
|
|
|
|
|
|
argv++;
|
|
|
|
if (!*argv)
|
|
|
|
usage(usage_msg);
|
|
|
|
if (!strcmp(*argv, "show"))
|
|
|
|
show_dates(argv+1, &now);
|
|
|
|
else if (!strcmp(*argv, "parse"))
|
|
|
|
parse_dates(argv+1, &now);
|
|
|
|
else if (!strcmp(*argv, "approxidate"))
|
|
|
|
parse_approxidate(argv+1, &now);
|
|
|
|
else
|
|
|
|
usage(usage_msg);
|
2005-04-30 22:19:56 +02:00
|
|
|
return 0;
|
|
|
|
}
|