git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC PATCH v2] Add 'human' date format

From
Andrei Rybak <rybak.a.v@gmail.com>
Date
Jul 11, 2018, 20:34 UTC
Message-ID
<CACayv=ifE5BQVtxXCVEhS3uO7iz1z+ZPrF3J_n=e-uoYOpwNtA@mail.gmail.com>
In-Reply-To
<alpine.LFD.2.21.999.1807071502260.18818@i7.lan>
On 2018-07-08 00:02, Linus Torvalds wrote:
Show 37 quoted lines
> 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;
>  }
>
[...]
Show 6 quoted lines
> +
>  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

Show 19 quoted lines
>       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

Previous: Linus TorvaldsNext: Andrei Rybak
Message 5 of 14 in “Add 'human' date format”
  1. Add 'human' date formatLinus Torvalds, Jul 7, 2018
  2. Linus TorvaldsJul 7, 2018
  3. Linus TorvaldsJul 7, 2018
  4. Add 'human' date formatLinus Torvalds, Jul 7, 2018
  5. Andrei RybakJul 11, 2018
  6. Andrei RybakJul 11, 2018
  7. Junio C HamanoJul 11, 2018
  8. Linus TorvaldsJul 11, 2018
  9. Linus TorvaldsJul 11, 2018
  10. Ævar Arnfjörð BjarmasonJul 11, 2018
  11. Linus TorvaldsJul 11, 2018
  12. Junio C HamanoJul 24, 2018
  13. Linus TorvaldsJul 24, 2018
  14. Stephen P. SmithNov 27, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.