replace timezone => offset
This commit is contained in:
parent
21b8655f85
commit
70b4d5b7fd
@ -104,7 +104,7 @@ function getQueryRewriteData(mapConfig, dataviewDefinition, params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getOverrideParams(params, ownFilter) {
|
function getOverrideParams(params, ownFilter) {
|
||||||
var overrideParams = _.reduce(_.pick(params, 'start', 'end', 'bins', 'timezone'),
|
var overrideParams = _.reduce(_.pick(params, 'start', 'end', 'bins', 'offset'),
|
||||||
function castNumbers(overrides, val, k) {
|
function castNumbers(overrides, val, k) {
|
||||||
if (!Number.isFinite(+val)) {
|
if (!Number.isFinite(+val)) {
|
||||||
throw new Error('Invalid number format for parameter \'' + k + '\'');
|
throw new Error('Invalid number format for parameter \'' + k + '\'');
|
||||||
|
@ -89,7 +89,7 @@ LayergroupController.prototype.register = function(app) {
|
|||||||
'column_type', // string
|
'column_type', // string
|
||||||
'bins', // number
|
'bins', // number
|
||||||
'aggregation', //string
|
'aggregation', //string
|
||||||
'timezone', // number
|
'offset', // number
|
||||||
'q' // widgets search
|
'q' // widgets search
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -145,9 +145,9 @@ var dateBasicsQueryTpl = dot.template([
|
|||||||
' min(date_part(\'epoch\', {{=it._column}})) AS min_val,',
|
' min(date_part(\'epoch\', {{=it._column}})) AS min_val,',
|
||||||
' avg(date_part(\'epoch\', {{=it._column}})) AS avg_val,',
|
' avg(date_part(\'epoch\', {{=it._column}})) AS avg_val,',
|
||||||
' min(date_trunc(',
|
' min(date_trunc(',
|
||||||
' \'{{=it._aggregation}}\', {{=it._column}} AT TIME ZONE \'{{=it._timezone}}\'',
|
' \'{{=it._aggregation}}\', {{=it._column}} AT TIME ZONE \'{{=it._offset}}\'',
|
||||||
' )) AS start_date,',
|
' )) AS start_date,',
|
||||||
' max({{=it._column}} AT TIME ZONE \'{{=it._timezone}}\') AS end_date,',
|
' max({{=it._column}} AT TIME ZONE \'{{=it._offset}}\') AS end_date,',
|
||||||
' count(1) AS total_rows',
|
' count(1) AS total_rows',
|
||||||
' FROM ({{=it._query}}) _cdb_basics',
|
' FROM ({{=it._query}}) _cdb_basics',
|
||||||
')'
|
')'
|
||||||
@ -162,11 +162,11 @@ var dateOverrideBasicsQueryTpl = dot.template([
|
|||||||
' min(',
|
' min(',
|
||||||
' date_trunc(',
|
' date_trunc(',
|
||||||
' \'{{=it._aggregation}}\',',
|
' \'{{=it._aggregation}}\',',
|
||||||
' TO_TIMESTAMP({{=it._start}})::timestamp AT TIME ZONE \'{{=it._timezone}}\'',
|
' TO_TIMESTAMP({{=it._start}})::timestamp AT TIME ZONE \'{{=it._offset}}\'',
|
||||||
' )',
|
' )',
|
||||||
' ) AS start_date,',
|
' ) AS start_date,',
|
||||||
' max(',
|
' max(',
|
||||||
' TO_TIMESTAMP({{=it._end}})::timestamp AT TIME ZONE \'{{=it._timezone}}\'',
|
' TO_TIMESTAMP({{=it._end}})::timestamp AT TIME ZONE \'{{=it._offset}}\'',
|
||||||
' ) AS end_date,',
|
' ) AS end_date,',
|
||||||
' count(1) AS total_rows',
|
' count(1) AS total_rows',
|
||||||
' FROM ({{=it._query}}) _cdb_basics',
|
' FROM ({{=it._query}}) _cdb_basics',
|
||||||
@ -201,7 +201,7 @@ var dateHistogramQueryTpl = dot.template([
|
|||||||
' THEN 0',
|
' THEN 0',
|
||||||
' ELSE GREATEST(1, LEAST(',
|
' ELSE GREATEST(1, LEAST(',
|
||||||
' WIDTH_BUCKET(',
|
' WIDTH_BUCKET(',
|
||||||
' {{=it._column}}::timestamp AT TIME ZONE \'{{=it._timezone}}\',',
|
' {{=it._column}}::timestamp AT TIME ZONE \'{{=it._offset}}\',',
|
||||||
' bins_array',
|
' bins_array',
|
||||||
' ),',
|
' ),',
|
||||||
' bins_number',
|
' bins_number',
|
||||||
@ -212,7 +212,7 @@ var dateHistogramQueryTpl = dot.template([
|
|||||||
' \'epoch\', ',
|
' \'epoch\', ',
|
||||||
' date_trunc(',
|
' date_trunc(',
|
||||||
' \'{{=it._aggregation}}\', {{=it._column}}::timestamptz',
|
' \'{{=it._aggregation}}\', {{=it._column}}::timestamptz',
|
||||||
' ) AT TIME ZONE \'{{=it._timezone}}\'',
|
' ) AT TIME ZONE \'{{=it._offset}}\'',
|
||||||
' )',
|
' )',
|
||||||
' )::numeric AS timestamp,',
|
' )::numeric AS timestamp,',
|
||||||
' min(date_part(\'epoch\', {{=it._column}}))::numeric AS min,',
|
' min(date_part(\'epoch\', {{=it._column}}))::numeric AS min,',
|
||||||
@ -243,7 +243,7 @@ Time series:
|
|||||||
options: {
|
options: {
|
||||||
column: 'date', // column data type: date
|
column: 'date', // column data type: date
|
||||||
aggregation: 'day' // OPTIONAL (if undefined then it'll be built as numeric)
|
aggregation: 'day' // OPTIONAL (if undefined then it'll be built as numeric)
|
||||||
timezone: -7200 // OPTIONAL (UTC offset in seconds)
|
offset: -7200 // OPTIONAL (UTC offset in seconds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
@ -257,7 +257,7 @@ function Histogram(query, options, queries) {
|
|||||||
this.column = options.column;
|
this.column = options.column;
|
||||||
this.bins = options.bins;
|
this.bins = options.bins;
|
||||||
this.aggregation = options.aggregation;
|
this.aggregation = options.aggregation;
|
||||||
this.timezone = options.timezone;
|
this.offset = options.offset;
|
||||||
|
|
||||||
this._columnType = null;
|
this._columnType = null;
|
||||||
}
|
}
|
||||||
@ -380,7 +380,7 @@ Histogram.prototype._buildDateHistogramQuery = function (psql, override, callbac
|
|||||||
var _column = this.column;
|
var _column = this.column;
|
||||||
var _query = this.query;
|
var _query = this.query;
|
||||||
var _aggregation = override && override.aggregation ? override.aggregation : this.aggregation;
|
var _aggregation = override && override.aggregation ? override.aggregation : this.aggregation;
|
||||||
var _timezone = override && Number.isFinite(override.timezone) ? override.timezone : this.timezone;
|
var _offset = override && Number.isFinite(override.offset) ? override.offset : this.offset;
|
||||||
|
|
||||||
if (!_aggregation) {
|
if (!_aggregation) {
|
||||||
this.getAutomaticAggregation(psql, function (err, aggregation) {
|
this.getAutomaticAggregation(psql, function (err, aggregation) {
|
||||||
@ -403,14 +403,14 @@ Histogram.prototype._buildDateHistogramQuery = function (psql, override, callbac
|
|||||||
_aggregation: _aggregation,
|
_aggregation: _aggregation,
|
||||||
_start: getBinStart(override),
|
_start: getBinStart(override),
|
||||||
_end: getBinEnd(override),
|
_end: getBinEnd(override),
|
||||||
_timezone: getTimezone(_timezone, _aggregation)
|
_offset: getOffset(_offset, _aggregation)
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
dateBasicsQuery = dateBasicsQueryTpl({
|
dateBasicsQuery = dateBasicsQueryTpl({
|
||||||
_query: _query,
|
_query: _query,
|
||||||
_column: _column,
|
_column: _column,
|
||||||
_aggregation: _aggregation,
|
_aggregation: _aggregation,
|
||||||
_timezone: getTimezone(_timezone, _aggregation)
|
_offset: getOffset(_offset, _aggregation)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,7 +429,7 @@ Histogram.prototype._buildDateHistogramQuery = function (psql, override, callbac
|
|||||||
_query: _query,
|
_query: _query,
|
||||||
_column: _column,
|
_column: _column,
|
||||||
_aggregation: _aggregation,
|
_aggregation: _aggregation,
|
||||||
_timezone: getTimezone(_timezone, _aggregation)
|
_offset: getOffset(_offset, _aggregation)
|
||||||
});
|
});
|
||||||
|
|
||||||
var histogramSql = [
|
var histogramSql = [
|
||||||
@ -492,7 +492,7 @@ Histogram.prototype.format = function(result, override) {
|
|||||||
var buckets = [];
|
var buckets = [];
|
||||||
|
|
||||||
var aggregation = getAggregation(override, this.aggregation);
|
var aggregation = getAggregation(override, this.aggregation);
|
||||||
var timezone = getTimezoneParam(override, this.timezone);
|
var offset = getOffsetParam(override, this.offset);
|
||||||
var binsCount = getBinsCount(override);
|
var binsCount = getBinsCount(override);
|
||||||
var width = getWidth(override);
|
var width = getWidth(override);
|
||||||
var binsStart = getBinStart(override);
|
var binsStart = getBinStart(override);
|
||||||
@ -514,7 +514,7 @@ Histogram.prototype.format = function(result, override) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
aggregation: aggregation,
|
aggregation: aggregation,
|
||||||
timezone: timezone,
|
offset: offset,
|
||||||
bin_width: width,
|
bin_width: width,
|
||||||
bins_count: binsCount,
|
bins_count: binsCount,
|
||||||
bins_start: binsStart,
|
bins_start: binsStart,
|
||||||
@ -528,12 +528,12 @@ function getAggregation(override, aggregation) {
|
|||||||
return override && override.aggregation ? override.aggregation : aggregation;
|
return override && override.aggregation ? override.aggregation : aggregation;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTimezoneParam(override, timezone) {
|
function getOffsetParam(override, offset) {
|
||||||
if (override && override.timezone) {
|
if (override && override.offset) {
|
||||||
return override.timezone;
|
return override.offset;
|
||||||
}
|
}
|
||||||
if (timezone) {
|
if (offset) {
|
||||||
return timezone;
|
return offset;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -567,8 +567,8 @@ function getWidth(override) {
|
|||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTimezone(timezone, aggregation) {
|
function getOffset(offset, aggregation) {
|
||||||
if (!timezone) {
|
if (!offset) {
|
||||||
return '0';
|
return '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,8 +576,8 @@ function getTimezone(timezone, aggregation) {
|
|||||||
return '0';
|
return '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
var timezoneInHours = Math.ceil(timezone / 3600);
|
var offsetInHours = Math.ceil(offset / 3600);
|
||||||
return '' + timezoneInHours;
|
return '' + offsetInHours;
|
||||||
}
|
}
|
||||||
|
|
||||||
function populateBinStart(override, firstRow) {
|
function populateBinStart(override, firstRow) {
|
||||||
|
@ -132,7 +132,7 @@ describe('histogram-dataview for date column type', function() {
|
|||||||
options: {
|
options: {
|
||||||
column: 'd',
|
column: 'd',
|
||||||
aggregation: 'month',
|
aggregation: 'month',
|
||||||
timezone: -14400 // EDT Eastern Daylight Time (GMT-4) in seconds
|
offset: -14400 // EDT Eastern Daylight Time (GMT-4) in seconds
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
datetime_histogram_tz: {
|
datetime_histogram_tz: {
|
||||||
@ -143,7 +143,7 @@ describe('histogram-dataview for date column type', function() {
|
|||||||
options: {
|
options: {
|
||||||
column: 'd',
|
column: 'd',
|
||||||
aggregation: 'month',
|
aggregation: 'month',
|
||||||
timezone: -14400 // EDT Eastern Daylight Time (GMT-4) in seconds
|
offset: -14400 // EDT Eastern Daylight Time (GMT-4) in seconds
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
datetime_histogram_automatic: {
|
datetime_histogram_automatic: {
|
||||||
@ -238,16 +238,16 @@ describe('histogram-dataview for date column type', function() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
var dateHistogramsUseCases = [{
|
var dateHistogramsUseCases = [{
|
||||||
desc: 'supporting timestamp with timezone',
|
desc: 'supporting timestamp with offset',
|
||||||
dataviewId: 'datetime_histogram_tz'
|
dataviewId: 'datetime_histogram_tz'
|
||||||
}, {
|
}, {
|
||||||
desc: 'supporting timestamp without timezone',
|
desc: 'supporting timestamp without offset',
|
||||||
dataviewId: 'datetime_histogram'
|
dataviewId: 'datetime_histogram'
|
||||||
}];
|
}];
|
||||||
|
|
||||||
dateHistogramsUseCases.forEach(function (test) {
|
dateHistogramsUseCases.forEach(function (test) {
|
||||||
it('should create a date histogram aggregated in months (EDT) ' + test.desc, function (done) {
|
it('should create a date histogram aggregated in months (EDT) ' + test.desc, function (done) {
|
||||||
var TIMEZONE_EDT_IN_MINUTES = -4 * 60; // EDT Eastern Daylight Time (GMT-4) in minutes
|
var OFFSET_EDT_IN_MINUTES = -4 * 60; // EDT Eastern Daylight Time (GMT-4) in minutes
|
||||||
|
|
||||||
this.testClient = new TestClient(mapConfig, 1234);
|
this.testClient = new TestClient(mapConfig, 1234);
|
||||||
|
|
||||||
@ -260,18 +260,18 @@ describe('histogram-dataview for date column type', function() {
|
|||||||
var initialTimestamp = '2007-02-01T00:00:00-04:00'; // EDT midnight
|
var initialTimestamp = '2007-02-01T00:00:00-04:00'; // EDT midnight
|
||||||
var binsStartInMilliseconds = dataview.bins_start * 1000;
|
var binsStartInMilliseconds = dataview.bins_start * 1000;
|
||||||
var binsStartFormatted = moment.utc(binsStartInMilliseconds)
|
var binsStartFormatted = moment.utc(binsStartInMilliseconds)
|
||||||
.utcOffset(TIMEZONE_EDT_IN_MINUTES)
|
.utcOffset(OFFSET_EDT_IN_MINUTES)
|
||||||
.format();
|
.format();
|
||||||
assert.equal(binsStartFormatted, initialTimestamp);
|
assert.equal(binsStartFormatted, initialTimestamp);
|
||||||
|
|
||||||
dataview.bins.forEach(function(bin, index) {
|
dataview.bins.forEach(function(bin, index) {
|
||||||
var binTimestampExpected = moment.utc(initialTimestamp)
|
var binTimestampExpected = moment.utc(initialTimestamp)
|
||||||
.utcOffset(TIMEZONE_EDT_IN_MINUTES)
|
.utcOffset(OFFSET_EDT_IN_MINUTES)
|
||||||
.add(index, 'month')
|
.add(index, 'month')
|
||||||
.format();
|
.format();
|
||||||
var binsTimestampInMilliseconds = bin.timestamp * 1000;
|
var binsTimestampInMilliseconds = bin.timestamp * 1000;
|
||||||
var binTimestampFormatted = moment.utc(binsTimestampInMilliseconds)
|
var binTimestampFormatted = moment.utc(binsTimestampInMilliseconds)
|
||||||
.utcOffset(TIMEZONE_EDT_IN_MINUTES)
|
.utcOffset(OFFSET_EDT_IN_MINUTES)
|
||||||
.format();
|
.format();
|
||||||
|
|
||||||
assert.equal(binTimestampFormatted, binTimestampExpected);
|
assert.equal(binTimestampFormatted, binTimestampExpected);
|
||||||
@ -344,11 +344,11 @@ describe('histogram-dataview for date column type', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should aggregate histogram overriding default timezone to CEST ' + test.desc, function (done) {
|
it('should aggregate histogram overriding default offset to CEST ' + test.desc, function (done) {
|
||||||
var TIMEZONE_CEST_IN_SECONDS = 2 * 3600; // Central European Summer Time (Daylight Saving Time)
|
var OFFSET_CEST_IN_SECONDS = 2 * 3600; // Central European Summer Time (Daylight Saving Time)
|
||||||
var TIMEZONE_CEST_IN_MINUTES = 2 * 60; // Central European Summer Time (Daylight Saving Time)
|
var OFFSET_CEST_IN_MINUTES = 2 * 60; // Central European Summer Time (Daylight Saving Time)
|
||||||
var params = {
|
var params = {
|
||||||
timezone: TIMEZONE_CEST_IN_SECONDS
|
offset: OFFSET_CEST_IN_SECONDS
|
||||||
};
|
};
|
||||||
|
|
||||||
this.testClient = new TestClient(mapConfig, 1234);
|
this.testClient = new TestClient(mapConfig, 1234);
|
||||||
@ -361,18 +361,18 @@ describe('histogram-dataview for date column type', function() {
|
|||||||
var initialTimestamp = '2007-02-01T00:00:00+02:00'; // CEST midnight
|
var initialTimestamp = '2007-02-01T00:00:00+02:00'; // CEST midnight
|
||||||
var binsStartInMilliseconds = dataview.bins_start * 1000;
|
var binsStartInMilliseconds = dataview.bins_start * 1000;
|
||||||
var binsStartFormatted = moment.utc(binsStartInMilliseconds)
|
var binsStartFormatted = moment.utc(binsStartInMilliseconds)
|
||||||
.utcOffset(TIMEZONE_CEST_IN_MINUTES)
|
.utcOffset(OFFSET_CEST_IN_MINUTES)
|
||||||
.format();
|
.format();
|
||||||
assert.equal(binsStartFormatted, initialTimestamp);
|
assert.equal(binsStartFormatted, initialTimestamp);
|
||||||
|
|
||||||
dataview.bins.forEach(function (bin, index) {
|
dataview.bins.forEach(function (bin, index) {
|
||||||
var binTimestampExpected = moment.utc(initialTimestamp)
|
var binTimestampExpected = moment.utc(initialTimestamp)
|
||||||
.utcOffset(TIMEZONE_CEST_IN_MINUTES)
|
.utcOffset(OFFSET_CEST_IN_MINUTES)
|
||||||
.add(index, 'month')
|
.add(index, 'month')
|
||||||
.format();
|
.format();
|
||||||
var binsTimestampInMilliseconds = bin.timestamp * 1000;
|
var binsTimestampInMilliseconds = bin.timestamp * 1000;
|
||||||
var binTimestampFormatted = moment.utc(binsTimestampInMilliseconds)
|
var binTimestampFormatted = moment.utc(binsTimestampInMilliseconds)
|
||||||
.utcOffset(TIMEZONE_CEST_IN_MINUTES)
|
.utcOffset(OFFSET_CEST_IN_MINUTES)
|
||||||
.format();
|
.format();
|
||||||
|
|
||||||
assert.equal(binTimestampFormatted, binTimestampExpected);
|
assert.equal(binTimestampFormatted, binTimestampExpected);
|
||||||
@ -384,11 +384,11 @@ describe('histogram-dataview for date column type', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should aggregate histogram overriding default timezone to UTC/GMT ' + test.desc, function (done) {
|
it('should aggregate histogram overriding default offset to UTC/GMT ' + test.desc, function (done) {
|
||||||
var TIMEZONE_UTC_IN_SECONDS = 0 * 3600; // UTC
|
var OFFSET_UTC_IN_SECONDS = 0 * 3600; // UTC
|
||||||
var TIMEZONE_UTC_IN_MINUTES = 0 * 60; // UTC
|
var OFFSET_UTC_IN_MINUTES = 0 * 60; // UTC
|
||||||
var params = {
|
var params = {
|
||||||
timezone: TIMEZONE_UTC_IN_SECONDS
|
offset: OFFSET_UTC_IN_SECONDS
|
||||||
};
|
};
|
||||||
|
|
||||||
this.testClient = new TestClient(mapConfig, 1234);
|
this.testClient = new TestClient(mapConfig, 1234);
|
||||||
@ -401,18 +401,18 @@ describe('histogram-dataview for date column type', function() {
|
|||||||
var initialTimestamp = '2007-02-01T00:00:00Z'; // UTC midnight
|
var initialTimestamp = '2007-02-01T00:00:00Z'; // UTC midnight
|
||||||
var binsStartInMilliseconds = dataview.bins_start * 1000;
|
var binsStartInMilliseconds = dataview.bins_start * 1000;
|
||||||
var binsStartFormatted = moment.utc(binsStartInMilliseconds)
|
var binsStartFormatted = moment.utc(binsStartInMilliseconds)
|
||||||
.utcOffset(TIMEZONE_UTC_IN_MINUTES)
|
.utcOffset(OFFSET_UTC_IN_MINUTES)
|
||||||
.format();
|
.format();
|
||||||
assert.equal(binsStartFormatted, initialTimestamp);
|
assert.equal(binsStartFormatted, initialTimestamp);
|
||||||
|
|
||||||
dataview.bins.forEach(function (bin, index) {
|
dataview.bins.forEach(function (bin, index) {
|
||||||
var binTimestampExpected = moment.utc(initialTimestamp)
|
var binTimestampExpected = moment.utc(initialTimestamp)
|
||||||
.utcOffset(TIMEZONE_UTC_IN_MINUTES)
|
.utcOffset(OFFSET_UTC_IN_MINUTES)
|
||||||
.add(index, 'month')
|
.add(index, 'month')
|
||||||
.format();
|
.format();
|
||||||
var binsTimestampInMilliseconds = bin.timestamp * 1000;
|
var binsTimestampInMilliseconds = bin.timestamp * 1000;
|
||||||
var binTimestampFormatted = moment.utc(binsTimestampInMilliseconds)
|
var binTimestampFormatted = moment.utc(binsTimestampInMilliseconds)
|
||||||
.utcOffset(TIMEZONE_UTC_IN_MINUTES)
|
.utcOffset(OFFSET_UTC_IN_MINUTES)
|
||||||
.format();
|
.format();
|
||||||
|
|
||||||
assert.equal(binTimestampFormatted, binTimestampExpected);
|
assert.equal(binTimestampFormatted, binTimestampExpected);
|
||||||
@ -425,10 +425,10 @@ describe('histogram-dataview for date column type', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should aggregate histogram using "quarter" aggregation ' + test.desc, function (done) {
|
it('should aggregate histogram using "quarter" aggregation ' + test.desc, function (done) {
|
||||||
var TIMEZONE_UTC_IN_SECONDS = 0 * 3600; // UTC
|
var OFFSET_UTC_IN_SECONDS = 0 * 3600; // UTC
|
||||||
var TIMEZONE_UTC_IN_MINUTES = 0 * 60; // UTC
|
var OFFSET_UTC_IN_MINUTES = 0 * 60; // UTC
|
||||||
var params = {
|
var params = {
|
||||||
timezone: TIMEZONE_UTC_IN_SECONDS,
|
offset: OFFSET_UTC_IN_SECONDS,
|
||||||
aggregation: 'quarter'
|
aggregation: 'quarter'
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -442,18 +442,18 @@ describe('histogram-dataview for date column type', function() {
|
|||||||
var initialTimestamp = '2007-01-01T00:00:00Z'; // UTC midnight
|
var initialTimestamp = '2007-01-01T00:00:00Z'; // UTC midnight
|
||||||
var binsStartInMilliseconds = dataview.bins_start * 1000;
|
var binsStartInMilliseconds = dataview.bins_start * 1000;
|
||||||
var binsStartFormatted = moment.utc(binsStartInMilliseconds)
|
var binsStartFormatted = moment.utc(binsStartInMilliseconds)
|
||||||
.utcOffset(TIMEZONE_UTC_IN_MINUTES)
|
.utcOffset(OFFSET_UTC_IN_MINUTES)
|
||||||
.format();
|
.format();
|
||||||
assert.equal(binsStartFormatted, initialTimestamp);
|
assert.equal(binsStartFormatted, initialTimestamp);
|
||||||
|
|
||||||
dataview.bins.forEach(function (bin, index) {
|
dataview.bins.forEach(function (bin, index) {
|
||||||
var binTimestampExpected = moment.utc(initialTimestamp)
|
var binTimestampExpected = moment.utc(initialTimestamp)
|
||||||
.utcOffset(TIMEZONE_UTC_IN_MINUTES)
|
.utcOffset(OFFSET_UTC_IN_MINUTES)
|
||||||
.add(index * 3, 'month')
|
.add(index * 3, 'month')
|
||||||
.format();
|
.format();
|
||||||
var binsTimestampInMilliseconds = bin.timestamp * 1000;
|
var binsTimestampInMilliseconds = bin.timestamp * 1000;
|
||||||
var binTimestampFormatted = moment.utc(binsTimestampInMilliseconds)
|
var binTimestampFormatted = moment.utc(binsTimestampInMilliseconds)
|
||||||
.utcOffset(TIMEZONE_UTC_IN_MINUTES)
|
.utcOffset(OFFSET_UTC_IN_MINUTES)
|
||||||
.format();
|
.format();
|
||||||
|
|
||||||
assert.equal(binTimestampFormatted, binTimestampExpected);
|
assert.equal(binTimestampFormatted, binTimestampExpected);
|
||||||
@ -466,9 +466,9 @@ describe('histogram-dataview for date column type', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('bins_count should be equal to bins length filtered by start and end ' + test.desc, function (done) {
|
it('bins_count should be equal to bins length filtered by start and end ' + test.desc, function (done) {
|
||||||
var TIMEZONE_UTC_IN_SECONDS = 0 * 3600; // UTC
|
var OFFSET_UTC_IN_SECONDS = 0 * 3600; // UTC
|
||||||
var params = {
|
var params = {
|
||||||
timezone: TIMEZONE_UTC_IN_SECONDS,
|
offset: OFFSET_UTC_IN_SECONDS,
|
||||||
aggregation: 'quarter',
|
aggregation: 'quarter',
|
||||||
start: 1167609600, // 2007-01-01T00:00:00Z, first bin start
|
start: 1167609600, // 2007-01-01T00:00:00Z, first bin start
|
||||||
end: 1214870399 // 2008-06-30T23:59:59Z, last bin end
|
end: 1214870399 // 2008-06-30T23:59:59Z, last bin end
|
||||||
@ -487,9 +487,9 @@ describe('histogram-dataview for date column type', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('bins_count should be greater than bins length filtered by start and end ' + test.desc, function (done) {
|
it('bins_count should be greater than bins length filtered by start and end ' + test.desc, function (done) {
|
||||||
var TIMEZONE_UTC_IN_SECONDS = 0 * 3600; // UTC
|
var OFFSET_UTC_IN_SECONDS = 0 * 3600; // UTC
|
||||||
var params = {
|
var params = {
|
||||||
timezone: TIMEZONE_UTC_IN_SECONDS,
|
offset: OFFSET_UTC_IN_SECONDS,
|
||||||
aggregation: 'quarter',
|
aggregation: 'quarter',
|
||||||
start: 1167609600, // 2007-01-01T00:00:00Z, first bin start
|
start: 1167609600, // 2007-01-01T00:00:00Z, first bin start
|
||||||
end: 1214870400 // 2008-07-01T00:00:00Z, start the next bin to the last
|
end: 1214870400 // 2008-07-01T00:00:00Z, start the next bin to the last
|
||||||
@ -548,22 +548,22 @@ describe('histogram-dataview for date column type', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not apply timezone for a histogram aggregated by minutes', function (done) {
|
it('should not apply offset for a histogram aggregated by minutes', function (done) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var params = {
|
var params = {
|
||||||
timezone: '-3600'
|
offset: '-3600'
|
||||||
};
|
};
|
||||||
|
|
||||||
self.testClient = new TestClient(mapConfig, 1234);
|
self.testClient = new TestClient(mapConfig, 1234);
|
||||||
|
|
||||||
self.testClient.getDataview('minute_histogram', {}, function (err, dataview) {
|
self.testClient.getDataview('minute_histogram', {}, function (err, dataview) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
self.testClient.getDataview('minute_histogram', params, function (err, dataviewWithTimezone) {
|
self.testClient.getDataview('minute_histogram', params, function (err, dataviewWithOffset) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|
||||||
assert.notEqual(dataview.timezone, dataviewWithTimezone.timezone);
|
assert.notEqual(dataview.offset, dataviewWithOffset.offset);
|
||||||
dataview.timezone = dataviewWithTimezone.timezone;
|
dataview.offset = dataviewWithOffset.offset;
|
||||||
assert.deepEqual(dataview, dataviewWithTimezone);
|
assert.deepEqual(dataview, dataviewWithOffset);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -576,10 +576,10 @@ describe('histogram-dataview for date column type', function() {
|
|||||||
end: 1171584600 // 2007-02-16 00:10:00 = max(date_colum)
|
end: 1171584600 // 2007-02-16 00:10:00 = max(date_colum)
|
||||||
};
|
};
|
||||||
|
|
||||||
var paramsWithTimezone = {
|
var paramsWithOffset = {
|
||||||
start: 1171583400, // 2007-02-15 23:50:00 = min(date_colum)
|
start: 1171583400, // 2007-02-15 23:50:00 = min(date_colum)
|
||||||
end: 1171584600, // 2007-02-16 00:10:00 = max(date_colum)
|
end: 1171584600, // 2007-02-16 00:10:00 = max(date_colum)
|
||||||
timezone: '-3600'
|
offset: '-3600'
|
||||||
};
|
};
|
||||||
|
|
||||||
self.testClient = new TestClient(mapConfig, 1234);
|
self.testClient = new TestClient(mapConfig, 1234);
|
||||||
@ -591,13 +591,13 @@ describe('histogram-dataview for date column type', function() {
|
|||||||
|
|
||||||
assert.deepEqual(dataview, filteredDataview);
|
assert.deepEqual(dataview, filteredDataview);
|
||||||
|
|
||||||
self.testClient.getDataview('minute_histogram', paramsWithTimezone,
|
self.testClient.getDataview('minute_histogram', paramsWithOffset,
|
||||||
function (err, filteredWithTimezoneDataview) {
|
function (err, filteredWithOffsetDataview) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|
||||||
assert.notEqual(filteredWithTimezoneDataview.timezone, filteredDataview.timezone);
|
assert.notEqual(filteredWithOffsetDataview.offset, filteredDataview.offset);
|
||||||
filteredWithTimezoneDataview.timezone = filteredDataview.timezone;
|
filteredWithOffsetDataview.offset = filteredDataview.offset;
|
||||||
assert.deepEqual(filteredWithTimezoneDataview, filteredDataview);
|
assert.deepEqual(filteredWithOffsetDataview, filteredDataview);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -618,7 +618,7 @@ describe('histogram-dataview for date column type', function() {
|
|||||||
bin_width: 600,
|
bin_width: 600,
|
||||||
bins_count: 2,
|
bins_count: 2,
|
||||||
bins_start: 1171497600,
|
bins_start: 1171497600,
|
||||||
timezone: 0,
|
offset: 0,
|
||||||
nulls: 0,
|
nulls: 0,
|
||||||
bins:
|
bins:
|
||||||
[{
|
[{
|
||||||
@ -649,23 +649,23 @@ describe('histogram-dataview for date column type', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a histogram aggregated by days with timezone', function (done) {
|
it('should return a histogram aggregated by days with offset', function (done) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var paramsWithDailyAggAndTimezone = {
|
var paramsWithDailyAggAndOffset = {
|
||||||
aggregation: 'day',
|
aggregation: 'day',
|
||||||
timezone: '-3600'
|
offset: '-3600'
|
||||||
};
|
};
|
||||||
|
|
||||||
// data (UTC): from 2007-02-15 23:50:00 to 2007-02-16 00:10:00
|
// data (UTC): from 2007-02-15 23:50:00 to 2007-02-16 00:10:00
|
||||||
|
|
||||||
var dataviewWithDailyAggAndTimezoneFixture = {
|
var dataviewWithDailyAggAndOffsetFixture = {
|
||||||
aggregation: 'day',
|
aggregation: 'day',
|
||||||
bin_width: 1200,
|
bin_width: 1200,
|
||||||
bins_count: 1,
|
bins_count: 1,
|
||||||
bins_start: 1171501200,
|
bins_start: 1171501200,
|
||||||
nulls: 0,
|
nulls: 0,
|
||||||
timezone: -3600,
|
offset: -3600,
|
||||||
bins:
|
bins:
|
||||||
[{
|
[{
|
||||||
bin: 0,
|
bin: 0,
|
||||||
@ -679,10 +679,10 @@ describe('histogram-dataview for date column type', function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
self.testClient = new TestClient(mapConfig, 1234);
|
self.testClient = new TestClient(mapConfig, 1234);
|
||||||
self.testClient.getDataview('minute_histogram', paramsWithDailyAggAndTimezone, function (err, dataview) {
|
self.testClient.getDataview('minute_histogram', paramsWithDailyAggAndOffset, function (err, dataview) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|
||||||
assert.deepEqual(dataview, dataviewWithDailyAggAndTimezoneFixture);
|
assert.deepEqual(dataview, dataviewWithDailyAggAndOffsetFixture);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -369,7 +369,7 @@ TestClient.prototype.getDataview = function(dataviewName, params, callback) {
|
|||||||
own_filter: params.hasOwnProperty('own_filter') ? params.own_filter : 1
|
own_filter: params.hasOwnProperty('own_filter') ? params.own_filter : 1
|
||||||
};
|
};
|
||||||
|
|
||||||
['bbox', 'bins', 'start', 'end', 'aggregation', 'timezone'].forEach(function(extraParam) {
|
['bbox', 'bins', 'start', 'end', 'aggregation', 'offset'].forEach(function(extraParam) {
|
||||||
if (params.hasOwnProperty(extraParam)) {
|
if (params.hasOwnProperty(extraParam)) {
|
||||||
urlParams[extraParam] = params[extraParam];
|
urlParams[extraParam] = params[extraParam];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user