From: Junio C Hamano <gitster@pobox.com>
To: Marcus Comstedt <marcus@mc.pp.se>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/2] Accept the timezone specifiers [+-]hh:mm and [+-]hh in addition to [+-]hhmm
Date: Wed, 19 May 2010 07:31:25 -0700 [thread overview]
Message-ID: <7v632karpe.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: 1274123231-18482-3-git-send-email-marcus@mc.pp.se
Marcus Comstedt <marcus@mc.pp.se> writes:
> ISO 8601 specifies three syntaxes for timezones other than "Z".
> git already supports the +-hhmm syntax. This patch adds support
> for the other two: +-hh:mm and +-hh.
>
> Signed-off-by: Marcus Comstedt <marcus@mc.pp.se>
> ---
> :100644 100644 6bae49c... f83e46e... M date.c
> date.c | 23 +++++++++++++++++++++++
> 1 files changed, 23 insertions(+), 0 deletions(-)
>
> diff --git a/date.c b/date.c
> index 6bae49c..f83e46e 100644
> --- a/date.c
> +++ b/date.c
> @@ -555,6 +555,18 @@ static int match_tz(const char *date, int *offp)
> int min, hour;
> int n = end - date - 1;
>
> + /* Check for HH:MM format, allowed by ISO 8601 */
> + if (n == 2 && date[3] == ':') {
> + char *end2;
> + min = strtoul(date+4, &end2, 10);
> + /* If we have two digits after the colon too, assume HH:MM */
> + if (end2 == date+6) {
> + offset = offset*100 + min;
> + end = end2;
> + n = end - date - 1;
> + }
> + }
> +
> min = offset % 100;
> hour = offset / 100;
>
> @@ -570,6 +582,17 @@ static int match_tz(const char *date, int *offp)
>
> *offp = offset;
> }
> + /*
> + * Also accept just the hour, allowed by ISO 8601
> + */
> + else if (n == 2 && hour == 0 && min < 24) {
> + offset = min*60;
> + if (*date == '-')
> + offset = -offset;
> +
> + *offp = offset;
> + }
> +
I don't recall seeing in ISO 8601 that +hh or -hh without minute
resolution was allowed, but I don't have my copy of ISO 8601 with me (they
are packed and are still in transit with my household goods) so I'll take
your word for it for now [*1*].
But the placement of this second hunk is somewhat curious. Why doesn't the
updated function look like this?
int offset = strtoul(date + 1, &end, 10);
int min, hour;
int n = end - date - 1;
if (n == 2 && offset <= 14) {
/* +HH:MM (ISO 8601) or +HH (ISO 8601 abbreviated) */
hour = offset;
if (n == 2 && date[3] == ':') {
min = strtoul(date + 4, &end, 10);
if (end != date + 6)
return 0; /* Bad CRAP */
} else {
min = 0;
}
} else if (n < 3) {
return 0; /* we want at least 3 digits */
} else {
min = offset % 100;
hour = offset / 100;
}
if (60 <= min)
return 0; /* invalid minute */
offset = hour * 60 + min;
if (*date == '-')
offset = -offset;
*offp = offset;
return end - date;
[Footnote]
*1* Appendix A of RFC3339 seems to agree with you.
next prev parent reply other threads:[~2010-05-19 14:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-17 19:07 PATCH: Improved support for ISO 8601 timezones Marcus Comstedt
2010-05-17 19:07 ` [PATCH 1/2] Added "Z" as an alias for the timezone "UTC" Marcus Comstedt
2010-05-17 20:32 ` Jay Soffian
2010-05-17 19:07 ` [PATCH 2/2] Accept the timezone specifiers [+-]hh:mm and [+-]hh in addition to [+-]hhmm Marcus Comstedt
2010-05-19 14:31 ` Junio C Hamano [this message]
2010-05-19 17:21 ` Marcus Comstedt
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7v632karpe.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=marcus@mc.pp.se \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).