{"thread":{"id":"42463","subject":"RFC: dynamic \"auto\" date formats","startedAt":"2016-05-27T03:36:57Z","lastAt":"2016-05-27T06:57:11Z","messageCount":4,"participants":["Linus Torvalds","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"287642","messageId":"CA+55aFzWEf2sN647v0mfiPOFE=KindQpweoHwdPmDshUb0YVsA@mail.gmail.com","threadId":"42463","inReplyTo":null,"subject":"RFC: dynamic \"auto\" date formats","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2016-05-27T03:36:57Z","receivedAt":"2016-05-27T03:36:57Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"This is a throw-away idea with a simple patch attached, which I don't\nthink anybody should really take all that seriously per se, but I\nthought I'd throw it out and see if it generates any discussion.\n\nI almost never use anything but the default date format (DATE_NORMAL),\nbut every once in a while I will use \"--date=relative\", typically\nbecause I'm looking at my own commits and I'm just checking when I did\nsomething.\n\nIt struck me that I've made the default for most of the logging things\nbe that when I'm just browsing with the pager, git will automatically\ndo the right thing. So I have\n\n  [color]\n      ui=auto\n\n  [log]\n      decorate = auto\n\nin my ~/.gitconfig, and it shows me all those other things I tench to\nwant to know (like \"thar's what I've pushed out\" thanks to\ndecorations).\n\nSo I started thinking about when I care about dates, and decided that\nmaybe I can have a \"--date=auto\" too. It basically uses relative date\nformats for the last 24 hours, and then switches over to the default\nformat.\n\nI've used it a bit, and like Katy Perry said, I think I might like it.\n\nNote that this doesn't add any gitconfig setting to do this, which\nwould be part of the whole point if this is actually sensible. But I'm\nnot entirely convinced it's worth it in the first place, thus this\nemail to see how people react (\"That's just stupid\" vs \"yeah, I didn't\neven know I wanted it, but now I need it\").\n\nAnd no, I'm not at all sure that the 24-hour cut-off is the right\nthing, but it didn't seem completely crazy either. I tend to like the\nrelative date format when it is \"19 minutes ago\" vs \"2 hours ago\", at\nsome point it's long enough ago that it's more useful to know \"Tuesday\nat 3pm\" than about how long ago it was.\n\n(And yes, it would be even better to have the \"short term relative\ndate\" turn into a \"medium-term 'day of the week at time x'\" and then\nturn into \"full date\" when it's more than a week ago, but this patch\nonly has the two modes of \"short term\" and \"long term\" and nothing in\nbetween).\n\n               Linus\n\n\n builtin/blame.c |  1 +\n cache.h         |  3 ++-\n date.c          | 10 +++++++---\n 3 files changed, 10 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 21f42b0b62b8..4d87181dc6cd 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -2640,6 +2640,7 @@ parse_done:\n \t\t   fewer display columns. */\n \t\tblame_date_width = utf8_strwidth(_(\"4 years, 11 months ago\")) + 1; /* add the null */\n \t\tbreak;\n+\tcase DATE_AUTO:\n \tcase DATE_NORMAL:\n \t\tblame_date_width = sizeof(\"Thu Oct 19 16:00:04 2006 -0700\");\n \t\tbreak;\ndiff --git a/cache.h b/cache.h\nindex 6049f8671138..624817c20414 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1223,7 +1223,8 @@ struct date_mode {\n \t\tDATE_ISO8601_STRICT,\n \t\tDATE_RFC2822,\n \t\tDATE_STRFTIME,\n-\t\tDATE_RAW\n+\t\tDATE_RAW,\n+\t\tDATE_AUTO,\n \t} type;\n \tconst char *strftime_fmt;\n \tint local;\ndiff --git a/date.c b/date.c\nindex 7c9f76998ac7..c38414a3d968 100644\n--- a/date.c\n+++ b/date.c\n@@ -184,13 +184,15 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode)\n \t\treturn timebuf.buf;\n \t}\n \n-\tif (mode->type == DATE_RELATIVE) {\n+\tif (mode->type == DATE_RELATIVE || mode->type == DATE_AUTO) {\n \t\tstruct timeval now;\n \n \t\tstrbuf_reset(&timebuf);\n \t\tgettimeofday(&now, NULL);\n-\t\tshow_date_relative(time, tz, &now, &timebuf);\n-\t\treturn timebuf.buf;\n+\t\tif (mode->type != DATE_AUTO || time + 24*60*60 > now.tv_sec) {\n+\t\t\tshow_date_relative(time, tz, &now, &timebuf);\n+\t\t\treturn timebuf.buf;\n+\t\t}\n \t}\n \n \ttm = time_to_tm(time, tz);\n@@ -792,6 +794,8 @@ static enum date_mode_type parse_date_type(const char *format, const char **end)\n \t\treturn DATE_RAW;\n \tif (skip_prefix(format, \"format\", end))\n \t\treturn DATE_STRFTIME;\n+\tif (skip_prefix(format, \"auto\", end))\n+\t\treturn DATE_AUTO;\n \n \tdie(\"unknown date format %s\", format);\n }\n"},{"id":"287647","messageId":"20160527040031.GB24972@sigill.intra.peff.net","threadId":"42463","inReplyTo":"CA+55aFzWEf2sN647v0mfiPOFE=KindQpweoHwdPmDshUb0YVsA@mail.gmail.com","subject":"Re: RFC: dynamic \"auto\" date formats","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-05-27T04:00:31Z","receivedAt":"2016-05-27T04:00:31Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, May 26, 2016 at 08:36:57PM -0700, Linus Torvalds wrote:\n\n> Note that this doesn't add any gitconfig setting to do this, which\n> would be part of the whole point if this is actually sensible. But I'm\n> not entirely convinced it's worth it in the first place, thus this\n> email to see how people react (\"That's just stupid\" vs \"yeah, I didn't\n> even know I wanted it, but now I need it\").\n> \n> And no, I'm not at all sure that the 24-hour cut-off is the right\n> thing, but it didn't seem completely crazy either. I tend to like the\n> relative date format when it is \"19 minutes ago\" vs \"2 hours ago\", at\n> some point it's long enough ago that it's more useful to know \"Tuesday\n> at 3pm\" than about how long ago it was.\n\nSeems like a reasonable idea, though I doubt I'd use it myself. In\naddition to possibly making the cutoff-time configurable, I'd expect\npeople would want the fallback format to be configurable, too.\n\nI wonder if something like:\n\n  --date=relative:24h:iso\n\nwould make sense as \"relative up to 24 hours, then iso\". You could even\nchain them, so your:\n\n> (And yes, it would be even better to have the \"short term relative\n> date\" turn into a \"medium-term 'day of the week at time x'\" and then\n> turn into \"full date\" when it's more than a week ago, but this patch\n> only has the two modes of \"short term\" and \"long term\" and nothing in\n> between).\n\ncould be something like:\n\n  --date=relative:24h:short:1w:normal\n\n(where \"short\" actually kind of sucks; we'd introduce a new format for\nyour \"Tuesday at 10pm\" output).\n\nI admit it's a bit baroque to look at, though.\n\n-Peff\n"},{"id":"287656","messageId":"xmqq1t4ot418.fsf@gitster.mtv.corp.google.com","threadId":"42463","inReplyTo":"CA+55aFzWEf2sN647v0mfiPOFE=KindQpweoHwdPmDshUb0YVsA@mail.gmail.com","subject":"Re: RFC: dynamic \"auto\" date formats","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-05-27T06:21:07Z","receivedAt":"2016-05-27T06:21:07Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Torvalds <torvalds@linux-foundation.org> writes:\n\n> And no, I'm not at all sure that the 24-hour cut-off is the right\n> thing, but it didn't seem completely crazy either. I tend to like the\n> relative date format when it is \"19 minutes ago\" vs \"2 hours ago\", at\n> some point it's long enough ago that it's more useful to know \"Tuesday\n> at 3pm\" than about how long ago it was.\n>\n> (And yes, it would be even better to have the \"short term relative\n> date\" turn into a \"medium-term 'day of the week at time x'\" and then\n> turn into \"full date\" when it's more than a week ago, but this patch\n> only has the two modes of \"short term\" and \"long term\" and nothing in\n> between).\n\nWhile I do not think this has much to do with \"auto\", other than\nthat it changes the representation depending on how far back the\ntime is to match the taste of Linus automatically, I think the\nobservation you made about the relative uselessness of \"relative in\nthe long past\" is real.  \"6 years ago\" that does not say if it was\nin the morning and that does not even say if it was in the summer\nis losing a bit too much information.\n\nYour message made me realize another thing I feel while viewing\n\"relative in the long past\" output.  In \"git log --date=relative\"\noutput (especially when the log is \"limited\" in some way, like with\na pathspec, --grep, -S, etc.) that shows multiple commits, all of\nwhich are labeled \"6 years ago\", they make me wonder how they are\nrelated to each other chronologically.  Perhaps I am seeing 6\ncommits, but the earlier four was made all within 20 minutes, and\nthe fifth one three days later, and the final one a month later,\nwhich may indicate that the first four was the initial round of a\ntopic, with two \"oops, this is a fix\" follow-up patches that are\nrelated in one area.  All of them being labeled \"6 years ago\" would\nnot give such a clue.\n\nWhich makes me wonder if another variant is useful (or at least\n\"interesting\").  What if we chose format according to this rule?\n\n    0. Set the \"reference time\" to the current time.\n\n    1. Do get_revision() to grab one commit to show.\n\n    2. Show that commit, using timeformat determined as:\n       a. if its time is close to the \"reference time\", then use\n          \"N hours M minues before that\" format;\n       b. otherwise, use the default time format;\n\n    3. Update the \"reference time\" to the timestamp of the commit\n       we just showed.\n\n    4. Go back to 1.\n    \n"},{"id":"287660","messageId":"CAPc5daVQEnehW311wi5U2Fs0cdYKzW_jqwpQ8M3c6ZqNGXuLsA@mail.gmail.com","threadId":"42463","inReplyTo":"CA+55aFwhUJ2g9690yMBR3inZmVXRupmgjbePmm4GC5kEcx2XLA@mail.gmail.com","subject":"Re: RFC: dynamic \"auto\" date formats","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-05-27T06:57:11Z","receivedAt":"2016-05-27T06:57:11Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"On Thu, May 26, 2016 at 11:53 PM, Linus Torvalds\n<torvalds@linux-foundation.org> wrote:\n>\n> So I think what I really would like to see is more like a reverse\n> \"approxidate\" that gives the date in human terms.\n\nYeah, \"human\" was the word I was looking for while composing my response.\n\nI am sure somebody will write the reverse approxidate that utters \"tea\ntime\" when\nit is appropriate, if only just for fun. I can't wait ;-)\n"}]}