Skip to content

Commit 1f7a2ab

Browse files
committed
Merge branch 'hl/iso8601-more-zone-formats' into maint-1.7.6
* hl/iso8601-more-zone-formats: date.c: Support iso8601 timezone formats
2 parents 588150b + ee646eb commit 1f7a2ab

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

date.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -552,23 +552,35 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
552552
static int match_tz(const char *date, int *offp)
553553
{
554554
char *end;
555-
int offset = strtoul(date+1, &end, 10);
556-
int min, hour;
557-
int n = end - date - 1;
555+
int hour = strtoul(date + 1, &end, 10);
556+
int n = end - (date + 1);
557+
int min = 0;
558558

559-
min = offset % 100;
560-
hour = offset / 100;
559+
if (n == 4) {
560+
/* hhmm */
561+
min = hour % 100;
562+
hour = hour / 100;
563+
} else if (n != 2) {
564+
min = 99; /* random crap */
565+
} else if (*end == ':') {
566+
/* hh:mm? */
567+
min = strtoul(end + 1, &end, 10);
568+
if (end - (date + 1) != 5)
569+
min = 99; /* random crap */
570+
} /* otherwise we parsed "hh" */
561571

562572
/*
563-
* Don't accept any random crap.. At least 3 digits, and
564-
* a valid minute. We might want to check that the minutes
565-
* are divisible by 30 or something too.
573+
* Don't accept any random crap. Even though some places have
574+
* offset larger than 12 hours (e.g. Pacific/Kiritimati is at
575+
* UTC+14), there is something wrong if hour part is much
576+
* larger than that. We might also want to check that the
577+
* minutes are divisible by 15 or something too. (Offset of
578+
* Kathmandu, Nepal is UTC+5:45)
566579
*/
567-
if (min < 60 && n > 2) {
568-
offset = hour*60+min;
580+
if (min < 60 && hour < 24) {
581+
int offset = hour * 60 + min;
569582
if (*date == '-')
570583
offset = -offset;
571-
572584
*offp = offset;
573585
}
574586
return end - date;

t/t0006-date.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ check_parse 2008-02 bad
4040
check_parse 2008-02-14 bad
4141
check_parse '2008-02-14 20:30:45' '2008-02-14 20:30:45 +0000'
4242
check_parse '2008-02-14 20:30:45 -0500' '2008-02-14 20:30:45 -0500'
43+
check_parse '2008-02-14 20:30:45 -0015' '2008-02-14 20:30:45 -0015'
44+
check_parse '2008-02-14 20:30:45 -5' '2008-02-14 20:30:45 +0000'
45+
check_parse '2008-02-14 20:30:45 -5:' '2008-02-14 20:30:45 +0000'
46+
check_parse '2008-02-14 20:30:45 -05' '2008-02-14 20:30:45 -0500'
47+
check_parse '2008-02-14 20:30:45 -:30' '2008-02-14 20:30:45 +0000'
48+
check_parse '2008-02-14 20:30:45 -05:00' '2008-02-14 20:30:45 -0500'
4349
check_parse '2008-02-14 20:30:45' '2008-02-14 20:30:45 -0500' EST5
4450

4551
check_approxidate() {

0 commit comments

Comments
 (0)