Skip to content
This repository was archived by the owner on Dec 11, 2022. It is now read-only.

Commit e08504a

Browse files
authored
Merge pull request #227 from doitintl/more-tests
Code Climate fixes
2 parents cf06f3f + 1299ed7 commit e08504a

File tree

4 files changed

+47
-46
lines changed

4 files changed

+47
-46
lines changed

dist/module.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58744,6 +58744,10 @@ function () {
5874458744
return q.replace(/(\$__timeShifting\().*?(?=\))./g, "");
5874558745
};
5874658746

58747+
BigQueryQuery.convertToUtc = function (d) {
58748+
return new Date(d.getTime() + d.getTimezoneOffset() * 60000);
58749+
};
58750+
5874758751
BigQueryQuery.prototype.getIntervalStr = function (interval, mininterval, options) {
5874858752
if (interval === "auto") {
5874958753
interval = this._calcAutoInterval(options);
@@ -59236,23 +59240,14 @@ function () {
5923659240
var toD = options.range.to;
5923759241

5923859242
if (this.target.convertToUTC === true) {
59239-
fromD = new Date(options.range.from._d.getTime() + options.range.from._d.getTimezoneOffset() * 60000);
59240-
toD = new Date(options.range.to._d.getTime() + options.range.to._d.getTimezoneOffset() * 60000);
59243+
fromD = BigQueryQuery.convertToUtc(options.range.from._d);
59244+
toD = BigQueryQuery.convertToUtc(options.range.to._d);
5924159245
}
5924259246

5924359247
var to = "";
5924459248
var from = "";
59245-
59246-
if (this.target.timeColumnType === "DATE") {
59247-
from = "'" + BigQueryQuery.formatDateToString(fromD, "-") + "'";
59248-
to = "'" + BigQueryQuery.formatDateToString(toD, "-") + "'";
59249-
} else if (this.target.timeColumnType === "DATETIME") {
59250-
from = "'" + BigQueryQuery.formatDateToString(fromD, "-", true) + "'";
59251-
to = "'" + BigQueryQuery.formatDateToString(toD, "-", true) + "'";
59252-
} else {
59253-
from = "TIMESTAMP_MILLIS (" + fromD.valueOf().toString() + ")";
59254-
to = "TIMESTAMP_MILLIS (" + toD.valueOf().toString() + ")";
59255-
}
59249+
from = this._getDateRangePart(fromD);
59250+
to = this._getDateRangePart(toD);
5925659251

5925759252
if (this.target.timeColumn === "-- time --") {
5925859253
var myRegexp = /\$__timeFilter\(([\w_.]+)\)/g;
@@ -59306,6 +59301,16 @@ function () {
5930659301
return Math.round(seconds / options.maxDataPoints) + "s";
5930759302
};
5930859303

59304+
BigQueryQuery.prototype._getDateRangePart = function (part) {
59305+
if (this.target.timeColumnType === "DATE") {
59306+
return "'" + BigQueryQuery.formatDateToString(part, "-") + "'";
59307+
} else if (this.target.timeColumnType === "DATETIME") {
59308+
return "'" + BigQueryQuery.formatDateToString(part, "-", true) + "'";
59309+
} else {
59310+
return "TIMESTAMP_MILLIS (" + part.valueOf().toString() + ")";
59311+
}
59312+
};
59313+
5930959314
return BigQueryQuery;
5931059315
}();
5931159316

@@ -61814,13 +61819,11 @@ function () {
6181461819
};
6181561820

6181661821
ResponseParser.manipulateItem = function (item) {
61817-
if (item.kind === "bigquery#table") {
61818-
if (item.timePartitioning) {
61819-
item.tableReference.tableId = item.tableReference.tableId + "__partitioned";
61822+
if (item.kind === "bigquery#table" && item.timePartitioning) {
61823+
item.tableReference.tableId = item.tableReference.tableId + "__partitioned";
6182061824

61821-
if (item.timePartitioning.field) {
61822-
item.tableReference.tableId += "__" + item.timePartitioning.field;
61823-
}
61825+
if (item.timePartitioning.field) {
61826+
item.tableReference.tableId += "__" + item.timePartitioning.field;
6182461827
}
6182561828
}
6182661829

dist/module.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bigquery_query.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ export default class BigQueryQuery {
9292
public static replaceTimeShift(q) {
9393
return q.replace(/(\$__timeShifting\().*?(?=\))./g, "");
9494
}
95+
private static convertToUtc(d) {
96+
return new Date(d.getTime() + d.getTimezoneOffset() * 60000);
97+
}
9598

9699
public target: any;
97100
public templateSrv: any;
@@ -630,27 +633,13 @@ export default class BigQueryQuery {
630633
let fromD = options.range.from;
631634
let toD = options.range.to;
632635
if (this.target.convertToUTC === true) {
633-
fromD = new Date(
634-
options.range.from._d.getTime() +
635-
options.range.from._d.getTimezoneOffset() * 60000
636-
);
637-
toD = new Date(
638-
options.range.to._d.getTime() +
639-
options.range.to._d.getTimezoneOffset() * 60000
640-
);
636+
fromD = BigQueryQuery.convertToUtc(options.range.from._d);
637+
toD = BigQueryQuery.convertToUtc(options.range.to._d);
641638
}
642639
let to = "";
643640
let from = "";
644-
if (this.target.timeColumnType === "DATE") {
645-
from = "'" + BigQueryQuery.formatDateToString(fromD, "-") + "'";
646-
to = "'" + BigQueryQuery.formatDateToString(toD, "-") + "'";
647-
} else if (this.target.timeColumnType === "DATETIME") {
648-
from = "'" + BigQueryQuery.formatDateToString(fromD, "-", true) + "'";
649-
to = "'" + BigQueryQuery.formatDateToString(toD, "-", true) + "'";
650-
} else {
651-
from = "TIMESTAMP_MILLIS (" + fromD.valueOf().toString() + ")";
652-
to = "TIMESTAMP_MILLIS (" + toD.valueOf().toString() + ")";
653-
}
641+
from = this._getDateRangePart(fromD);
642+
to = this._getDateRangePart(toD);
654643
if (this.target.timeColumn === "-- time --") {
655644
const myRegexp = /\$__timeFilter\(([\w_.]+)\)/g;
656645
const tf = myRegexp.exec(q);
@@ -713,4 +702,13 @@ export default class BigQueryQuery {
713702
1000;
714703
return Math.round(seconds / options.maxDataPoints) + "s";
715704
}
705+
private _getDateRangePart(part) {
706+
if (this.target.timeColumnType === "DATE") {
707+
return "'" + BigQueryQuery.formatDateToString(part, "-") + "'";
708+
} else if (this.target.timeColumnType === "DATETIME") {
709+
return "'" + BigQueryQuery.formatDateToString(part, "-", true) + "'";
710+
} else {
711+
return "TIMESTAMP_MILLIS (" + part.valueOf().toString() + ")";
712+
}
713+
}
716714
}

src/response_parser.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,11 @@ export default class ResponseParser {
108108
}
109109

110110
private static manipulateItem(item) {
111-
if (item.kind === "bigquery#table") {
112-
if (item.timePartitioning) {
113-
item.tableReference.tableId =
114-
item.tableReference.tableId + "__partitioned";
115-
if (item.timePartitioning.field) {
116-
item.tableReference.tableId += "__" + item.timePartitioning.field;
117-
}
111+
if (item.kind === "bigquery#table" && item.timePartitioning) {
112+
item.tableReference.tableId =
113+
item.tableReference.tableId + "__partitioned";
114+
if (item.timePartitioning.field) {
115+
item.tableReference.tableId += "__" + item.timePartitioning.field;
118116
}
119117
}
120118
return item;
@@ -298,7 +296,9 @@ export default class ResponseParser {
298296
tags: row.f[tagsColumnIndex].v
299297
? row.f[tagsColumnIndex].v.trim().split(/\s*,\s*/)
300298
: [],
301-
text: row.f[textColumnIndex].v ? row.f[textColumnIndex].v.toString() : "",
299+
text: row.f[textColumnIndex].v
300+
? row.f[textColumnIndex].v.toString()
301+
: "",
302302
time: Number(Math.floor(Number(row.f[timeColumnIndex].v))) * 1000
303303
});
304304
}

0 commit comments

Comments
 (0)