207
(diff + 183) / 365);
208
}
209
210
-struct date_mode *date_mode_from_type(enum date_mode_type type)
210
+struct date_mode date_mode_from_type(enum date_mode_type type)
211
{
212
- static struct date_mode mode = DATE_MODE_INIT;
212
+ struct date_mode mode = DATE_MODE_INIT;
213
if (type == DATE_STRFTIME)
214
BUG("cannot create anonymous strftime date_mode struct");
215
mode.type = type;
216
- return &mode;
216
+ return mode;
217
}
218
219
static void show_date_normal(struct strbuf *buf, timestamp_t time, struct tm *tm, int tz, struct tm *human_tm, int human_tz, int local)
283
strbuf_addf(buf, " %+05d", tz);
284
}
285
286
-const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
286
+const char *show_date(timestamp_t time, int tz, struct date_mode mode)
287
{
288
struct tm *tm;
289
struct tm tmbuf = { 0 };
291
int human_tz = -1;
292
static struct strbuf timebuf = STRBUF_INIT;
293
294
- if (mode->type == DATE_UNIX) {
294
+ if (mode.type == DATE_UNIX) {
295
strbuf_reset(&timebuf);
296
strbuf_addf(&timebuf, "%"PRItime, time);
297
return timebuf.buf;
298
}
299
300
- if (mode->type == DATE_HUMAN) {
300
+ if (mode.type == DATE_HUMAN) {
301
struct timeval now;
302
303
get_time(&now);
306
human_tz = local_time_tzoffset(now.tv_sec, &human_tm);
307
}
308
309
- if (mode->local)
309
+ if (mode.local)
310
tz = local_tzoffset(time);
311
312
- if (mode->type == DATE_RAW) {
312
+ if (mode.type == DATE_RAW) {
313
strbuf_reset(&timebuf);
314
strbuf_addf(&timebuf, "%"PRItime" %+05d", time, tz);
315
return timebuf.buf;
316
}
317
318
- if (mode->type == DATE_RELATIVE) {
318
+ if (mode.type == DATE_RELATIVE) {
319
strbuf_reset(&timebuf);
320
show_date_relative(time, &timebuf);
321
return timebuf.buf;
322
}
323
324
- if (mode->local)
324
+ if (mode.local)
325
tm = time_to_tm_local(time, &tmbuf);
326
else
327
tm = time_to_tm(time, tz, &tmbuf);
331
}
332
333
strbuf_reset(&timebuf);
334
- if (mode->type == DATE_SHORT)
334
+ if (mode.type == DATE_SHORT)
335
strbuf_addf(&timebuf, "%04d-%02d-%02d", tm->tm_year + 1900,
336
tm->tm_mon + 1, tm->tm_mday);
337
- else if (mode->type == DATE_ISO8601)
337
+ else if (mode.type == DATE_ISO8601)
338
strbuf_addf(&timebuf, "%04d-%02d-%02d %02d:%02d:%02d %+05d",
339
tm->tm_year + 1900,
340
tm->tm_mon + 1,
341
tm->tm_mday,
342
tm->tm_hour, tm->tm_min, tm->tm_sec,
343
tz);
344
- else if (mode->type == DATE_ISO8601_STRICT) {
344
+ else if (mode.type == DATE_ISO8601_STRICT) {
345
strbuf_addf(&timebuf, "%04d-%02d-%02dT%02d:%02d:%02d",
346
tm->tm_year + 1900,
347
tm->tm_mon + 1,
354
tz = abs(tz);
355
strbuf_addf(&timebuf, "%02d:%02d", tz / 100, tz % 100);
356
}
357
- } else if (mode->type == DATE_RFC2822)
357
+ } else if (mode.type == DATE_RFC2822)
358
strbuf_addf(&timebuf, "%.3s, %d %.3s %d %02d:%02d:%02d %+05d",
359
weekday_names[tm->tm_wday], tm->tm_mday,
360
month_names[tm->tm_mon], tm->tm_year + 1900,
361
tm->tm_hour, tm->tm_min, tm->tm_sec, tz);
362
- else if (mode->type == DATE_STRFTIME)
363
- strbuf_addftime(&timebuf, mode->strftime_fmt, tm, tz,
364
- !mode->local);
362
+ else if (mode.type == DATE_STRFTIME)
363
+ strbuf_addftime(&timebuf, mode.strftime_fmt, tm, tz,
364
+ !mode.local);
365
else
366
- show_date_normal(&timebuf, time, tm, tz, &human_tm, human_tz, mode->local);
366
+ show_date_normal(&timebuf, time, tm, tz, &human_tm, human_tz, mode.local);
367
return timebuf.buf;
368
}
369