{"thread":{"id":"6456","subject":"[PATCH] show_date(): fix relative dates","startedAt":"2007-01-20T21:21:38Z","lastAt":"2007-01-21T02:48:14Z","messageCount":4,"participants":["Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"32173","messageId":"Pine.LNX.4.63.0701202203260.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6456","inReplyTo":null,"subject":"[PATCH] show_date(): fix relative dates","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-01-20T21:21:38Z","receivedAt":"2007-01-20T21:21:38Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nWe pass a timestamp (i.e. number of seconds elapsed since Jan 1 1970,\n00:00:00 GMT) to the function. So there is no need to \"fix\" the\ntimestamp according to the timezone.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n---\n\n\tJust compile & run this little test program to see what I mean:\n\n\t#include \"cache.h\"\n\n\tint main(int argc, char **argv)\n\t{\n\t\ttime_t t = time(NULL);\n\t\tprintf(\"%s\\n\", show_rfc2822_date(t, 100));\n\t\tprintf(\"%s\\n\", show_date(t, 100, 0));\n\t\tprintf(\"%s\\n\", show_date(t, 0, 0));\n\t\tprintf(\"%s\\n\", show_date(t, 100, 1));\n\t\tprintf(\"%s\\n\", show_date(t, 0, 1));\n\t\treturn 0;\n\t}\n\n\tHere, it outputs this:\n\n\tSat, 20 Jan 2007 22:20:42 +0100\n\tSat Jan 20 22:20:42 2007 +0100\n\tSat Jan 20 21:20:42 2007 +0000\n\tin the future\n\t0 seconds ago\n\n\tNoticed that \"in the future\"?\n\n date.c |    5 ++---\n 1 files changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/date.c b/date.c\nindex 7acb8cb..542c004 100644\n--- a/date.c\n+++ b/date.c\n@@ -62,12 +62,11 @@ const char *show_date(unsigned long time, int tz, int relative)\n \n \tif (relative) {\n \t\tunsigned long diff;\n-\t\ttime_t t = gm_time_t(time, tz);\n \t\tstruct timeval now;\n \t\tgettimeofday(&now, NULL);\n-\t\tif (now.tv_sec < t)\n+\t\tif (now.tv_sec < time)\n \t\t\treturn \"in the future\";\n-\t\tdiff = now.tv_sec - t;\n+\t\tdiff = now.tv_sec - time;\n \t\tif (diff < 90) {\n \t\t\tsnprintf(timebuf, sizeof(timebuf), \"%lu seconds ago\", diff);\n \t\t\treturn timebuf;\n-- \n1.5.0.rc1.g956c1-dirty\n"},{"id":"32181","messageId":"7v3b656vq5.fsf@assigned-by-dhcp.cox.net","threadId":"6456","inReplyTo":"Pine.LNX.4.63.0701202203260.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] show_date(): fix relative dates","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-01-21T00:59:14Z","receivedAt":"2007-01-21T00:59:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"I noticed this and have a different solution in the show-branch\n--reflog code (it does not pass tz).  I haven't thought about\nwhich solution is the correct one (and do not have time to think\nabout it now while writing this message, sorry -- will do the\nthinking later unless you beat me to it).\n"},{"id":"32183","messageId":"Pine.LNX.4.63.0701210219400.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6456","inReplyTo":"7v3b656vq5.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] show_date(): fix relative dates","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-01-21T01:34:21Z","receivedAt":"2007-01-21T01:34:21Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 20 Jan 2007, Junio C Hamano wrote:\n\n> I noticed this and have a different solution in the show-branch\n> --reflog code (it does not pass tz).\n\nActually, you do pass tz, but with a fixed value of 0. But this is only a \nworkaround.\n\nThe thing is, if you pass the same timestamp with a different timezone, \nabsolute (non-relative) date will show the same time, i.e. 22:24 +0000 \nis the same as 23:24 +0100.\n\nNow I expect the same of relative mode, only that the timezone does not \nmatter for relative mode _at all_.\n\nAs you can see in my patch for --walk-reflogs (to honour --relative-date), \nit can make sense to pass make the choice whether to show a relative or an \nabsolute date a runtime option (where you don't want to set tz to 0 \ndepending on relativa_date).\n\nI guess nobody realized that \"git log --relative-date\" does not work \ncorrectly (for all commits which were not committed in tz +0000), is due \nto its narrowspread use, or that it is not all that obviously wrong.\n\nHowever, I was very surprised when \"git log --walk-reflogs \n--relative-date\" showed me \"in the future\" for my last commits.\n\nIf you don't want to think it through, please just verify my reasoning by \ncompiling the script I gave with the patch both before and after applying \nthe patch. The absolute dates _and_ the relative dates should be all the \nsame, but the relative date with non-zero timezone is displayed as \"in the \nfuture\" withouth the patch.\n\nCiao,\nDscho\n"},{"id":"32186","messageId":"7vy7nx5c41.fsf@assigned-by-dhcp.cox.net","threadId":"6456","inReplyTo":"Pine.LNX.4.63.0701210219400.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] show_date(): fix relative dates","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-01-21T02:48:14Z","receivedAt":"2007-01-21T02:48:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> Now I expect the same of relative mode, only that the timezone does not \n> matter for relative mode _at all_.\n> ...\n> However, I was very surprised when \"git log --walk-reflogs \n> --relative-date\" showed me \"in the future\" for my last commits.\n\nExactly.\n\nYou are absolutely right.  I should have done that when I did\nthe show-branch --reflog workaround to pass 0.\n"}]}