On 2018-07-08 00:02, Linus Torvalds wrote:
> diff --git a/date.c b/date.c
> index 49f943e25..4486c028a 100644
> --- a/date.c
> +++ b/date.c
> @@ -77,22 +77,16 @@ static struct tm *time_to_tm_local(timestamp_t time)
> }
>
> /*
> - * What value of "tz" was in effect back then at "time" in the
> - * local timezone?
> + * Fill in the localtime 'struct tm' for the supplied time,
> + * and return the local tz.
> */
> -static int local_tzoffset(timestamp_t time)
> +static int local_time_tzoffset(time_t t, struct tm *tm)
> {
> - time_t t, t_local;
> - struct tm tm;
> + time_t t_local;
> int offset, eastwest;
>
> - if (date_overflows(time))
> - die("Timestamp too large for this system: %"PRItime, time);
> -
> - t = (time_t)time;
> - localtime_r(&t, &tm);
> - t_local = tm_to_time_t(&tm);
> -
> + localtime_r(&t, tm);
> + t_local = tm_to_time_t(tm);
> if (t_local == -1)
> return 0; /* error; just use +0000 */
> if (t_local < t) {
> @@ -107,6 +101,20 @@ static int local_tzoffset(timestamp_t time)
> return offset * eastwest;
> }
>
[...]
> +
> const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
> {
> struct tm *tm;
> + struct tm human_tm = { 0 };
> + int human_tz = -1;
Is -1 an OK initial value for timezone if local_time_tzoffset returns
negative values as well? It looks like it doesn't matter for from functional
> static struct strbuf timebuf = STRBUF_INIT;
>
> if (mode->type == DATE_UNIX) {
> @@ -202,6 +281,15 @@ const char *show_date(timestamp_t time, int tz, const
> struct date_mode *mode)
> return timebuf.buf;
> }
>
> + if (mode->type == DATE_HUMAN) {
> + struct timeval now;
> +
> + gettimeofday(&now, NULL);
> +
> + /* Fill in the data for "current time" in human_tz and human_tm
> */
> + human_tz = local_time_tzoffset(now.tv_sec, &human_tm);
> + }
> +
> if (mode->local)
> tz = local_tzoffset(time);
>
--
Best regards, Andrei Rybak