diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index f82d43ad72d..779e88afe4d 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -372,8 +372,8 @@ export default class TimeScale extends Scale { const timestamps = tickOpts.source === 'labels' ? this.getLabelTimestamps() : this._generate(); if (options.bounds === 'ticks' && timestamps.length) { - this.min = this._userMin || timestamps[0]; - this.max = this._userMax || timestamps[timestamps.length - 1]; + this.min = isNullOrUndef(this._userMin) ? timestamps[0] : this._userMin; + this.max = isNullOrUndef(this._userMax) ? timestamps[timestamps.length - 1] : this._userMax; } const min = this.min; diff --git a/test/specs/scale.time.tests.js b/test/specs/scale.time.tests.js index 42817ae15c9..dde6afec275 100644 --- a/test/specs/scale.time.tests.js +++ b/test/specs/scale.time.tests.js @@ -28,6 +28,24 @@ describe('Time scale tests', function() { return scale.ticks.map(t => t.label); } + ['time', 'timeseries'].forEach(function(type) { + ['min', 'max'].forEach(function(bound) { + ['labels', 'auto'].forEach(function(source) { + it('should preserve an explicit epoch-zero ' + bound + ' for ' + type + ' with ' + source + ' ticks', function() { + var labels = bound === 'min' ? [1000, 2000] : [-2000, -1000]; + var options = {type: type, bounds: 'ticks', ticks: {source: source}, time: {unit: 'second'}}; + options[bound] = 0; + var chart = window.acquireChart({ + type: 'line', + data: {labels: labels, datasets: [{data: [1, 2]}]}, + options: {animation: false, scales: {x: options}} + }); + expect(chart.scales.x[bound]).toBe(0); + }); + }); + }); + }); + beforeEach(function() { // Need a time matcher for getValueFromPixel jasmine.addMatchers({