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

Re: Trying to use AUTHOR_DATE

From
ETEdgar Toernig <froese@gmx.de>
Date
Apr 30, 2005, 04:50 UTC
Message-ID
<20050430065039.21ac9a4e.froese@gmx.de>
In-Reply-To
<B8E391BBE9FE384DAA4C5C003888BE6F035EDE2C@scsmsx401.amr.corp.intel.com>
Luck, Tony wrote:
>
> >What's wrong with the patch I sent to fix this:
>
> I missed it ... there is a problem that you drop the timezone.
Upps, sorry.
> I'd much rather see your version fixed up to preserve the timezone
> than have the libcurl dependency.
Fixed version below.

--- x/commit-tree.c Thu Apr 21 19:58:47 2005 +++ y/commit-tree.c Sat Apr 30 06:24:19 2005

@@ -113,6 +113,25 @@
 	}
 }
 
+static time_t my_mktime(struct tm *tm)
+{
+	static const int mdays[] = {
+	    0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
+	};
+	int year = tm->tm_year - 70;
+	int month = tm->tm_mon;
+	int day = tm->tm_mday;
+
+	if (year < 0 || year > 129) /* algo only works for 1970-2099 */
+		return -1;
+	if (month < 0 || month > 11) /* array bounds */
+		return -1;
+	if (month < 2 || (year + 2) % 4)
+		day--;
+	return (year * 365 + (year + 1) / 4 + mdays[month] + day) * 24*60*60UL +
+		tm->tm_hour * 60*60 + tm->tm_min * 60 + tm->tm_sec;
+}
+
 static const char *month_names[] = {
         "Jan", "Feb", "Mar", "Apr", "May", "Jun",
         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
@@ -136,7 +155,7 @@
 static void parse_rfc2822_date(char *date, char *result, int maxlen)
 {
 	struct tm tm;
-	char *p;
+	char *p, *tz;
 	int i, offset;
 	time_t then;
 
@@ -194,7 +213,7 @@
 		return;
 	tm.tm_hour = strtoul(p, &p, 10);
 	
-	if (!tm.tm_hour > 23)
+	if (tm.tm_hour > 23)
 		return;
 
 	if (*p != ':')
@@ -206,14 +225,11 @@
 		return;
 	tm.tm_min = strtoul(p, &p, 10);
 	
-	if (!tm.tm_min > 59)
+	if (tm.tm_min > 59)
 		return;
 
-	if (isspace(*p))
-		goto zone;
-
 	if (*p != ':')
-		return; /* Error -- bad time */
+		goto zone;
 	p++;
 
 	/* second */
@@ -221,13 +237,13 @@
 		return;
 	tm.tm_sec = strtoul(p, &p, 10);
 	
-	if (!tm.tm_sec > 59)
+	if (tm.tm_sec > 59)
 		return;
 
+ zone:
 	if (!isspace(*p))
 		return;
 
- zone:
 	p = skipfws(p);
 
 	if (*p == '-')
@@ -240,19 +256,21 @@
 	if (!isdigit(p[1]) || !isdigit(p[2]) || !isdigit(p[3]) || !isdigit(p[4]))
 		return;
 
+	tz = p;
 	i = strtoul(p+1, NULL, 10);
 	offset *= ((i % 100) + ((i / 100) * 60));
 
-	if (*(skipfws(p + 5)))
+	p = skipfws(p + 5);
+	if (*p && *p != '(') /* trailing comment like (EDT) is ok */
 		return;
 
-	then = mktime(&tm); /* mktime appears to ignore the GMT offset, stupidly */
+	then = my_mktime(&tm); /* mktime uses local timezone */
 	if (then == -1)
 		return;
 
 	then -= offset;
 
-	snprintf(result, maxlen, "%lu %5.5s", then, p);
+	snprintf(result, maxlen, "%lu %5.5s", then, tz);
 }
 
 static void check_valid(unsigned char *sha1, const char *expect)


Ciao, ET.
Previous: H. Peter Anvin
Message 31 of 31 in “RE: Trying to use AUTHOR_DATE”
  1. Luck, TonyApr 30, 2005
  2. H. Peter AnvinApr 30, 2005
  3. Linus TorvaldsApr 30, 2005
  4. Linus TorvaldsApr 30, 2005
  5. Russ AllberyApr 30, 2005
  6. David WoodhouseApr 30, 2005
  7. Edgar ToernigApr 30, 2005
  8. Russ AllberyApr 30, 2005
  9. Linus TorvaldsApr 30, 2005
  10. Juliusz ChroboczekApr 30, 2005
  11. Edgar ToernigApr 30, 2005
  12. Linus TorvaldsApr 30, 2005
  13. Linus TorvaldsMay 1, 2005
  14. Randy.DunlapMay 1, 2005
  15. Edgar ToernigMay 1, 2005
  16. Junio C HamanoApr 30, 2005
  17. Edgar ToernigApr 30, 2005
  18. David WoodhouseApr 30, 2005
  19. Kay SieversApr 30, 2005
  20. David WoodhouseApr 30, 2005
  21. Edgar ToernigApr 30, 2005
  22. David WoodhouseApr 30, 2005
  23. Edgar ToernigApr 30, 2005
  24. Krzysztof HalasaMay 2, 2005
  25. H. Peter AnvinMay 2, 2005
  26. Krzysztof HalasaMay 2, 2005
  27. H. Peter AnvinMay 2, 2005
  28. Krzysztof HalasaMay 3, 2005
  29. H. Peter AnvinMay 3, 2005
  30. H. Peter AnvinApr 30, 2005
  31. Edgar ToernigApr 30, 2005

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.