8000 Dates: Accept ISO-8601 format, and use UTC milliseconds as the backend by alexcjohnson · Pull Request #1194 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Dates: Accept ISO-8601 format, and use UTC milliseconds as the backend #1194

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 12 commits into from
Nov 25, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix one more UTC bug and update new tests to UTC
  • Loading branch information
alexcjohnson committed Nov 23, 2016
commit fa0dd3836bf9a7948aa4740aa2e3c781a4a4a247
6 changes: 3 additions & 3 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -931,9 +931,9 @@ axes.tickIncrement = function(x, dtick, axrev) {
// Dates: months (or years)
if(tType === 'M') {
var y = new Date(x);
// is this browser consistent? setMonth edits a date bu 10000 t
// is this browser consistent? setUTCMonth edits a date but
// returns that date's milliseconds
return y.setMonth(y.getUTCMonth() + dtSigned);
return y.setUTCMonth(y.getUTCMonth() + dtSigned);
}

// Log scales: Linear, Digits
Expand Down Expand Up @@ -986,7 +986,7 @@ axes.tickFirst = function(ax) {
r0 = new Date(r0);
mdif = (r0.getUTCFullYear() - t0.getUTCFullYear()) * 12 +
r0.getUTCMonth() - t0.getUTCMonth();
t1 = t0.setMonth(t0.getUTCMonth() +
t1 = t0.setUTCMonth(t0.getUTCMonth() +
(Math.round(mdif / dtNum) + (axrev ? 1 : -1)) * dtNum);

while(axrev ? t1 > r0 : t1 < r0) {
Expand Down
4 changes: 2 additions & 2 deletions src/plots/cartesian/set_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ module.exports = function setConvert(ax) {
// NOTE: Changed this behavior: previously we took any numeric value
// to be a ms, even if it was a string that could be a bare year.
// Now we convert it as a date if at all possible, and only try
// as ms if that fails.
// as (local) ms if that fails.
var ms = Lib.dateTime2ms(v);
if(ms === BADNUM) {
if(isNumeric(v)) ms = Number(v);
if(isNumeric(v)) ms = Lib.dateTime2ms(new Date(v));
else return BADNUM;
}
return Lib.constrain(ms, Lib.MIN_MS, Lib.MAX_MS);
Expand Down
22 changes: 11 additions & 11 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ describe('Test axes', function() {
}

function mockHoverText(ax, x) {
var xCalc = (ax.d2l_noadd || ax.d2c)(x);
var xCalc = (ax.d2l_noadd || ax.d2l)(x);
var tickTextObj = Axes.tickText(ax, xCalc, true);
return tickTextObj.text;
}
Expand Down Expand Up @@ -1433,7 +1433,7 @@ describe('Test axes', function() {
'Feb 12'
];
expect(textOut).toEqual(expectedText);
expect(mockHoverText(ax, ax.d2c('1999-12-18 15:34:33.3')))
expect(mockHoverText(ax, '1999-12-18 15:34:33.3'))
.toBe('Dec 18, 1999, 15:34');

ax = {
Expand All @@ -1454,7 +1454,7 @@ describe('Test axes', function() {
'00:00<br>Jan 6, 2000'
];
expect(textOut).toEqual(expectedText);
expect(mockHoverText(ax, ax.d2c('2000-01-04 15:34:33.3')))
expect(mockHoverText(ax, '2000-01-04 15:34:33.3'))
.toBe('Jan 4, 2000, 15:34:33');

ax = {
Expand All @@ -1475,9 +1475,9 @@ describe('Test axes', function() {
'00:00:02'
];
expect(textOut).toEqual(expectedText);
expect(mockHoverText(ax, ax.d2c('2000-02-04 00:00:00.123456')))
expect(mockHoverText(ax, '2000-02-04 00:00:00.123456'))
.toBe('Feb 4, 2000, 00:00:00.1235');
expect(mockHoverText(ax, ax.d2c('2000-02-04 00:00:00')))
expect(mockHoverText(ax, '2000-02-04 00:00:00'))
.toBe('Feb 4, 2000');
});

Expand All @@ -1500,9 +1500,9 @@ describe('Test axes', function() {
'00:05<br>Feb 12, 2000'
];
expect(textOut).toEqual(expectedText);
expect(mockHoverText(ax, ax.d2c('2000-02-04 00:00:00.123456')))
expect(mockHoverText(ax, '2000-02-04 00:00:00.123456'))
.toBe('Feb 4, 2000');
expect(mockHoverText(ax, ax.d2c('2000-02-04 00:00:05.123456')))
expect(mockHoverText(ax, '2000-02-04 00:00:05.123456'))
.toBe('Feb 4, 2000, 00:00:05');
});

Expand Down Expand Up @@ -1559,9 +1559,9 @@ describe('Test axes', function() {
'00:00:01<br>Jan 1, 2013'
];
expect(textOut).toEqual(expectedText);
expect(mockHoverText(ax, ax.d2c('2012-01-01')))
expect(mockHoverText(ax, '2012-01-01'))
.toBe('New year');
expect(mockHoverText(ax, ax.d2c('2012-01-01 12:34:56.1234')))
expect(mockHoverText(ax, '2012-01-01 12:34:56.1234'))
.toBe('Jan 1, 2012, 12:34:56');
});

Expand All @@ -1587,8 +1587,8 @@ describe('Test axes', function() {
// 10 and 0.1 are off scale
];
expect(textOut).toEqual(expectedText, axType);
expect(mockHoverText(ax, ax.c2l(1))).toBe('One');
expect(mockHoverText(ax, ax.c2l(19.999))).toBe('19.999');
expect(mockHoverText(ax, 1)).toBe('One');
expect(mockHoverText(ax, 19.999)).toBe('19.999');
});
});

Expand Down
8 changes: 3 additions & 5 deletions test/jasmine/tests/histogram_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ describe('Test histogram', function() {
return out;
}

// remove tzOffset when we move to UTC
var tzOffset = (new Date(1970, 0, 1)).getTimezoneOffset() * 60000,
oneDay = 24 * 3600000;
var oneDay = 24 * 3600000;

it('should handle auto dates with nonuniform (month) bins', function() {
var out = _calc({
Expand All @@ -165,7 +163,7 @@ describe('Test histogram', function() {
// bars. Now that we have explicit per-bar positioning, perhaps
// we should fill the space, rather than insisting on equal-width
// bars?
var x0 = tzOffset + 15768000000,
var x0 = 15768000000,
x1 = x0 + oneDay * 365,
x2 = x1 + oneDay * 365.5,
x3 = x2 + oneDay * 365.5;
Expand All @@ -186,7 +184,7 @@ describe('Test histogram', function() {
nbinsx: 4
});

var x0 = tzOffset,
var x0 = 0,
x1 = x0 + oneDay,
x2 = x1 + oneDay,
x3 = x2 + oneDay;
Expand Down
0