Skip to content

Fix tz offset #241

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion src/js/charts/cb-xy/parse-xy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,17 @@ function parseXY(config, _chartProps, callback, parseOpts) {
// clone so that we aren't modifying original
// this can probably be avoided by applying new settings differently
var chartProps = JSON.parse(JSON.stringify(_chartProps));

var bySeries = dataBySeries(chartProps.input.raw, {
checkForDate: true,
type: chartProps.input.type
type: chartProps.input.type,
inputTZ: (function() {
if (chartProps.scale.dateSettings) {
return chartProps.scale.dateSettings.inputTZ;
} else {
return "Z";
}
})()
});

var labels = chartProps._annotations.labels;
Expand Down
8 changes: 4 additions & 4 deletions src/js/components/chart-grid/ChartGridXY.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ function drawXYChartGrid(el, state) {
text: numericSettings ? numericSettings.suffix : "",
dy: state.grid.rows == 1 ? "1.2em" : 0
}]
})
})

})
.using("xAxis", function(axis) {
if(chartProps.scale.isNumeric) {
Expand Down Expand Up @@ -331,8 +331,8 @@ function drawXYChartGrid(el, state) {
text: "",
dy: 0
}]
})
})

})
chart.outerWidth(state.dimensions.width);
chart.extraPadding(extraPadding);
Expand Down
4 changes: 1 addition & 3 deletions src/js/components/chart-xy/XYRenderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -759,11 +759,9 @@ function drawXY(el, state) {
var inputOffset = state.chartProps.scale.dateSettings.inputTZ ? -help.TZOffsetToMinutes(state.chartProps.scale.dateSettings.inputTZ) : curOffset;
var timeOffset = 0;
axis.tickFormat(function(d,i) {

if(displayTZ === "as-entered") {
if (displayTZ === "as-entered") {
timeOffset = curOffset - inputOffset;
}

return dateSettings.dateFormatter(d.clone(),i,timeOffset);
});
}
Expand Down
5 changes: 4 additions & 1 deletion src/js/stores/SessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ var _session = {
separators: detectNumberSeparators(),
emSize: 10,
width: 640,
timerOn: (localStorage.hasOwnProperty("model") === true),
timerOn: (function() {
if (localStorage) return ( localStorage.hasOwnProperty("model") === true );
return false;
})(),
nowOffset: getTZOffset(now),
now: now
};
Expand Down
2 changes: 1 addition & 1 deletion src/js/util/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ function merge_or_apply(defaults, source) {
}

/**
* Given a the domain of a scale suggest the most numerous number
* Given a the domain of a scale suggest the most numerous number
* of round number ticks that it cold be divided into while still containing
values evenly divisible by 1, 2, 2.5, 5, 10, or 25.
* @param {array} domain - An array of two number like objects
Expand Down
3 changes: 2 additions & 1 deletion src/js/util/parse-data-by-series.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function dataBySeries(input, opts) {

var parsedInput = parseDelimInput(input, {
checkForDate: opts.checkForDate,
type: opts.type
type: opts.type,
inputTZ: opts.inputTZ
});

var columnNames = parsedInput.columnNames;
Expand Down
15 changes: 8 additions & 7 deletions src/js/util/parse-delimited-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ var help = require("./helper.js");
var assign = require("lodash/assign");
var defaults = require("lodash/defaults");
var unique = require("lodash/uniq");
var separators;
var SessionStore = require("../stores/SessionStore");

var curOffset = Date.create().getTimezoneOffset();
var tz_pattern = /((\+|\-)\d\d\:?\d\d)/gi;

// We need this to get the current locale's thousands separator
// Check for localStorage in case we are testing from node
if (typeof(localStorage) !== 'undefined') {
separators = require("../stores/SessionStore").get("separators");
separators = SessionStore.get("separators");
} else {
separators = {
decimal: ".",
Expand All @@ -40,7 +43,7 @@ function parseDelimInput(input, opts) {
var _defaultOpts = defaults(opts, {
delimiter: parseUtils.detectDelimiter(input),
type: opts.type,
inputTZ: "Z"
inputTZ: SessionStore.get("nowOffset")
});

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

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

var data = dsv.parse(input, function(d,ii) {
var curOffset = Date.create().getTimezoneOffset();
var offset = opts.inputTZ !== null ? -help.TZOffsetToMinutes(opts.inputTZ) : curOffset;
each(columnNames, function(column, i) {
if (i === 0) {
//first column
Expand Down
1 change: 0 additions & 1 deletion test/timezone-adjustments.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ test("timezone: tz adjustments", function(t) {
entries = cast(input, ["date-col", "val"], stripCharsRegex, opts).entries;
t.deepEqual(entries, expected,"dates that don't have a timezone are adjusted to local when there is no inputTZ");


opts = {
type: "date",
inputTZ: "-0500",
Expand Down