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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Feb 27, 2007 at 16:21 UTC
f8493ec09bcdbd616084dcfa6f5b8ca0bbb68acf
2 files changed
+14
-9
cache.h
+2
-1
@@ -315,7 +315,8 @@ extern void *read_object_with_reference(const unsigned char *sha1,
315
unsigned long *size,
316
unsigned char *sha1_ret);
317
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);
320
const char *show_rfc2822_date(unsigned long time, int timezone);
321
int parse_date(const char *date, char *buf, int bufsize);
322
void datestamp(char *buf, int bufsize);
date.c
+12
-8
@@ -55,12 +55,12 @@ static struct tm *time_to_tm(unsigned long time, int tz)
55
return gmtime(&t);
56
}
57
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)
59
{
60
struct tm *tm;
61
static char timebuf[200];
62
63
- if (relative) {
63
+ if (mode == DATE_RELATIVE) {
64
unsigned long diff;
65
struct timeval now;
66
gettimeofday(&now, NULL);
@@ -105,12 +105,16 @@ const char *show_date(unsigned long time, int tz, int relative)
105
tm = time_to_tm(time, tz);
106
if (!tm)
107
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);
118
return timebuf;
119
}
120