Support UTC timezone override
This commit is contained in:
parent
c86f92f8eb
commit
d01787842f
@ -313,7 +313,7 @@ Histogram.prototype._buildDateHistogramQuery = function (override, callback) {
|
||||
var _column = this.column;
|
||||
var _query = this.query;
|
||||
var _aggregation = override && override.aggregation ? override.aggregation : this.aggregation;
|
||||
var _timezone = override && override.timezone ? override.timezone : this.timezone;
|
||||
var _timezone = override && Number.isFinite(override.timezone) ? override.timezone : this.timezone;
|
||||
|
||||
var dateBasicsQuery;
|
||||
|
||||
@ -438,7 +438,6 @@ function getTimezone(timezone) {
|
||||
if (!timezone) {
|
||||
return '0';
|
||||
}
|
||||
|
||||
var timezoneInHours = Math.ceil(timezone / 3600);
|
||||
return '' + timezoneInHours;
|
||||
}
|
||||
|
@ -267,4 +267,44 @@ describe('histogram-dataview for date column type', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should aggregate histogram overriding default timezone to UTC/GMT', function (done) {
|
||||
var TIMEZONE_UTC_IN_SECONDS = 0 * 3600; // UTC
|
||||
var TIMEZONE_UTC_IN_MINUTES = 0 * 60; // UTC
|
||||
var params = {
|
||||
timezone: TIMEZONE_UTC_IN_SECONDS
|
||||
};
|
||||
|
||||
this.testClient = new TestClient(mapConfig, 1234);
|
||||
this.testClient.getDataview('date_histogram', params, function(err, dataview) {
|
||||
assert.ok(!err, err);
|
||||
assert.equal(dataview.type, 'histogram');
|
||||
assert.ok(dataview.bin_width > 0, 'Unexpected bin width: ' + dataview.bin_width);
|
||||
assert.equal(dataview.bins.length, 15);
|
||||
|
||||
var initialTimestamp = '2007-02-01T00:00:00Z'; // UTC midnight
|
||||
var binsStartInMilliseconds = dataview.bins_start * 1000;
|
||||
var binsStartFormatted = moment.utc(binsStartInMilliseconds)
|
||||
.utcOffset(TIMEZONE_UTC_IN_MINUTES)
|
||||
.format();
|
||||
assert.equal(binsStartFormatted, initialTimestamp);
|
||||
|
||||
dataview.bins.forEach(function(bin, index) {
|
||||
var binTimestampExpected = moment.utc(initialTimestamp)
|
||||
.utcOffset(TIMEZONE_UTC_IN_MINUTES)
|
||||
.add(index, 'month')
|
||||
.format();
|
||||
var binsTimestampInMilliseconds = bin.timestamp * 1000;
|
||||
var binTimestampFormatted = moment.utc(binsTimestampInMilliseconds)
|
||||
.utcOffset(TIMEZONE_UTC_IN_MINUTES)
|
||||
.format();
|
||||
|
||||
assert.equal(binTimestampFormatted, binTimestampExpected);
|
||||
assert.ok(bin.timestamp <= bin.min, 'bin timestamp < bin min: ' + JSON.stringify(bin));
|
||||
assert.ok(bin.min <= bin.max, 'bin min < bin max: ' + JSON.stringify(bin));
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user