Skip to content

Commit a8513a2

Browse files
CDRIVER-5572 Allow ':' in timezone (#1599)
1 parent 84728bd commit a8513a2

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/libbson/src/bson/bson-iso8601.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ _bson_iso8601_date_parse (const char *str, int32_t len, int64_t *out, bson_error
133133

134134
#define DEFAULT_DATE_PARSE_ERR \
135135
DATE_PARSE_ERR ("use ISO8601 format yyyy-mm-ddThh:mm plus timezone, either" \
136-
" \"Z\" or like \"+0500\"")
136+
" \"Z\" or like \"+0500\" or like \"+05:00\"")
137137

138138
ptr = str;
139139

@@ -214,15 +214,17 @@ _bson_iso8601_date_parse (const char *str, int32_t len, int64_t *out, bson_error
214214
int32_t tz_hour;
215215
int32_t tz_min;
216216

217-
if (tz_len != 5 || !digits_only (tz_ptr + 1, 4)) {
217+
if ((tz_len != 5 || !digits_only (tz_ptr + 1, 4)) &&
218+
(tz_len != 6 || !digits_only (tz_ptr + 1, 2) || tz_ptr[3] != ':' || !digits_only (tz_ptr + 4, 2))) {
218219
DATE_PARSE_ERR ("could not parse timezone");
219220
}
220221

221222
if (!parse_num (tz_ptr + 1, 2, -1, -23, 23, &tz_hour)) {
222223
DATE_PARSE_ERR ("timezone hour must be at most 23");
223224
}
224225

225-
if (!parse_num (tz_ptr + 3, 2, -1, 0, 59, &tz_min)) {
226+
int32_t tz_min_offset = tz_ptr[3] == ':' ? 1 : 0;
227+
if (!parse_num (tz_ptr + 3 + tz_min_offset, 2, -1, 0, 59, &tz_min)) {
226228
DATE_PARSE_ERR ("timezone minute must be at most 59");
227229
}
228230

src/libbson/tests/test-iso8601.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ test_bson_iso8601_utc (void)
8585
test_date_io ("1970-01-01T00:00:00.000Z", "1970-01-01T00:00:00Z", 0ULL);
8686
test_date_rt ("1970-06-30T01:06:40.981Z", 15556000981ULL);
8787
test_date ("1970-01-01T00:00:00.000+0100", -3600LL * 1000);
88+
test_date ("1970-01-01T00:00:00.000+01:00", -3600LL * 1000);
8889

8990
if (!is_time_t_small) {
9091
test_date_rt ("2058-02-20T18:29:11.100Z", 2781455351100ULL);
@@ -115,6 +116,7 @@ test_bson_iso8601_local (void)
115116
test_date_io ("1971-02-03T09:16:06.7+0511", "1971-02-03T04:05:06.700Z", 34401906700ULL);
116117
test_date_io ("1971-02-03T09:16:06+0511", "1971-02-03T04:05:06Z", 34401906000ULL);
117118
test_date_io ("1971-02-03T09:16+0511", "1971-02-03T04:05:00Z", 34401900000ULL);
119+
test_date_io ("1971-02-03T09:16+05:11", "1971-02-03T04:05:00Z", 34401900000ULL);
118120
test_date_io ("1970-01-01T00:00:00.000Z", "1970-01-01T00:00:00Z", 0ULL);
119121
test_date_rt ("1970-06-30T01:06:40.981Z", 15556000981ULL);
120122
test_date_io ("1970-06-29T21:06:40.981-0400", "1970-06-30T01:06:40.981Z", 15556000981ULL);

src/libbson/tests/test-json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2319,7 +2319,7 @@ test_bson_json_date (void)
23192319
test_bson_json_date_check ("{ \"dt\" : { \"$date\" : \"1970-01-01T00:00:00.000Z\" } }", 0);
23202320
test_bson_json_date_check ("{ \"dt\" : { \"$date\" : \"1969-12-31T16:00:00.000-0800\" } }", 0);
23212321

2322-
test_bson_json_date_error ("{ \"dt\" : { \"$date\" : \"1970-01-01T01:00:00.000+01:00\" } }", "Could not parse");
2322+
test_bson_json_date_check ("{ \"dt\" : { \"$date\" : \"1970-01-01T01:00:00.000+01:00\" } }", 0);
23232323
test_bson_json_date_error ("{ \"dt\" : { \"$date\" : \"1970-01-01T01:30:\" } }",
23242324
"reached end of date while looking for seconds");
23252325
test_bson_json_date_error ("{ \"dt\" : { \"$date\" : \"1970-01-01T01:00:+01:00\" } }", "seconds is required");

0 commit comments

Comments
 (0)