{"thread":{"id":"315","subject":"[PATCH] Fix rfc2822 date parser","startedAt":"2005-04-25T21:32:44Z","lastAt":"2005-04-25T21:32:44Z","messageCount":1,"participants":["Edgar Toernig"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"1656","messageId":"20050425233244.5f79d59c.froese@gmx.de","threadId":"315","inReplyTo":null,"subject":"[PATCH] Fix rfc2822 date parser","fromName":"Edgar Toernig","fromEmail":"froese@gmx.de","sentAt":"2005-04-25T21:32:44Z","receivedAt":"2005-04-25T21:32:44Z","isPatch":true,"sender":{"key":"froese@gmx.de","avatar":null},"body":"- Fix some broken tests like \"if (!tm.tm_sec > 59)\"\n- Make seconds optional\n- Allow trailing comments like (EDT)\n- Stand-alone mktime without timezone correction\n\nCiao, ET.\n\n\ndiff -u git-0.6-orig/commit-tree.c git-0.6/commit-tree.c\n--- git-0.6-orig/commit-tree.c\tThu Apr 21 19:58:47 2005\n+++ git-0.6/commit-tree.c\tMon Apr 25 23:06:36 2005\n@@ -113,6 +113,25 @@\n \t}\n }\n \n+static time_t my_mktime(struct tm *tm)\n+{\n+\tstatic const int mdays[] = {\n+\t    0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334\n+\t};\n+\tint year = tm->tm_year - 70;\n+\tint month = tm->tm_mon;\n+\tint day = tm->tm_mday;\n+\n+\tif (year < 0 || year > 129) /* algo only works for 1970-2099 */\n+\t\treturn -1;\n+\tif (month < 0 || month > 11) /* array bounds */\n+\t\treturn -1;\n+\tif (month < 2 || (year + 2) % 4)\n+\t\tday--;\n+\treturn (year * 365 + (year + 1) / 4 + mdays[month] + day) * 24*60*60UL +\n+\t\ttm->tm_hour * 60*60 + tm->tm_min * 60 + tm->tm_sec;\n+}\n+\n static const char *month_names[] = {\n         \"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\",\n         \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"\n@@ -194,7 +213,7 @@\n \t\treturn;\n \ttm.tm_hour = strtoul(p, &p, 10);\n \t\n-\tif (!tm.tm_hour > 23)\n+\tif (tm.tm_hour > 23)\n \t\treturn;\n \n \tif (*p != ':')\n@@ -206,14 +225,11 @@\n \t\treturn;\n \ttm.tm_min = strtoul(p, &p, 10);\n \t\n-\tif (!tm.tm_min > 59)\n+\tif (tm.tm_min > 59)\n \t\treturn;\n \n-\tif (isspace(*p))\n-\t\tgoto zone;\n-\n \tif (*p != ':')\n-\t\treturn; /* Error -- bad time */\n+\t\tgoto zone;\n \tp++;\n \n \t/* second */\n@@ -221,13 +237,13 @@\n \t\treturn;\n \ttm.tm_sec = strtoul(p, &p, 10);\n \t\n-\tif (!tm.tm_sec > 59)\n+\tif (tm.tm_sec > 59)\n \t\treturn;\n \n+ zone:\n \tif (!isspace(*p))\n \t\treturn;\n \n- zone:\n \tp = skipfws(p);\n \n \tif (*p == '-')\n@@ -243,10 +259,11 @@\n \ti = strtoul(p+1, NULL, 10);\n \toffset *= ((i % 100) + ((i / 100) * 60));\n \n-\tif (*(skipfws(p + 5)))\n+\tp = skipfws(p + 5);\n+\tif (*p && *p != '(') /* trailing comment like (EDT) is ok */\n \t\treturn;\n \n-\tthen = mktime(&tm); /* mktime appears to ignore the GMT offset, stupidly */\n+\tthen = my_mktime(&tm); /* mktime appears to ignore the GMT offset, stupidly */\n \tif (then == -1)\n \t\treturn;\n \n"}]}