git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Andrei Rybak <rybak.a.v@gmail.com>
To: torvalds@linux-foundation.org, Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [RFC PATCH v2] Add 'human' date format
Date: Wed, 11 Jul 2018 22:34:19 +0200	[thread overview]
Message-ID: <CACayv=ifE5BQVtxXCVEhS3uO7iz1z+ZPrF3J_n=e-uoYOpwNtA@mail.gmail.com> (raw)
In-Reply-To: <alpine.LFD.2.21.999.1807071502260.18818@i7.lan>

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

  reply	other threads:[~2018-07-11 20:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-07 19:38 [RFC PATCH] Add 'human' date format Linus Torvalds
2018-07-07 19:58 ` Linus Torvalds
2018-07-07 20:12   ` Linus Torvalds
2018-07-07 22:02 ` [RFC PATCH v2] " Linus Torvalds
2018-07-11 20:34   ` Andrei Rybak [this message]
2018-07-11 20:38     ` Andrei Rybak
2018-07-11 20:54       ` Junio C Hamano
2018-07-11 20:49     ` Linus Torvalds
2018-07-11 21:23       ` Linus Torvalds
2018-07-11 21:24   ` Ævar Arnfjörð Bjarmason
2018-07-11 21:49     ` Linus Torvalds
2018-07-24 21:49   ` Junio C Hamano
2018-07-24 22:58     ` Linus Torvalds
2018-11-27  4:10   ` Stephen P. Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACayv=ifE5BQVtxXCVEhS3uO7iz1z+ZPrF3J_n=e-uoYOpwNtA@mail.gmail.com' \
    --to=rybak.a.v@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).