Merge branch 'jk/tzoffset-fix'

The internal code used to show local timezone offset is not
prepared to handle timestamps beyond year 2100, and gave a
bogus offset value to the caller.  Use a more benign looking
+0000 instead and let "git log" going in such a case, instead
of aborting.

* jk/tzoffset-fix:
  local_tzoffset: detect errors from tm_to_time_t
  t0006: test various date formats
  t0006: rename test-date's "show" to "relative"
This commit is contained in:
Junio C Hamano
2016-07-06 13:38:15 -07:00
3 changed files with 71 additions and 17 deletions

View File

@ -1,11 +1,12 @@
#include "cache.h"
static const char *usage_msg = "\n"
" test-date show [time_t]...\n"
" test-date relative [time_t]...\n"
" test-date show:<format> [time_t]...\n"
" test-date parse [date]...\n"
" test-date approxidate [date]...\n";
static void show_dates(char **argv, struct timeval *now)
static void show_relative_dates(char **argv, struct timeval *now)
{
struct strbuf buf = STRBUF_INIT;
@ -17,6 +18,29 @@ static void show_dates(char **argv, struct timeval *now)
strbuf_release(&buf);
}
static void show_dates(char **argv, const char *format)
{
struct date_mode mode;
parse_date_format(format, &mode);
for (; *argv; argv++) {
char *arg = *argv;
time_t t;
int tz;
/*
* Do not use our normal timestamp parsing here, as the point
* is to test the formatting code in isolation.
*/
t = strtol(arg, &arg, 10);
while (*arg == ' ')
arg++;
tz = atoi(arg);
printf("%s -> %s\n", *argv, show_date(t, tz, &mode));
}
}
static void parse_dates(char **argv, struct timeval *now)
{
struct strbuf result = STRBUF_INIT;
@ -61,8 +85,10 @@ int main(int argc, char **argv)
argv++;
if (!*argv)
usage(usage_msg);
if (!strcmp(*argv, "show"))
show_dates(argv+1, &now);
if (!strcmp(*argv, "relative"))
show_relative_dates(argv+1, &now);
else if (skip_prefix(*argv, "show:", &x))
show_dates(argv+1, x);
else if (!strcmp(*argv, "parse"))
parse_dates(argv+1, &now);
else if (!strcmp(*argv, "approxidate"))