Skip to content

Commit d199cd5

Browse files
committed
fix: Make date measure parsing optional
Fixes #602
1 parent cf44753 commit d199cd5

File tree

6 files changed

+46
-22
lines changed

6 files changed

+46
-22
lines changed

packages/cubejs-client-core/dist/cubejs-client-core.esm.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,20 @@ var TIME_SERIES = {
7676
}
7777
};
7878
var DateRegex = /^\d\d\d\d-\d\d-\d\d$/;
79-
var ISO8601_REGEX = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
79+
var LocalDateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z?$/;
8080
/**
8181
* Provides a convenient interface for data manipulation.
8282
*/
8383

8484
var ResultSet =
8585
/*#__PURE__*/
8686
function () {
87-
function ResultSet(loadResponse) {
87+
function ResultSet(loadResponse, options) {
8888
_classCallCheck(this, ResultSet);
8989

90+
options = options || {};
9091
this.loadResponse = loadResponse;
92+
this.parseDateMeasures = options.parseDateMeasures;
9193
}
9294
/**
9395
* Returns an array of series with key, title and series data.
@@ -424,7 +426,7 @@ function () {
424426
var _this3 = this;
425427

426428
var validate = function validate(value) {
427-
if (ISO8601_REGEX.test(value)) {
429+
if (_this3.parseDateMeasures && LocalDateRegex.test(value)) {
428430
return new Date(value);
429431
} else if (!Number.isNaN(Number.parseFloat(value))) {
430432
return Number.parseFloat(value);
@@ -994,6 +996,7 @@ function () {
994996
headers: this.headers
995997
});
996998
this.pollInterval = options.pollInterval || 5;
999+
this.parseDateMeasures = options.parseDateMeasures;
9971000
}
9981001

9991002
_createClass(CubejsApi, [{
@@ -1433,7 +1436,9 @@ function () {
14331436
query: query
14341437
});
14351438
}, function (body) {
1436-
return new ResultSet(body);
1439+
return new ResultSet(body, {
1440+
parseDateMeasures: _this2.parseDateMeasures
1441+
});
14371442
}, options, callback);
14381443
}
14391444
/**
@@ -1485,7 +1490,9 @@ function () {
14851490
query: query
14861491
});
14871492
}, function (body) {
1488-
return new ResultSet(body);
1493+
return new ResultSet(body, {
1494+
parseDateMeasures: _this5.parseDateMeasures
1495+
});
14891496
}, _objectSpread2({}, options, {
14901497
subscribe: true
14911498
}), callback);

packages/cubejs-client-core/dist/cubejs-client-core.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,20 @@ var TIME_SERIES = {
8282
}
8383
};
8484
var DateRegex = /^\d\d\d\d-\d\d-\d\d$/;
85-
var ISO8601_REGEX = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
85+
var LocalDateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z?$/;
8686
/**
8787
* Provides a convenient interface for data manipulation.
8888
*/
8989

9090
var ResultSet =
9191
/*#__PURE__*/
9292
function () {
93-
function ResultSet(loadResponse) {
93+
function ResultSet(loadResponse, options) {
9494
_classCallCheck(this, ResultSet);
9595

96+
options = options || {};
9697
this.loadResponse = loadResponse;
98+
this.parseDateMeasures = options.parseDateMeasures;
9799
}
98100
/**
99101
* Returns an array of series with key, title and series data.
@@ -430,7 +432,7 @@ function () {
430432
var _this3 = this;
431433

432434
var validate = function validate(value) {
433-
if (ISO8601_REGEX.test(value)) {
435+
if (_this3.parseDateMeasures && LocalDateRegex.test(value)) {
434436
return new Date(value);
435437
} else if (!Number.isNaN(Number.parseFloat(value))) {
436438
return Number.parseFloat(value);
@@ -1000,6 +1002,7 @@ function () {
10001002
headers: this.headers
10011003
});
10021004
this.pollInterval = options.pollInterval || 5;
1005+
this.parseDateMeasures = options.parseDateMeasures;
10031006
}
10041007

10051008
_createClass(CubejsApi, [{
@@ -1439,7 +1442,9 @@ function () {
14391442
query: query
14401443
});
14411444
}, function (body) {
1442-
return new ResultSet(body);
1445+
return new ResultSet(body, {
1446+
parseDateMeasures: _this2.parseDateMeasures
1447+
});
14431448
}, options, callback);
14441449
}
14451450
/**
@@ -1491,7 +1496,9 @@ function () {
14911496
query: query
14921497
});
14931498
}, function (body) {
1494-
return new ResultSet(body);
1499+
return new ResultSet(body, {
1500+
parseDateMeasures: _this5.parseDateMeasures
1501+
});
14951502
}, _objectSpread2({}, options, {
14961503
subscribe: true
14971504
}), callback);

packages/cubejs-client-core/dist/cubejs-client-core.umd.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13599,18 +13599,20 @@
1359913599
}
1360013600
};
1360113601
var DateRegex = /^\d\d\d\d-\d\d-\d\d$/;
13602-
var ISO8601_REGEX = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
13602+
var LocalDateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z?$/;
1360313603
/**
1360413604
* Provides a convenient interface for data manipulation.
1360513605
*/
1360613606

1360713607
var ResultSet =
1360813608
/*#__PURE__*/
1360913609
function () {
13610-
function ResultSet(loadResponse) {
13610+
function ResultSet(loadResponse, options) {
1361113611
_classCallCheck(this, ResultSet);
1361213612

13613+
options = options || {};
1361313614
this.loadResponse = loadResponse;
13615+
this.parseDateMeasures = options.parseDateMeasures;
1361413616
}
1361513617
/**
1361613618
* Returns an array of series with key, title and series data.
@@ -13947,7 +13949,7 @@
1394713949
var _this3 = this;
1394813950

1394913951
var validate = function validate(value) {
13950-
if (ISO8601_REGEX.test(value)) {
13952+
if (_this3.parseDateMeasures && LocalDateRegex.test(value)) {
1395113953
return new Date(value);
1395213954
} else if (!Number.isNaN(Number.parseFloat(value))) {
1395313955
return Number.parseFloat(value);
@@ -15448,6 +15450,7 @@
1544815450
headers: this.headers
1544915451
});
1545015452
this.pollInterval = options.pollInterval || 5;
15453+
this.parseDateMeasures = options.parseDateMeasures;
1545115454
}
1545215455

1545315456
_createClass(CubejsApi, [{
@@ -15887,7 +15890,9 @@
1588715890
query: query
1588815891
});
1588915892
}, function (body) {
15890-
return new ResultSet(body);
15893+
return new ResultSet(body, {
15894+
parseDateMeasures: _this2.parseDateMeasures
15895+
});
1589115896
}, options, callback);
1589215897
}
1589315898
/**
@@ -15939,7 +15944,9 @@
1593915944
query: query
1594015945
});
1594115946
}, function (body) {
15942-
return new ResultSet(body);
15947+
return new ResultSet(body, {
15948+
parseDateMeasures: _this5.parseDateMeasures
15949+
});
1594315950
}, _objectSpread({}, options, {
1594415951
subscribe: true
1594515952
}), callback);

packages/cubejs-client-core/src/ResultSet.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ const TIME_SERIES = {
2828
};
2929

3030
const DateRegex = /^\d\d\d\d-\d\d-\d\d$/;
31-
const ISO8601_REGEX = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
31+
const LocalDateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z?$/;
3232

3333
/**
3434
* Provides a convenient interface for data manipulation.
3535
*/
3636
class ResultSet {
37-
constructor(loadResponse) {
37+
constructor(loadResponse, options) {
38+
options = options || {};
3839
this.loadResponse = loadResponse;
40+
this.parseDateMeasures = options.parseDateMeasures;
3941
}
4042

4143
/**
@@ -289,7 +291,7 @@ class ResultSet {
289291
*/
290292
chartPivot(pivotConfig) {
291293
const validate = (value) => {
292-
if (ISO8601_REGEX.test(value)) {
294+
if (this.parseDateMeasures && LocalDateRegex.test(value)) {
293295
return new Date(value);
294296
} else if (!Number.isNaN(Number.parseFloat(value))) {
295297
return Number.parseFloat(value);

packages/cubejs-client-core/src/ResultSet.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ describe('ResultSet', () => {
228228
},
229229
data: [{
230230
'Foo.name': 'Name 1',
231-
'Foo.count': 10,
231+
'Foo.count': '10',
232232
}],
233233
lastRefreshTime: '2020-03-18T13:41:04.436Z',
234234
usedPreAggregations: {},
@@ -292,7 +292,7 @@ describe('ResultSet', () => {
292292
segments: {},
293293
timeDimensions: {},
294294
},
295-
});
295+
}, { parseDateMeasures: true });
296296

297297
expect(resultSet.chartPivot()).toEqual([{
298298
x: 'Name 1',

packages/cubejs-client-core/src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class CubejsApi {
4343
headers: this.headers
4444
});
4545
this.pollInterval = options.pollInterval || 5;
46+
this.parseDateMeasures = options.parseDateMeasures;
4647
}
4748

4849
request(method, params) {
@@ -204,7 +205,7 @@ class CubejsApi {
204205
load(query, options, callback) {
205206
return this.loadMethod(
206207
() => this.request(`load`, { query }),
207-
(body) => new ResultSet(body),
208+
(body) => new ResultSet(body, { parseDateMeasures: this.parseDateMeasures }),
208209
options,
209210
callback
210211
);
@@ -244,7 +245,7 @@ class CubejsApi {
244245
subscribe(query, options, callback) {
245246
return this.loadMethod(
246247
() => this.request(`subscribe`, { query }),
247-
(body) => new ResultSet(body),
248+
(body) => new ResultSet(body, { parseDateMeasures: this.parseDateMeasures }),
248249
{ ...options, subscribe: true },
249250
callback
250251
);

0 commit comments

Comments
 (0)