return local_time_tzoffset((time_t)time, &tm);
}
-void show_date_relative(timestamp_t time, int tz,
- const struct timeval *now,
- struct strbuf *timebuf)
+static void get_time(struct timeval *now)
+{
+ const char *x;
+
+ x = getenv("GIT_TEST_DATE_NOW");
+ if (x) {
+ now->tv_sec = atoi(x);
+ now->tv_usec = 0;
+ }
+ else
+ gettimeofday(now, NULL);
+}
+
+void show_date_relative(timestamp_t time,
+ const struct timeval *now,
+ struct strbuf *timebuf)
{
timestamp_t diff;
if (now->tv_sec < time) {
/* Show "today" times as just relative times */
if (hide.wday) {
struct timeval now;
- gettimeofday(&now, NULL);
- show_date_relative(time, tz, &now, buf);
+ get_time(&now);
+ show_date_relative(time, &now, buf);
return;
}
if (mode->type == DATE_HUMAN) {
struct timeval now;
- gettimeofday(&now, NULL);
+ get_time(&now);
/* Fill in the data for "current time" in human_tz and human_tm */
human_tz = local_time_tzoffset(now.tv_sec, &human_tm);
struct timeval now;
strbuf_reset(&timebuf);
- gettimeofday(&now, NULL);
- show_date_relative(time, tz, &now, &timebuf);
+ get_time(&now);
+ show_date_relative(time, &now, &timebuf);
return timebuf.buf;
}
return DATE_UNIX;
if (skip_prefix(format, "format", end))
return DATE_STRFTIME;
+ /*
+ * Please update $__git_log_date_formats in
+ * git-completion.bash when you add new formats.
+ */
die("unknown date format %s", format);
}
return n;
}
+/*
+ * Do we have a pending number at the end, or when
+ * we see a new one? Let's assume it's a month day,
+ * as in "Dec 6, 1992"
+ */
+static void pending_number(struct tm *tm, int *num)
+{
+ int number = *num;
+
+ if (number) {
+ *num = 0;
+ if (tm->tm_mday < 0 && number < 32)
+ tm->tm_mday = number;
+ else if (tm->tm_mon < 0 && number < 13)
+ tm->tm_mon = number-1;
+ else if (tm->tm_year < 0) {
+ if (number > 1969 && number < 2100)
+ tm->tm_year = number - 1900;
+ else if (number > 69 && number < 100)
+ tm->tm_year = number;
+ else if (number < 38)
+ tm->tm_year = 100 + number;
+ /* We screw up for number = 00 ? */
+ }
+ }
+}
+
static void date_now(struct tm *tm, struct tm *now, int *num)
{
+ *num = 0;
update_tm(tm, now, 0);
}
static void date_yesterday(struct tm *tm, struct tm *now, int *num)
{
+ *num = 0;
update_tm(tm, now, 24*60*60);
}
static void date_time(struct tm *tm, struct tm *now, int hour)
{
if (tm->tm_hour < hour)
- date_yesterday(tm, now, NULL);
+ update_tm(tm, now, 24*60*60);
tm->tm_hour = hour;
tm->tm_min = 0;
tm->tm_sec = 0;
static void date_midnight(struct tm *tm, struct tm *now, int *num)
{
+ pending_number(tm, num);
date_time(tm, now, 0);
}
static void date_noon(struct tm *tm, struct tm *now, int *num)
{
+ pending_number(tm, num);
date_time(tm, now, 12);
}
static void date_tea(struct tm *tm, struct tm *now, int *num)
{
+ pending_number(tm, num);
date_time(tm, now, 17);
}
{
time_t n = 0;
localtime_r(&n, tm);
+ *num = 0;
}
static const struct special {
return end;
}
-/*
- * Do we have a pending number at the end, or when
- * we see a new one? Let's assume it's a month day,
- * as in "Dec 6, 1992"
- */
-static void pending_number(struct tm *tm, int *num)
-{
- int number = *num;
-
- if (number) {
- *num = 0;
- if (tm->tm_mday < 0 && number < 32)
- tm->tm_mday = number;
- else if (tm->tm_mon < 0 && number < 13)
- tm->tm_mon = number-1;
- else if (tm->tm_year < 0) {
- if (number > 1969 && number < 2100)
- tm->tm_year = number - 1900;
- else if (number > 69 && number < 100)
- tm->tm_year = number;
- else if (number < 38)
- tm->tm_year = 100 + number;
- /* We screw up for number = 00 ? */
- }
- }
-}
-
static timestamp_t approxidate_str(const char *date,
const struct timeval *tv,
int *error_ret)
return timestamp;
}
- gettimeofday(&tv, NULL);
+ get_time(&tv);
return approxidate_str(date, &tv, error_ret);
}