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

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

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Jul 11, 2018, 21:23 UTC
Message-ID
<CA+55aFx8-hni4WoDpc6jkNo03GJr1jVbRr5-Pz35X=yaq+hEqQ@mail.gmail.com>
In-Reply-To
<CA+55aFym5aSudSHiVA=VmvoY=WFytUqficLQCE4Sd_urjwKqPw@mail.gmail.com>
[ Trying to come up with crazy special cases ]

On Wed, Jul 11, 2018 at 1:49 PM Linus Torvalds <torvalds@linux-foundation.org> wrote:

>
> But it could be anything else invalid, of course. It could be MAX_INT
> or something like that.

That might be better. A timezone of -1 isn't actually a valid timezone, but I guess you could create a commit by hand that had "-0001" as the timezone.

You can't do that with something like MAX_INT, without fsck complaining - since it has to be exactly four digits.

Show 7 quoted lines
> The clearing of "human_tm" is done for a similar reason: the code does
>
>         hide.year = tm->tm_year == human_tm->tm_year;
>
> (and then later just checks "if (human_tm->tm_year)") knowing that a
> non-zero tm_year will only ever happen for human_tz (and that 1900 is
> not a valid git date, even though I guess in theory you could do it).

Actually, the 1900 should be safe, because 'timestamp_t' is unsigned. So a valid timestamp really can't be before 1970.

Of course, you can probably try to mess with it by giving values that don't actually fit, because sometimes we do convert mindlessly from 'timestamp_t' to 'time_t'. In particular, if you use the "default-local" time, it will use that

  static struct tm *time_to_tm_local(timestamp_t time)
  {
        time_t t = time;
        return localtime(&t);
  }
and not check the range of the timestamp.

But other proper time stamp functions will actually do range checking with "date_overflow()", so in general that whole assumption of "a real git date cannot be in the year 1900" is valid.

              Linus
Previous: Linus TorvaldsNext: Ævar Arnfjörð Bjarmason
Message 9 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.