Skip to content

Commit 96f0957

Browse files
committed
add timezone offset initial parse
offset for localized fix tz regex properly apply inputTZ option
1 parent 52b3de2 commit 96f0957

File tree

8 files changed

+29
-19
lines changed

8 files changed

+29
-19
lines changed

src/js/charts/cb-xy/parse-xy.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ function parseXY(config, _chartProps, callback, parseOpts) {
2323
// clone so that we aren't modifying original
2424
// this can probably be avoided by applying new settings differently
2525
var chartProps = JSON.parse(JSON.stringify(_chartProps));
26+
2627
var bySeries = dataBySeries(chartProps.input.raw, {
2728
checkForDate: true,
28-
type: chartProps.input.type
29+
type: chartProps.input.type,
30+
inputTZ: (function() {
31+
if (chartProps.scale.dateSettings) {
32+
return chartProps.scale.dateSettings.inputTZ;
33+
} else {
34+
return "Z";
35+
}
36+
})()
2937
});
3038

3139
var labels = chartProps._annotations.labels;

src/js/components/chart-grid/ChartGridXY.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ function drawXYChartGrid(el, state) {
276276
text: numericSettings ? numericSettings.suffix : "",
277277
dy: state.grid.rows == 1 ? "1.2em" : 0
278278
}]
279-
})
280-
279+
})
280+
281281
})
282282
.using("xAxis", function(axis) {
283283
if(chartProps.scale.isNumeric) {
@@ -331,8 +331,8 @@ function drawXYChartGrid(el, state) {
331331
text: "",
332332
dy: 0
333333
}]
334-
})
335-
334+
})
335+
336336
})
337337
chart.outerWidth(state.dimensions.width);
338338
chart.extraPadding(extraPadding);

src/js/components/chart-xy/XYRenderer.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -759,11 +759,9 @@ function drawXY(el, state) {
759759
var inputOffset = state.chartProps.scale.dateSettings.inputTZ ? -help.TZOffsetToMinutes(state.chartProps.scale.dateSettings.inputTZ) : curOffset;
760760
var timeOffset = 0;
761761
axis.tickFormat(function(d,i) {
762-
763-
if(displayTZ === "as-entered") {
762+
if (displayTZ === "as-entered") {
764763
timeOffset = curOffset - inputOffset;
765764
}
766-
767765
return dateSettings.dateFormatter(d.clone(),i,timeOffset);
768766
});
769767
}

src/js/stores/SessionStore.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ var _session = {
1010
separators: detectNumberSeparators(),
1111
emSize: 10,
1212
width: 640,
13-
timerOn: (localStorage.hasOwnProperty("model") === true),
13+
timerOn: (function() {
14+
if (localStorage) return ( localStorage.hasOwnProperty("model") === true );
15+
return false;
16+
})(),
1417
nowOffset: getTZOffset(now),
1518
now: now
1619
};

src/js/util/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ function merge_or_apply(defaults, source) {
216216
}
217217

218218
/**
219-
* Given a the domain of a scale suggest the most numerous number
219+
* Given a the domain of a scale suggest the most numerous number
220220
* of round number ticks that it cold be divided into while still containing
221221
values evenly divisible by 1, 2, 2.5, 5, 10, or 25.
222222
* @param {array} domain - An array of two number like objects

src/js/util/parse-data-by-series.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ function dataBySeries(input, opts) {
1616

1717
var parsedInput = parseDelimInput(input, {
1818
checkForDate: opts.checkForDate,
19-
type: opts.type
19+
type: opts.type,
20+
inputTZ: opts.inputTZ
2021
});
2122

2223
var columnNames = parsedInput.columnNames;

src/js/util/parse-delimited-input.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ var help = require("./helper.js");
99
var assign = require("lodash/assign");
1010
var defaults = require("lodash/defaults");
1111
var unique = require("lodash/uniq");
12-
var separators;
12+
var SessionStore = require("../stores/SessionStore");
13+
14+
var curOffset = Date.create().getTimezoneOffset();
15+
var tz_pattern = /((\+|\-)\d\d\:?\d\d)/gi;
1316

1417
// We need this to get the current locale's thousands separator
1518
// Check for localStorage in case we are testing from node
1619
if (typeof(localStorage) !== 'undefined') {
17-
separators = require("../stores/SessionStore").get("separators");
20+
separators = SessionStore.get("separators");
1821
} else {
1922
separators = {
2023
decimal: ".",
@@ -40,7 +43,7 @@ function parseDelimInput(input, opts) {
4043
var _defaultOpts = defaults(opts, {
4144
delimiter: parseUtils.detectDelimiter(input),
4245
type: opts.type,
43-
inputTZ: "Z"
46+
inputTZ: SessionStore.get("nowOffset")
4447
});
4548

4649
if (opts.checkForDate === false) {
@@ -97,12 +100,10 @@ function cast_data(input, columnNames, stripCharsRegex, opts) {
97100
var all_index_types = [];
98101
var all_entry_values = [];
99102

100-
var tz_pattern = /([+-]\d\d:*\d\d)/gi;
101-
var found_timezones = input.match(tz_pattern);
103+
var found_timezones = tz_pattern.test(input);
104+
var offset = opts.inputTZ !== null ? -help.TZOffsetToMinutes(opts.inputTZ) : curOffset;
102105

103106
var data = dsv.parse(input, function(d,ii) {
104-
var curOffset = Date.create().getTimezoneOffset();
105-
var offset = opts.inputTZ !== null ? -help.TZOffsetToMinutes(opts.inputTZ) : curOffset;
106107
each(columnNames, function(column, i) {
107108
if (i === 0) {
108109
//first column

test/timezone-adjustments.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ test("timezone: tz adjustments", function(t) {
7575
entries = cast(input, ["date-col", "val"], stripCharsRegex, opts).entries;
7676
t.deepEqual(entries, expected,"dates that don't have a timezone are adjusted to local when there is no inputTZ");
7777

78-
7978
opts = {
8079
type: "date",
8180
inputTZ: "-0500",

0 commit comments

Comments
 (0)