Merge pull request #720 from CartoDB/fix-aggregation-falsy-values

Fix bad condition when timestampt_start has falsy values
This commit is contained in:
Daniel
2017-08-03 18:36:37 +02:00
committed by GitHub
2 changed files with 72 additions and 1 deletions
+1 -1
View File
@@ -589,7 +589,7 @@ Histogram.prototype.format = function(result, override) {
nans = firstRow.nans_count;
binsStart = populateBinStart(override, firstRow);
if (timestampStart) {
if (Number.isFinite(timestampStart)) {
aggregation = getAggregation(override, this.aggregation);
offset = getOffset(override, this.offset);
}
+71
View File
@@ -887,3 +887,74 @@ describe('histogram-dates: aggregation input value', function() {
});
});
});
describe('histogram-dates: timestamp starts at epoch', function() {
afterEach(function(done) {
if (this.testClient) {
this.testClient.drain(done);
} else {
done();
}
});
var mapConfig = createMapConfig(
[
{
type: "cartodb",
options: {
source: {
id: "a0"
},
cartocss: "#points { marker-width: 10; marker-fill: red; }",
cartocss_version: "2.3.0"
}
}
],
{
epoch_start_histogram: {
source: {
id: 'a0'
},
type: 'histogram',
options: {
column: 'd',
aggregation: 'auto'
}
}
},
[
{
id: 'a0',
type: 'source',
params: {
query: [
'select null::geometry the_geom_webmercator, date AS d',
'from generate_series(',
'\'1970-01-04 10:00:00\'::timestamp,',
'\'1984-01-04 10:00:00\'::timestamp,',
' \'1 month\'::interval',
') date'
].join(' ')
}
}
]
);
it('should work when timestamp_start is epoch (1970-01-01 = 0)', function(done) {
this.testClient = new TestClient(mapConfig, 1234);
const override = {};
this.testClient.getDataview('epoch_start_histogram', override, function(err, dataview) {
assert.ifError(err);
const { aggregation, timestamp_start } = dataview;
assert.equal(timestamp_start, 0);
assert.equal(aggregation, 'month');
done();
});
});
});