* [PATCHv2] Accept the timezone specifiers [+-]hh:mm and [+-]hh in addition to [+-]hhmm
@ 2010-05-19 20:49 Marcus Comstedt
2010-05-19 20:49 ` [PATCH] " Marcus Comstedt
0 siblings, 1 reply; 2+ messages in thread
From: Marcus Comstedt @ 2010-05-19 20:49 UTC (permalink / raw)
To: git
Ok, here's a new attempt for the +hh(:mm) timezones, which should be
semantically equivalent to the previous one. In particular, I tested
the following corner cases:
check_parse '+31/05/06 1980 01:02:03' '1980-05-06 01:02:03 +0000'
check_parse '+1979/05/06/03 01:02:03' '2003-05-06 01:02:03 +0000'
check_parse '+11:5:6 1999/04/01' '1999-03-31 18:06:00 +0000'
check_parse '+11:73 Jun 15 10:00:00' bad
I'm not arguing that these results are "correct" or anything, I just
observe that it was like that before, and so by conservatively not
changing them, I shouldn't break anything...
(Ok, the last one _is_ a change from how it was in the before time,
in the long long ago, but it's the same as it was with the last
version of the patch.)
// Marcus
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] Accept the timezone specifiers [+-]hh:mm and [+-]hh in addition to [+-]hhmm
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
0 siblings, 0 replies; 2+ messages in thread
From: Marcus Comstedt @ 2010-05-19 20:49 UTC (permalink / raw)
To: git; +Cc: Marcus Comstedt
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-05-19 20:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH] " Marcus Comstedt
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).