diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-07-11 10:44:14 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-07-11 10:44:14 -0700 |
commit | 0c72d6da31dd6ffce56989e4bcbd1b8650b1ef25 (patch) | |
tree | 28ec9bc02f2918c704abdf1b8f6efb5cf9fd1b05 /t/helper | |
parent | Merge branch 'js/mingw-parameter-less-c-functions' into maint (diff) | |
parent | local_tzoffset: detect errors from tm_to_time_t (diff) | |
download | tgif-0c72d6da31dd6ffce56989e4bcbd1b8650b1ef25.tar.xz |
Merge branch 'jk/tzoffset-fix' into maint
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"
Diffstat (limited to 't/helper')
-rw-r--r-- | t/helper/test-date.c | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/t/helper/test-date.c b/t/helper/test-date.c index 63f373557e..d9ab360909 100644 --- a/t/helper/test-date.c +++ b/t/helper/test-date.c @@ -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")) |