From: Marcus Comstedt <marcus@mc.pp.se>
To: git@vger.kernel.org
Cc: Marcus Comstedt <marcus@mc.pp.se>
Subject: [PATCH] Accept the timezone specifiers [+-]hh:mm and [+-]hh in addition to [+-]hhmm
Date: Wed, 19 May 2010 22:49:37 +0200 [thread overview]
Message-ID: <1274302177-3573-2-git-send-email-marcus@mc.pp.se> (raw)
In-Reply-To: <1274302177-3573-1-git-send-email-marcus@mc.pp.se>
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>
---
date.c | 39 ++++++++++++++++++++++++++-------------
1 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/date.c b/date.c
index 6bae49c..f2cad1f 100644
--- a/date.c
+++ b/date.c
@@ -555,21 +555,34 @@ static int match_tz(const char *date, int *offp)
int min, hour;
int n = end - date - 1;
- min = offset % 100;
- hour = offset / 100;
+ if (n == 2 && offset <= 14) {
+ /* +HH:MM (ISO 8601) or +HH (ISO 8601 abbreviated) */
+ hour = offset;
+ if (date[3] == ':') {
+ min = strtoul(date + 4, &end, 10);
+ if (end != date + 6) {
+ /* there was no minute field, but we're
+ fine with just the hour */
+ end = (char *)date + 3;
+ min = 0;
+ }
+ } else {
+ min = 0;
+ }
+ } else if (n < 3) {
+ return end - date; /* we want at least 3 digits */
+ } else {
+ min = offset % 100;
+ hour = offset / 100;
+ }
- /*
- * Don't accept any random crap.. At least 3 digits, and
- * a valid minute. We might want to check that the minutes
- * are divisible by 30 or something too.
- */
- if (min < 60 && n > 2) {
- offset = hour*60+min;
- if (*date == '-')
- offset = -offset;
+ if (60 <= min)
+ return end - date; /* invalid minute */
- *offp = offset;
- }
+ offset = hour * 60 + min;
+ if (*date == '-')
+ offset = -offset;
+ *offp = offset;
return end - date;
}
--
1.7.0.4
prev parent reply other threads:[~2010-05-19 20:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-19 20:49 [PATCHv2] Accept the timezone specifiers [+-]hh:mm and [+-]hh in addition to [+-]hhmm Marcus Comstedt
2010-05-19 20:49 ` Marcus Comstedt [this message]
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=1274302177-3573-2-git-send-email-marcus@mc.pp.se \
--to=marcus@mc.pp.se \
--cc=git@vger.kernel.org \
/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 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 NNTP newsgroup(s).