All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Haitao Li <lihaitao@gmail.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>
Subject: Re: [PATCH v3] date.c: Support iso8601 timezone formats
Date: Fri, 09 Sep 2011 10:04:05 -0700	[thread overview]
Message-ID: <7vd3f9ve9m.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <7vhb4lvflb.fsf@alter.siamese.dyndns.org> (Junio C. Hamano's message of "Fri, 09 Sep 2011 09:35:28 -0700")

Junio C Hamano <gitster@pobox.com> writes:

> Haitao Li <lihaitao@gmail.com> writes:
>
>> Timezone designators including additional separator (`:`) are ignored.
>> Actually zone designators in below formats are all valid according to
>> ISO8601:2004, section 4.3.2:
>>     [+-]hh, [+-]hhmm, [+-]hh:mm
>
> Thanks for a re-roll.
>
>> This patch teaches git recognizing zone designators with hours and
>> minutes separated by colon, or minutes are empty.
>
> The last sentence above makes it sound as if you are accepting
>
> 	"2011-09-17 12:34:56 +09:"
>
> but I suspect that is not what you intend to allow.  Perhaps "we allowed
> hh and hhmm and this teaches Git to recognize hh:mm format as well"?

Also, I do not quite understand why the match_tz() logic needs to be that
long.

Wouldn't something like this patch (on top of yours) easier to follow?

 date.c |   50 +++++++++++++++++++++-----------------------------
 1 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/date.c b/date.c
index f8722c1..6079b1a 100644
--- a/date.c
+++ b/date.c
@@ -551,44 +551,36 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
 
 static int match_tz(const char *date, int *offp)
 {
+	int min;
 	char *end;
-	int offset = strtoul(date+1, &end, 10);
-	int min, hour;
-	int n = end - date - 1;
+	int hour = strtoul(date + 1, &end, 10);
+	int n = end - (date + 1);
 
-	/*
-	 * ISO8601:2004(E) allows time zone designator been separated
-	 * by a clone in the extended format
-	 */
-	if (*end == ':') {
-		if (isdigit(end[1])) {
-			hour = offset;
-			min = strtoul(end+1, &end, 10);
-		} else {
-			/* Mark as invalid */
-			n = -1;
-		}
-	} else {
-		if (n == 1 || n == 2) {
-			/* Only hours specified */
-			hour = offset;
-			min = 0;
-		} else {
-			hour = offset / 100;
-			min = offset % 100;
-		}
+	if (n == 4) {
+		/* hhmm */
+		min = hour % 100;
+		hour = hour / 100;
+	} else if (n != 2) {
+		min = 99; /* random crap */
+	} else if (*end == ':') {
+		/* hh:mm? */
+		min = strtoul(end + 1, &end, 10);
+		if (end - (date + 1) != 5)
+			min = 99; /* random crap */
 	}
 
 	/*
-	 * Don't accept any random crap.. We might want to check that
-	 * the minutes are divisible by 15 or something too. (Offset of
+	 * Don't accept any random crap. Even though some places have
+	 * offset larger than 12 hours (e.g. Pacific/Kiritimati is at
+	 * UTC+14), there is something wrong if hour part is much
+	 * larger than that. We might also want to check that the
+	 * minutes are divisible by 15 or something too. (Offset of
 	 * Kathmandu, Nepal is UTC+5:45)
 	 */
-	if (n > 0 && min < 60) {
-		offset = hour*60+min;
+	if (min < 60 && hour < 24) {
+		int offset = hour * 60 + min;
 		if (*date == '-')
 			offset = -offset;
-
 		*offp = offset;
 	}
 	return end - date;

  reply	other threads:[~2011-09-09 17:04 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-06 14:56 [PATCH] date.c: Parse timezone with colon as separator Haitao Li
2011-09-06 20:24 ` Jeff King
2011-09-07  3:00   ` Haitao Li
2011-09-07  5:46 ` [PATCH v2] date.c: Support iso8601 timezone formats Haitao Li
2011-09-07 17:00   ` Junio C Hamano
2011-09-08  2:53     ` Haitao Li
2011-09-09 10:10 ` [PATCH v3] " Haitao Li
2011-09-09 16:35   ` Junio C Hamano
2011-09-09 17:04     ` Junio C Hamano [this message]
2011-09-09 20:46       ` Junio C Hamano
2011-09-10  8:29       ` Haitao Li
2011-09-10  8:06     ` Haitao Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vd3f9ve9m.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=lihaitao@gmail.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.