Skip to content

fix #1363 - honor tenths of milliseconds in old numeric date data #2847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/plots/cartesian/set_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ module.exports = function setConvert(ax, fullLayout) {
// as (local) ms if that fails.
var ms = dateTime2ms(v, calendar || ax.calendar);
if(ms === BADNUM) {
if(isNumeric(v)) ms = dateTime2ms(new Date(+v));
if(isNumeric(v)) {
v = +v;
// keep track of tenths of ms, that `new Date` will drop
// same logic as in Lib.ms2DateTime
var msecTenths = Math.floor(Lib.mod(v + 0.05, 1) * 10);
var msRounded = Math.round(v - msecTenths / 10);
ms = dateTime2ms(new Date(msRounded)) + msecTenths / 10;
}
else return BADNUM;
}
return ms;
Expand Down
12 changes: 10 additions & 2 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2510,10 +2510,18 @@ describe('Test axes', function() {
});

it('- date case', function() {
var msLocal = new Date(2000, 0, 1).getTime();
var msUTC = 946684800000;
var out = _makeCalcdata({
x: ['2000-01-01', NaN, null, new Date(2000, 0, 1).getTime()],
x: ['2000-01-01', NaN, null, msLocal],
}, 'x', 'date');
expect(out).toEqual([946684800000, BADNUM, BADNUM, 946684800000]);
expect(out).toEqual([msUTC, BADNUM, BADNUM, msUTC]);

// fractional milliseconds - should round to 0.1 msec
var out2 = _makeCalcdata({
x: [msLocal, msLocal + 0.04, msLocal + 0.06, msLocal + 0.5, msLocal + 0.94, msLocal + 0.96, msLocal + 1]
}, 'x', 'date');
expect(out2).toEqual([msUTC, msUTC, msUTC + 0.1, msUTC + 0.5, msUTC + 0.9, msUTC + 1, msUTC + 1]);
});

it('- category case', function() {
Expand Down