Skip to content

Commit fa0dd38

Browse files
committed
fix one more UTC bug and update new tests to UTC
1 parent 61778d2 commit fa0dd38

File tree

4 files changed

+19
-21
lines changed

4 files changed

+19
-21
lines changed

src/plots/cartesian/axes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -931,9 +931,9 @@ axes.tickIncrement = function(x, dtick, axrev) {
931931
// Dates: months (or years)
932932
if(tType === 'M') {
933933
var y = new Date(x);
934-
// is this browser consistent? setMonth edits a date but
934+
// is this browser consistent? setUTCMonth edits a date but
935935
// returns that date's milliseconds
936-
return y.setMonth(y.getUTCMonth() + dtSigned);
936+
return y.setUTCMonth(y.getUTCMonth() + dtSigned);
937937
}
938938

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

992992
while(axrev ? t1 > r0 : t1 < r0) {

src/plots/cartesian/set_convert.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,10 @@ module.exports = function setConvert(ax) {
265265
// NOTE: Changed this behavior: previously we took any numeric value
266266
// to be a ms, even if it was a string that could be a bare year.
267267
// Now we convert it as a date if at all possible, and only try
268-
// as ms if that fails.
268+
// as (local) ms if that fails.
269269
var ms = Lib.dateTime2ms(v);
270270
if(ms === BADNUM) {
271-
if(isNumeric(v)) ms = Number(v);
271+
if(isNumeric(v)) ms = Lib.dateTime2ms(new Date(v));
272272
else return BADNUM;
273273
}
274274
return Lib.constrain(ms, Lib.MIN_MS, Lib.MAX_MS);

test/jasmine/tests/axes_test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ describe('Test axes', function() {
14021402
}
14031403

14041404
function mockHoverText(ax, x) {
1405-
var xCalc = (ax.d2l_noadd || ax.d2c)(x);
1405+
var xCalc = (ax.d2l_noadd || ax.d2l)(x);
14061406
var tickTextObj = Axes.tickText(ax, xCalc, true);
14071407
return tickTextObj.text;
14081408
}
@@ -1433,7 +1433,7 @@ describe('Test axes', function() {
14331433
'Feb 12'
14341434
];
14351435
expect(textOut).toEqual(expectedText);
1436-
expect(mockHoverText(ax, ax.d2c('1999-12-18 15:34:33.3')))
1436+
expect(mockHoverText(ax, '1999-12-18 15:34:33.3'))
14371437
.toBe('Dec 18, 1999, 15:34');
14381438

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

14601460
ax = {
@@ -1475,9 +1475,9 @@ describe('Test axes', function() {
14751475
'00:00:02'
14761476
];
14771477
expect(textOut).toEqual(expectedText);
1478-
expect(mockHoverText(ax, ax.d2c('2000-02-04 00:00:00.123456')))
1478+
expect(mockHoverText(ax, '2000-02-04 00:00:00.123456'))
14791479
.toBe('Feb 4, 2000, 00:00:00.1235');
1480-
expect(mockHoverText(ax, ax.d2c('2000-02-04 00:00:00')))
1480+
expect(mockHoverText(ax, '2000-02-04 00:00:00'))
14811481
.toBe('Feb 4, 2000');
14821482
});
14831483

@@ -1500,9 +1500,9 @@ describe('Test axes', function() {
15001500
'00:05<br>Feb 12, 2000'
15011501
];
15021502
expect(textOut).toEqual(expectedText);
1503-
expect(mockHoverText(ax, ax.d2c('2000-02-04 00:00:00.123456')))
1503+
expect(mockHoverText(ax, '2000-02-04 00:00:00.123456'))
15041504
.toBe('Feb 4, 2000');
1505-
expect(mockHoverText(ax, ax.d2c('2000-02-04 00:00:05.123456')))
1505+
expect(mockHoverText(ax, '2000-02-04 00:00:05.123456'))
15061506
.toBe('Feb 4, 2000, 00:00:05');
15071507
});
15081508

@@ -1559,9 +1559,9 @@ describe('Test axes', function() {
15591559
'00:00:01<br>Jan 1, 2013'
15601560
];
15611561
expect(textOut).toEqual(expectedText);
1562-
expect(mockHoverText(ax, ax.d2c('2012-01-01')))
1562+
expect(mockHoverText(ax, '2012-01-01'))
15631563
.toBe('New year');
1564-
expect(mockHoverText(ax, ax.d2c('2012-01-01 12:34:56.1234')))
1564+
expect(mockHoverText(ax, '2012-01-01 12:34:56.1234'))
15651565
.toBe('Jan 1, 2012, 12:34:56');
15661566
});
15671567

@@ -1587,8 +1587,8 @@ describe('Test axes', function() {
15871587
// 10 and 0.1 are off scale
15881588
];
15891589
expect(textOut).toEqual(expectedText, axType);
1590-
expect(mockHoverText(ax, ax.c2l(1))).toBe('One');
1591-
expect(mockHoverText(ax, ax.c2l(19.999))).toBe('19.999');
1590+
expect(mockHoverText(ax, 1)).toBe('One');
1591+
expect(mockHoverText(ax, 19.999)).toBe('19.999');
15921592
});
15931593
});
15941594

test/jasmine/tests/histogram_test.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ describe('Test histogram', function() {
146146
return out;
147147
}
148148

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

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

189-
var x0 = tzOffset,
187+
var x0 = 0,
190188
x1 = x0 + oneDay,
191189
x2 = x1 + oneDay,
192190
x3 = x2 + oneDay;

0 commit comments

Comments
 (0)