Re: [PATCH] apply: Recognize epoch timestamps with : in the timezone

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] apply: Recognize epoch timestamps with : in the timezone

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:49:46

Junio C Hamano [off-list ref] writes:
Neither the patch nor your suggestion makes much sense to me.  With the
patch, the regexp is now

    ^(1969-12-31|1970-01-01) <time>(\.0+)? ([-+][0-2][0-9]):?([0-5][0-9])

so $3 is always 3 letters long (i.e. hour with sign), no?  IOW, zoneoffset
is never divided by 100 by the original patch.

What am I missing?
Well, I was missing that without ':' strtol() goes through to parse $3$4
as a single integer, and the division was done to discard the minute part
and parse it again.

Calling strtol() twice only because some unusual input may have ':' there
feels ugly, but now I understand why the patch is written that way, at
least.

Re: [PATCH] apply: Recognize epoch timestamps with : in the timezone

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:47

Junio C Hamano wrote:
Junio C Hamano [off-list ref] writes:
quoted
Neither the patch nor your suggestion makes much sense to me.  With the
patch, the regexp is now

    ^(1969-12-31|1970-01-01) <time>(\.0+)? ([-+][0-2][0-9]):?([0-5][0-9])
[...]
Well, I was missing that without ':' strtol() goes through to parse $3$4
as a single integer
So maybe something like the following would make this easier to follow.
diff --git a/builtin/apply.c b/builtin/apply.c
index 0fa9a8d..000d3e5 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -733,8 +733,8 @@ static int has_epoch_timestamp(const char *nameline)
 		" "
 		"[0-2][0-9]:[0-5][0-9]:00(\\.0+)?"
 		" "
-		"([-+][0-2][0-9]):?([0-5][0-9])\n";
+		"([-+][0-2][0-9]:?[0-5][0-9])\n";
-	const char *timestamp = NULL, *cp;
+	const char *timestamp = NULL, *cp, *colon;
 	static regex_t *stamp;
 	regmatch_t m[10];
 	int zoneoffset;
@@ -764,10 +764,11 @@ static int has_epoch_timestamp(const char *nameline)
 		return 0;
 	}
 
-	zoneoffset = strtol(timestamp + m[3].rm_so + 1, NULL, 10);
+	zoneoffset = strtol(timestamp + m[3].rm_so + 1, (char **) &colon, 10);
-	if (m[4].rm_so == m[3].rm_so + 3)
-		zoneoffset /= 100;
-	zoneoffset = zoneoffset * 60 + strtol(timestamp + m[4].rm_so, NULL, 10);
+	if (*colon == ':')
+		zoneoffset = zoneoffset * 60 + strtol(colon + 1, NULL, 10);
+	else
+		zoneoffset = (zoneoffset / 100) * 60 + (zoneoffset % 100);
 	if (timestamp[m[3].rm_so] == '-')
 		zoneoffset = -zoneoffset;
 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help