{"thread":{"id":"21141","subject":"[PATCH/RFC] New date format: local_original","startedAt":"2009-10-06T19:09:47Z","lastAt":"2009-10-07T23:31:39Z","messageCount":4,"participants":["Tuomas Suutari","Jeff King","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"124319","messageId":"200910062209.47606.tuomas.suutari@gmail.com","threadId":"21141","inReplyTo":null,"subject":"[PATCH/RFC] New date format: local_original","fromName":"Tuomas Suutari","fromEmail":"tuomas.suutari@gmail.com","sentAt":"2009-10-06T19:09:47Z","receivedAt":"2009-10-06T19:09:47Z","isPatch":true,"sender":{"key":"tuomas.suutari@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2368817?v=4"},"body":"Formats date and time with local and original timezone representation\nin same string. They both can be useful at the same time: local\ntimezone for relating timestamp to local events, and original timezone\nto see the author's time of the day.\n\nThe format is ISO-8601 timestamp with weekday in local timezone\nfollowed by weekday and time in original timezone in parentheses. The\nweekday part makes it easier to understand the timestamps when the\ndays differ. For example, if local timezone is +0800, then timestamp\n2009-10-04T19:37:03+0300 would be formatted as\n\"Mon 2009-10-05 00:37:03 (Sun 19:37:03 +0300)\".\n\nSigned-off-by: Tuomas Suutari <tuomas.suutari@gmail.com>\n---\n\nIt was hard to decide whether to use --date=local or --date=iso\nwith git log, so I though that maybe I could have them both.\n\nHardest part was to decide the actual format string, especially\nbecause they tend to get so long. My solution for that,\nis to drop the date part out from the other timestamp and use\nweekday as a way to relate them to each other.\n\nSo, what do you think? Could this be useful for anyone else?\nAny better ideas for the format string?\n\nps. I tried to find the relevant parts of the documentation\nand tests by grepping the names of the other formats (iso8601\nand rfc2822) and updated them, but I could have easily missed\nsomething. Tests did not show any new problems, but the\ncvsimport tests (t960?) didn't seem to work before or after\nmy changes.\n\n Documentation/git-for-each-ref.txt     |    4 ++--\n Documentation/rev-list-options.txt     |    4 +++-\n builtin-blame.c                        |    3 +++\n cache.h                                |    3 ++-\n contrib/completion/git-completion.bash |    5 ++++-\n date.c                                 |   23 +++++++++++++++++++++++\n t/t6300-for-each-ref.sh                |   15 ++++++++++++++-\n 7 files changed, 51 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt\nindex 8dc873f..00525c2 100644\n--- a/Documentation/git-for-each-ref.txt\n+++ b/Documentation/git-for-each-ref.txt\n@@ -114,8 +114,8 @@ returns an empty string instead.\n \n As a special case for the date-type fields, you may specify a format for\n the date by adding one of `:default`, `:relative`, `:short`, `:local`,\n-`:iso8601` or `:rfc2822` to the end of the fieldname; e.g.\n-`%(taggerdate:relative)`.\n+`:iso8601`, `:rfc2822`, or `:local_original`, to the end of the\n+fieldname; e.g. `%(taggerdate:relative)`.\n \n \n EXAMPLES\ndiff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt\nindex bf66116..e007244 100644\n--- a/Documentation/rev-list-options.txt\n+++ b/Documentation/rev-list-options.txt\n@@ -13,7 +13,7 @@ include::pretty-options.txt[]\n \n \tSynonym for `--date=relative`.\n \n---date={relative,local,default,iso,rfc,short,raw}::\n+--date={relative,local,default,iso,rfc,short,raw,local_original}::\n \n \tOnly takes effect for dates shown in human-readable format, such\n \tas when using \"--pretty\". `log.date` config variable sets a default\n@@ -35,6 +35,8 @@ format, often found in E-mail messages.\n +\n `--date=default` shows timestamps in the original timezone\n (either committer's or author's).\n++\n+`--date=local_original` shows timestamps in local and original timezone.\n \n ifdef::git-rev-list[]\n --header::\ndiff --git a/builtin-blame.c b/builtin-blame.c\nindex 7512773..4766dd5 100644\n--- a/builtin-blame.c\n+++ b/builtin-blame.c\n@@ -2290,6 +2290,9 @@ parse_done:\n \tcase DATE_NORMAL:\n \t\tblame_date_width = sizeof(\"Thu Oct 19 16:00:04 2006 -0700\");\n \t\tbreak;\n+\tcase DATE_LOCAL_ORIGINAL:\n+\t\tblame_date_width = sizeof(\"Thu 2006-10-19 16:00:04 (Thu 16:00:04 -0700)\");\n+\t\tbreak;\n \t}\n \tblame_date_width -= 1; /* strip the null */\n \ndiff --git a/cache.h b/cache.h\nindex a5eeead..89c3c12 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -729,7 +729,8 @@ enum date_mode {\n \tDATE_LOCAL,\n \tDATE_ISO8601,\n \tDATE_RFC2822,\n-\tDATE_RAW\n+\tDATE_RAW,\n+\tDATE_LOCAL_ORIGINAL\n };\n \n const char *show_date(unsigned long time, int timezone, enum date_mode mode);\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 2c2a0d4..4f4ca53 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1152,7 +1152,10 @@ __git_log_shortlog_options=\"\n \"\n \n __git_log_pretty_formats=\"oneline short medium full fuller email raw format:\"\n-__git_log_date_formats=\"relative iso8601 rfc2822 short local default raw\"\n+__git_log_date_formats=\"\n+\trelative iso8601 rfc2822 short local default raw\n+\tlocal_original\n+\"\n \n _git_log ()\n {\ndiff --git a/date.c b/date.c\nindex 5d05ef6..b34a735 100644\n--- a/date.c\n+++ b/date.c\n@@ -151,6 +151,7 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)\n {\n \tstruct tm *tm;\n \tstatic char timebuf[200];\n+\tint n;\n \n \tif (mode == DATE_RAW) {\n \t\tsnprintf(timebuf, sizeof(timebuf), \"%lu %+05d\", time, tz);\n@@ -185,6 +186,26 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)\n \t\t\tweekday_names[tm->tm_wday], tm->tm_mday,\n \t\t\tmonth_names[tm->tm_mon], tm->tm_year + 1900,\n \t\t\ttm->tm_hour, tm->tm_min, tm->tm_sec, tz);\n+\telse if (mode == DATE_LOCAL_ORIGINAL) {\n+\t\t/* Use local timezone first... */\n+\t\ttm = time_to_tm(time, local_tzoffset(time));\n+\t\tif (!tm)\n+\t\t\treturn NULL;\n+\t\tn = sprintf(timebuf, \"%.3s %04d-%02d-%02d %02d:%02d:%02d\",\n+\t\t\tweekday_names[tm->tm_wday],\n+\t\t\ttm->tm_year + 1900,\n+\t\t\ttm->tm_mon + 1,\n+\t\t\ttm->tm_mday,\n+\t\t\ttm->tm_hour, tm->tm_min, tm->tm_sec);\n+\t\t/* ...and then original timezone. */\n+\t\ttm = time_to_tm(time, tz);\n+\t\tif (!tm)\n+\t\t\treturn NULL;\n+\t\tsprintf(timebuf + n, \" (%.3s %02d:%02d:%02d %+05d)\",\n+\t\t\tweekday_names[tm->tm_wday],\n+\t\t\ttm->tm_hour, tm->tm_min, tm->tm_sec,\n+\t\t\ttz);\n+\t}\n \telse\n \t\tsprintf(timebuf, \"%.3s %.3s %d %02d:%02d:%02d %d%c%+05d\",\n \t\t\t\tweekday_names[tm->tm_wday],\n@@ -656,6 +677,8 @@ enum date_mode parse_date_format(const char *format)\n \t\treturn DATE_NORMAL;\n \telse if (!strcmp(format, \"raw\"))\n \t\treturn DATE_RAW;\n+\telse if (!strcmp(format, \"local_original\"))\n+\t\treturn DATE_LOCAL_ORIGINAL;\n \telse\n \t\tdie(\"unknown date format %s\", format);\n }\ndiff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh\nindex 8052c86..1c91b21 100755\n--- a/t/t6300-for-each-ref.sh\n+++ b/t/t6300-for-each-ref.sh\n@@ -122,7 +122,8 @@ test_expect_success 'Check valid format specifiers for date fields' '\n \tgit for-each-ref --format=\"%(authordate:short)\" refs/heads &&\n \tgit for-each-ref --format=\"%(authordate:local)\" refs/heads &&\n \tgit for-each-ref --format=\"%(authordate:iso8601)\" refs/heads &&\n-\tgit for-each-ref --format=\"%(authordate:rfc2822)\" refs/heads\n+\tgit for-each-ref --format=\"%(authordate:rfc2822)\" refs/heads &&\n+\tgit for-each-ref --format=\"%(authordate:local_original)\" refs/heads\n '\n \n test_expect_success 'Check invalid format specifiers are errors' '\n@@ -211,6 +212,18 @@ test_expect_success 'Check format \"rfc2822\" date fields output' '\n '\n \n cat >expected <<\\EOF\n+'refs/heads/master' 'Mon 2006-07-03 15:18:43 (Mon 17:18:43 +0200)' 'Mon 2006-07-03 15:18:44 (Mon 17:18:44 +0200)'\n+'refs/tags/testtag' 'Mon 2006-07-03 15:18:45 (Mon 17:18:45 +0200)'\n+EOF\n+\n+test_expect_success 'Check format \"local_original\" date fields output' '\n+\tf=local_original &&\n+\t(git for-each-ref --shell --format=\"%(refname) %(committerdate:$f) %(authordate:$f)\" refs/heads &&\n+\tgit for-each-ref --shell --format=\"%(refname) %(taggerdate:$f)\" refs/tags) >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+cat >expected <<\\EOF\n refs/heads/master\n refs/remotes/origin/master\n refs/tags/testtag\n-- \n1.6.4.1\n"},{"id":"124333","messageId":"20091007125427.GA20067@coredump.intra.peff.net","threadId":"21141","inReplyTo":"200910062209.47606.tuomas.suutari@gmail.com","subject":"Re: [PATCH/RFC] New date format: local_original","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-10-07T12:54:27Z","receivedAt":"2009-10-07T12:54:27Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Oct 06, 2009 at 10:09:47PM +0300, Tuomas Suutari wrote:\n\n> Formats date and time with local and original timezone representation\n> in same string. They both can be useful at the same time: local\n> timezone for relating timestamp to local events, and original timezone\n> to see the author's time of the day.\n>\n> [...]\n>\n> It was hard to decide whether to use --date=local or --date=iso\n> with git log, so I though that maybe I could have them both.\n\nIt's not clear to me. Do you really _like_ seeing them both, or did you\nsimply want to see local dates in the iso format, but those two options\n(which are conceptually orthogonal) could not be used at the same time?\n\nIf the latter, then maybe we should resurrect the patch that allows\n\"--date=local --date=iso\" to do what you want. From this thread:\n\n  http://thread.gmane.org/gmane.comp.version-control.git/112026\n\nIf the former, then should the options be orthogonal? That is, should it\nbe a new format combining the two, or should it be an option to show, in\nyour preferred format, the time in both local and original time zones?\nE.g., something like:\n\n  $ git log --date=iso --local-dates-too\n  commit bf01a69ed40e1afcf56aff143f7523da2ce263ed\n  Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n  Date:   2009-10-04 00:41:55 +0200\n  Local:  2009-10-03 17:41:55 -0500\n\nAnd then you can use it with \"normal\" dates, iso dates, rfc2822 dates,\netc.\n\nI dunno. I have to admit I never personally really wanted anything\nexcept the default date format, unless I was parsing it for something\nspecial.\n\n-Peff\n"},{"id":"124343","messageId":"7vocojrn26.fsf@alter.siamese.dyndns.org","threadId":"21141","inReplyTo":"20091007125427.GA20067@coredump.intra.peff.net","subject":"Re: [PATCH/RFC] New date format: local_original","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-07T20:01:05Z","receivedAt":"2009-10-07T20:01:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> If the former, then should the options be orthogonal? That is, should it\n> be a new format combining the two, or should it be an option to show, in\n> your preferred format, the time in both local and original time zones?\n> E.g., something like:\n>\n>   $ git log --date=iso --local-dates-too\n>   commit bf01a69ed40e1afcf56aff143f7523da2ce263ed\n>   Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n>   Date:   2009-10-04 00:41:55 +0200\n>   Local:  2009-10-03 17:41:55 -0500\n>\n> And then you can use it with \"normal\" dates, iso dates, rfc2822 dates,\n> etc.\n\nThanks for comments.\n\nI think \"--date=iso --local-dates-too\" is still not orthogonal enough, let\nalone \"local_original\" which invites \"Why is this combination supported\nand not this, that, and 47 others?\" questions.\n\nI however do not think it is so bad an idea to allow something like:\n\n\tgit log --date='custom:%Y-%m-%d ...'\n\tgit log --date=custom\t;# looks at \"date.custom\" config\n\nYou (not Peff, but figuratively whoever wants to implement it) can add a\nmechanism to specify in which timezone (original or local) you would want\nthe timestring to be given, and make what Tuomas's RFC patch does a mere\nspecial case.  For example, we could reuse 'date \"+format\"' string with\nour own extension %{magic}, with two magic tokens initially defined:\n\n    %{local}\tinterpret timestamp in local zone from now on\n    %{original}\tinterpret timestamp in the original zone from now on\n\nWith such a mechanism Tuomas can define:\n\n\t[date]\n            custom=%{local}%a %Y-%m-%d %H:%M:%S %{original}(%a %H:%M:%S %z)\n\nand ask \"git log --date=custom\" to get what his patch does.\n"},{"id":"124351","messageId":"20091007233139.GB22533@coredump.intra.peff.net","threadId":"21141","inReplyTo":"7vocojrn26.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH/RFC] New date format: local_original","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-10-07T23:31:39Z","receivedAt":"2009-10-07T23:31:39Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Oct 07, 2009 at 01:01:05PM -0700, Junio C Hamano wrote:\n\n> I think \"--date=iso --local-dates-too\" is still not orthogonal enough, let\n> alone \"local_original\" which invites \"Why is this combination supported\n> and not this, that, and 47 others?\" questions.\n> \n> I however do not think it is so bad an idea to allow something like:\n> \n> \tgit log --date='custom:%Y-%m-%d ...'\n> \tgit log --date=custom\t;# looks at \"date.custom\" config\n\nThanks, that (and the %{local} bit) is a much better suggestion than\nmine, I think.\n\n-Peff\n"}]}