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

Re: [PATCH 2/2] date.c: allow compact version of ISO-8601 datetime

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 15, 2020, 15:03 UTC
Message-ID
<xmqq5ze094gg.fsf@gitster.c.googlers.com>
In-Reply-To
<20200414202401.GC1879688@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 19 quoted lines
> On Tue, Apr 14, 2020 at 04:31:55PM +0700, Đoàn Trần Công Danh wrote:
>
>> @@ -666,6 +666,24 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
>>  		n++;
>>  	} while (isdigit(date[n]));
>>  
>> +	/* 8 digits, compact style of ISO-8601's date: YYYYmmDD */
>> +	if (n == 8) {
>> +		tm->tm_year = num / 10000 - 1900;
>> +		tm->tm_mon = (num % 10000) / 100 - 1;
>> +		tm->tm_mday = num % 100;
>> +		return n;
>> +	}
>
> I worry a little this may conflict with other approxidate heuristics.
>
> The only one I can think of is an actual unix timestamp, though, and we
> already require that to have at least 9 digits (plus anybody wanting to
> use one robustly really should be using @12345678).

I am OK with 1/2, but I'd worry a LOT about this one, if we didn't require 9 digits. 60/100 * 60/100 * 24/100 ~= 8.6% so limiting the hour/min/sec to sensible values is not a useful protection against ambiguity. We'd essentially be declaring that a raw UNIX timestamp without @ prefix is now hit-and-miss if we take this change, were there not the "must be at least 9 digits" requirement.

Somebody was thinking when he wrote the very beginning part of the match_digit() function ;-)

> We could probably tighten the heuristics a bit by insisting that the
> month and day be sensible. Or even year (see the 1900 to 2100 magic for
> the 4-digit year guess).

I do agree that we'd want 0 <= hr <= 24, 0 <= min <= 59, and 0 <= sec <= 60 (or should this be 61?), but it is for correctness of the new code. It wouldn't have any value in disambiguation from other formats, I would think. So, from that point of view, I would buy something like 1969 as a lower bound, but I am not sure if we necessarily want an upper bound for the year. What mistake are we protecting us against?

Thanks.
Show 13 quoted lines
>> +	/* 6 digits, compact style of ISO-8601's time: HHMMSS */
>> +	if (n == 6) {
>> +		tm->tm_hour = num / 10000;
>> +		tm->tm_min = (num % 10000) / 100;
>> +		tm->tm_sec = num % 100;
>> +		if (*end == '.' && isdigit(end[1]))
>> +			strtoul(end + 1, &end, 10);
>> +		return end - date;
>> +	}
>
> And likewise here that the hour, minute, and second be reasonable.
>
> -Peff
Previous: Danh DoanNext: Jeff King
Message 12 of 49 in “Mishandling of fractional seconds in ISO 8601 format”
  1. brian m. carlsonApr 14, 2020
  2. 0/2 More ISO-8601 supportĐoàn Trần Công Danh, Apr 14, 2020
  3. 1/2 date.c: allow fractional second part of ISO-8601Đoàn Trần Công Danh, Apr 14, 2020
  4. Jeff KingApr 14, 2020
  5. Danh DoanApr 15, 2020
  6. Jeff KingApr 14, 2020
  7. brian m. carlsonApr 14, 2020
  8. Danh DoanApr 15, 2020
  9. 2/2 date.c: allow compact version of ISO-8601 datetimeĐoàn Trần Công Danh, Apr 14, 2020
  10. Jeff KingApr 14, 2020
  11. Danh DoanApr 15, 2020
  12. Junio C HamanoApr 15, 2020
  13. Jeff KingApr 15, 2020
  14. Junio C HamanoApr 15, 2020
  15. Danh DoanApr 16, 2020
  16. brian m. carlsonApr 14, 2020
  17. 0/2 More ISO-8601 supportĐoàn Trần Công Danh, Apr 15, 2020
  18. 1/2 date.c: skip fractional second part of ISO-8601Đoàn Trần Công Danh, Apr 15, 2020
  19. Torsten BögershausenApr 15, 2020
  20. Danh DoanApr 16, 2020
  21. 2/2 date.c: allow compact version of ISO-8601 datetimeĐoàn Trần Công Danh, Apr 15, 2020
  22. 0/2 More ISO-8601 supportĐoàn Trần Công Danh, Apr 22, 2020
  23. 1/2 date.c: skip fractional second part of ISO-8601Đoàn Trần Công Danh, Apr 22, 2020
  24. Junio C HamanoApr 22, 2020
  25. Danh DoanApr 23, 2020
  26. Junio C HamanoApr 23, 2020
  27. Philip OakleyApr 23, 2020
  28. Danh DoanApr 24, 2020
  29. Junio C HamanoApr 24, 2020
  30. Philip OakleyApr 24, 2020
  31. Philip OakleyApr 24, 2020
  32. 2/2 date.c: allow compact version of ISO-8601 datetimeĐoàn Trần Công Danh, Apr 22, 2020
  33. Junio C HamanoApr 22, 2020
  34. Danh DoanApr 23, 2020
  35. 0/4 More ISO-8601 supportĐoàn Trần Công Danh, Apr 23, 2020
  36. 1/4 date.c: s/is_date/set_date/Đoàn Trần Công Danh, Apr 23, 2020
  37. Junio C HamanoApr 23, 2020
  38. 2/4 date.c: validate and set time in a helper functionĐoàn Trần Công Danh, Apr 23, 2020
  39. Junio C HamanoApr 23, 2020
  40. Danh DoanApr 24, 2020
  41. Junio C HamanoApr 24, 2020
  42. 3/4 date.c: skip fractional second part of ISO-8601Đoàn Trần Công Danh, Apr 23, 2020
  43. Junio C HamanoApr 23, 2020
  44. 4/4 date.c: allow compact version of ISO-8601 datetimeĐoàn Trần Công Danh, Apr 23, 2020
  45. 0/4 More ISO-8601 supportĐoàn Trần Công Danh, Apr 24, 2020
  46. 1/4 date.c: s/is_date/set_date/Đoàn Trần Công Danh, Apr 24, 2020
  47. 2/4 date.c: validate and set time in a helper functionĐoàn Trần Công Danh, Apr 24, 2020
  48. 3/4 date.c: skip fractional second part of ISO-8601Đoàn Trần Công Danh, Apr 24, 2020
  49. 4/4 date.c: allow compact version of ISO-8601 datetimeĐoàn Trần Công Danh, Apr 24, 2020

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.