Skip to content

Commit 556b5d4

Browse files
authored
Merge pull request #5015 from mtgto/iso8601_short_tz
Accept ISO-8601 short time offset format
2 parents 2ddfa84 + 8700a51 commit 556b5d4

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/lib/dates.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ var Registry = require('../registry');
2727

2828
var utcFormat = d3.time.format.utc;
2929

30-
var DATETIME_REGEXP = /^\s*(-?\d\d\d\d|\d\d)(-(\d?\d)(-(\d?\d)([ Tt]([01]?\d|2[0-3])(:([0-5]\d)(:([0-5]\d(\.\d+)?))?(Z|z|[+\-]\d\d:?\d\d)?)?)?)?)?\s*$/m;
30+
var DATETIME_REGEXP = /^\s*(-?\d\d\d\d|\d\d)(-(\d?\d)(-(\d?\d)([ Tt]([01]?\d|2[0-3])(:([0-5]\d)(:([0-5]\d(\.\d+)?))?(Z|z|[+\-]\d\d(:?\d\d)?)?)?)?)?)?\s*$/m;
3131
// special regex for chinese calendars to support yyyy-mmi-dd etc for intercalary months
32-
var DATETIME_REGEXP_CN = /^\s*(-?\d\d\d\d|\d\d)(-(\d?\di?)(-(\d?\d)([ Tt]([01]?\d|2[0-3])(:([0-5]\d)(:([0-5]\d(\.\d+)?))?(Z|z|[+\-]\d\d:?\d\d)?)?)?)?)?\s*$/m;
32+
var DATETIME_REGEXP_CN = /^\s*(-?\d\d\d\d|\d\d)(-(\d?\di?)(-(\d?\d)([ Tt]([01]?\d|2[0-3])(:([0-5]\d)(:([0-5]\d(\.\d+)?))?(Z|z|[+\-]\d\d(:?\d\d)?)?)?)?)?)?\s*$/m;
3333

3434
// for 2-digit years, the first year we map them onto
3535
var YFIRST = new Date().getFullYear() - 70;
@@ -90,8 +90,9 @@ var MIN_MS, MAX_MS;
9090
* -?YYYY-mm-dd<sep>HH:MM:SS.sss<tzInfo>?
9191
*
9292
* <sep>: space (our normal standard) or T or t (ISO-8601)
93-
* <tzInfo>: Z, z, or [+\-]HH:?MM and we THROW IT AWAY
93+
* <tzInfo>: Z, z, [+\-]HH:?MM or [+\-]HH and we THROW IT AWAY
9494
* this format comes from https://tools.ietf.org/html/rfc3339#section-5.6
95+
* and 4.2.5.1 Difference between local time and UTC of day (ISO-8601)
9596
* but we allow it even with a space as the separator
9697
*
9798
* May truncate after any full field, and sss can be any length

test/jasmine/tests/lib_date_test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ describe('dates', function() {
8282
['2014-03-04 08:15:00.00z', new Date(2014, 2, 4, 8, 15)],
8383
['2014-03-04 08:15:34+1200', new Date(2014, 2, 4, 8, 15, 34)],
8484
['2014-03-04 08:15:34.567-05:45', new Date(2014, 2, 4, 8, 15, 34, 567)],
85+
86+
// iso8601 short time offset
87+
['2014-03-04T08:15:34-05', new Date(2014, 2, 4, 8, 15, 34)],
8588
].forEach(function(v) {
8689
// just for sub-millisecond precision tests, use timezoneoffset
8790
// from the previous date object
@@ -157,7 +160,7 @@ describe('dates', function() {
157160
'2015-01-01 12:60', '2015-01-01 12:-1', '2015-01-01 12:001', '2015-01-01 12:1', // bad minute
158161
'2015-01-01 12:00:60', '2015-01-01 12:00:-1', '2015-01-01 12:00:001', '2015-01-01 12:00:1', // bad second
159162
'2015-01-01T', '2015-01-01TT12:34', // bad ISO separators
160-
'2015-01-01Z', '2015-01-01T12Z', '2015-01-01T12:34Z05:00', '2015-01-01 12:34+500', '2015-01-01 12:34-5:00' // bad TZ info
163+
'2015-01-01Z', '2015-01-01T12Z', '2015-01-01T12:34Z05:00', '2015-01-01 12:34+500', '2015-01-01 12:34-5:00', '2015-01-01 12:34+5' // bad TZ info
161164
].forEach(function(v) {
162165
expect(Lib.dateTime2ms(v)).toBeUndefined(v);
163166
});

0 commit comments

Comments
 (0)