git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
cf8d4574b7c6db006f8593d3a4ec0e19542270bb blob 3045 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
 
#include "test-tool.h"
#include "cache.h"

static const char *usage_msg = "\n"
"  test-tool date relative [time_t]...\n"
"  test-tool date human [time_t]...\n"
"  test-tool date show:<format> [time_t]...\n"
"  test-tool date parse [date]...\n"
"  test-tool date approxidate [date]...\n"
"  test-tool date timestamp [date]...\n"
"  test-tool date getnanos [start-nanos]\n"
"  test-tool date is64bit\n"
"  test-tool date time_t-is64bit\n";

static void show_relative_dates(const char **argv)
{
	struct strbuf buf = STRBUF_INIT;

	for (; *argv; argv++) {
		time_t t = atoi(*argv);
		show_date_relative(t, &buf);
		printf("%s -> %s\n", *argv, buf.buf);
	}
	strbuf_release(&buf);
}

static void show_human_dates(const char **argv)
{
	for (; *argv; argv++) {
		time_t t = atoi(*argv);
		printf("%s -> %s\n", *argv, show_date(t, 0, NULL, DATE_MODE(HUMAN)));
	}
}

static void show_dates(const char **argv, const char *format)
{
	struct date_mode mode;

	parse_date_format(format, &mode);
	for (; *argv; argv++) {
		char *arg;
		timestamp_t t;
		int tz;

		/*
		 * Do not use our normal timestamp parsing here, as the point
		 * is to test the formatting code in isolation.
		 */
		t = parse_timestamp(*argv, &arg, 10);
		while (*arg == ' ')
			arg++;
		tz = atoi(arg);

		printf("%s -> %s\n", *argv, show_date(t, tz, NULL, &mode));
	}
}

static void parse_dates(const char **argv)
{
	struct strbuf result = STRBUF_INIT;

	for (; *argv; argv++) {
		timestamp_t t;
		int tz;

		strbuf_reset(&result);
		parse_date(*argv, &result);
		if (sscanf(result.buf, "%"PRItime" %d", &t, &tz) == 2)
			printf("%s -> %s\n",
			       *argv, show_date(t, tz, NULL, DATE_MODE(ISO8601)));
		else
			printf("%s -> bad\n", *argv);
	}
	strbuf_release(&result);
}

static void parse_approxidate(const char **argv)
{
	for (; *argv; argv++) {
		timestamp_t t;
		t = approxidate_relative(*argv);
		printf("%s -> %s\n", *argv, show_date(t, 0, NULL, DATE_MODE(ISO8601)));
	}
}

static void parse_approx_timestamp(const char **argv)
{
	for (; *argv; argv++) {
		timestamp_t t;
		t = approxidate_relative(*argv);
		printf("%s -> %"PRItime"\n", *argv, t);
	}
}

static void getnanos(const char **argv)
{
	double seconds = getnanotime() / 1.0e9;

	if (*argv)
		seconds -= strtod(*argv, NULL);
	printf("%lf\n", seconds);
}

int cmd__date(int argc, const char **argv)
{
	const char *x;

	argv++;
	if (!*argv)
		usage(usage_msg);
	if (!strcmp(*argv, "relative"))
		show_relative_dates(argv+1);
	else if (!strcmp(*argv, "human"))
		show_human_dates(argv+1);
	else if (skip_prefix(*argv, "show:", &x))
		show_dates(argv+1, x);
	else if (!strcmp(*argv, "parse"))
		parse_dates(argv+1);
	else if (!strcmp(*argv, "approxidate"))
		parse_approxidate(argv+1);
	else if (!strcmp(*argv, "timestamp"))
		parse_approx_timestamp(argv+1);
	else if (!strcmp(*argv, "getnanos"))
		getnanos(argv+1);
	else if (!strcmp(*argv, "is64bit"))
		return sizeof(timestamp_t) == 8 ? 0 : 1;
	else if (!strcmp(*argv, "time_t-is64bit"))
		return sizeof(time_t) == 8 ? 0 : 1;
	else
		usage(usage_msg);
	return 0;
}
debug log:

solving cf8d4574b7 ...
found cf8d4574b7 in https://public-inbox.org/git/20201013052851.373029-2-shengfa@google.com/
found 099eff4f0f in https://80x24.org/mirrors/git.git
preparing index
index prepared:
100644 099eff4f0fc880689d06c0b8b6301c3e83dff747	t/helper/test-date.c

applying [1/1] https://public-inbox.org/git/20201013052851.373029-2-shengfa@google.com/
diff --git a/t/helper/test-date.c b/t/helper/test-date.c
index 099eff4f0f..cf8d4574b7 100644

Checking patch t/helper/test-date.c...
Applied patch t/helper/test-date.c cleanly.

index at:
100644 cf8d4574b7c6db006f8593d3a4ec0e19542270bb	t/helper/test-date.c

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).