convert unix timestamps to local timezone for chart x-axes. fixes #39

This commit is contained in:
Danny 2018-05-28 23:30:59 +12:00
parent bf817eff8e
commit f822dbbdb7
2 changed files with 6 additions and 2 deletions

View File

@ -41,8 +41,10 @@ var timeFormatPicker = function (formats, len) {
};
function prepareData(startUnix, endUnix, data) {
let startDate = new Date(startUnix * 1000);
let endDate = new Date(endUnix * 1000);
// add timezone offset back in to get local start date
const timezoneOffset = (new Date()).getTimezoneOffset() * 60;
let startDate = new Date((startUnix + timezoneOffset) * 1000);
let endDate = new Date((endUnix+timezoneOffset) * 1000);
let datamap = [];
let newData = [];

View File

@ -85,6 +85,7 @@ class DatePicker extends Component {
let before, after;
before = Math.round(((+endDate) / 1000) - timezoneOffset);
after = Math.round(((+startDate) / 1000) - timezoneOffset);
this.setState({
period: period || '',
startDate: startDate,
@ -93,6 +94,7 @@ class DatePicker extends Component {
after: after,
});
// use slight delay for updating rest of application to allow this function to be called again
if(!this.timeout) {
this.timeout = window.setTimeout(() => {
this.props.onChange(this.state);