Skip to content

Commit f8493ec

Browse files
dschoJunio C Hamano
authored andcommitted
show_date(): rename the "relative" parameter to "mode"
Now, show_date() can print three different kinds of dates: normal, relative and short (%Y-%m-%s) dates. To achieve this, the "int relative" was changed to "enum date_mode mode", which has three states: DATE_NORMAL, DATE_RELATIVE and DATE_SHORT. Since existing users of show_date() only call it with relative_date being either 0 or 1, and DATE_NORMAL and DATE_RELATIVE having these values, no behaviour is changed. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 094e03b commit f8493ec

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

cache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ extern void *read_object_with_reference(const unsigned char *sha1,
315315
unsigned long *size,
316316
unsigned char *sha1_ret);
317317

318-
const char *show_date(unsigned long time, int timezone, int relative);
318+
enum date_mode { DATE_NORMAL = 0, DATE_RELATIVE, DATE_SHORT };
319+
const char *show_date(unsigned long time, int timezone, enum date_mode mode);
319320
const char *show_rfc2822_date(unsigned long time, int timezone);
320321
int parse_date(const char *date, char *buf, int bufsize);
321322
void datestamp(char *buf, int bufsize);

date.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ static struct tm *time_to_tm(unsigned long time, int tz)
5555
return gmtime(&t);
5656
}
5757

58-
const char *show_date(unsigned long time, int tz, int relative)
58+
const char *show_date(unsigned long time, int tz, enum date_mode mode)
5959
{
6060
struct tm *tm;
6161
static char timebuf[200];
6262

63-
if (relative) {
63+
if (mode == DATE_RELATIVE) {
6464
unsigned long diff;
6565
struct timeval now;
6666
gettimeofday(&now, NULL);
@@ -105,12 +105,16 @@ const char *show_date(unsigned long time, int tz, int relative)
105105
tm = time_to_tm(time, tz);
106106
if (!tm)
107107
return NULL;
108-
sprintf(timebuf, "%.3s %.3s %d %02d:%02d:%02d %d %+05d",
109-
weekday_names[tm->tm_wday],
110-
month_names[tm->tm_mon],
111-
tm->tm_mday,
112-
tm->tm_hour, tm->tm_min, tm->tm_sec,
113-
tm->tm_year + 1900, tz);
108+
if (mode == DATE_SHORT)
109+
sprintf(timebuf, "%04d-%02d-%02d", tm->tm_year + 1900,
110+
tm->tm_mon + 1, tm->tm_mday);
111+
else
112+
sprintf(timebuf, "%.3s %.3s %d %02d:%02d:%02d %d %+05d",
113+
weekday_names[tm->tm_wday],
114+
month_names[tm->tm_mon],
115+
tm->tm_mday,
116+
tm->tm_hour, tm->tm_min, tm->tm_sec,
117+
tm->tm_year + 1900, tz);
114118
return timebuf;
115119
}
116120

0 commit comments

Comments
 (0)