Merge branch 'jk/tzoffset-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 11 Jul 2016 17:44:14 +0000 (10:44 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 11 Jul 2016 17:44:14 +0000 (10:44 -0700)
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"

1  2 
t/helper/test-date.c
index 63f373557e7236d294fb580d38db9e6d331e53d3,0000000000000000000000000000000000000000..d9ab3609094df80a1e3afc3d24d8fd158c96e496
mode 100644,000000..100644
--- /dev/null
@@@ -1,73 -1,0 +1,99 @@@
- "  test-date show [time_t]...\n"
 +#include "cache.h"
 +
 +static const char *usage_msg = "\n"
- static void show_dates(char **argv, struct timeval *now)
++"  test-date relative [time_t]...\n"
++"  test-date show:<format> [time_t]...\n"
 +"  test-date parse [date]...\n"
 +"  test-date approxidate [date]...\n";
 +
-       if (!strcmp(*argv, "show"))
-               show_dates(argv+1, &now);
++static void show_relative_dates(char **argv, struct timeval *now)
 +{
 +      struct strbuf buf = STRBUF_INIT;
 +
 +      for (; *argv; argv++) {
 +              time_t t = atoi(*argv);
 +              show_date_relative(t, 0, now, &buf);
 +              printf("%s -> %s\n", *argv, buf.buf);
 +      }
 +      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;
 +
 +      for (; *argv; argv++) {
 +              unsigned long t;
 +              int tz;
 +
 +              strbuf_reset(&result);
 +              parse_date(*argv, &result);
 +              if (sscanf(result.buf, "%lu %d", &t, &tz) == 2)
 +                      printf("%s -> %s\n",
 +                             *argv, show_date(t, tz, DATE_MODE(ISO8601)));
 +              else
 +                      printf("%s -> bad\n", *argv);
 +      }
 +      strbuf_release(&result);
 +}
 +
 +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_MODE(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;
 +      }
 +      else
 +              gettimeofday(&now, NULL);
 +
 +      argv++;
 +      if (!*argv)
 +              usage(usage_msg);
++      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"))
 +              parse_approxidate(argv+1, &now);
 +      else
 +              usage(usage_msg);
 +      return 0;
 +}