get rid of timezone offset as we're already populating date object from timestamp

This commit is contained in:
Danny van Kooten 2018-09-13 11:47:48 +03:00
parent 5ef2b166ab
commit 86e50ca573
2 changed files with 10 additions and 11 deletions

View File

@ -52,9 +52,9 @@ function timeFormatPicker(n) {
function prepareData(startUnix, endUnix, data) {
// 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);
//const timezoneOffset = (new Date()).getTimezoneOffset() * 60;
let startDate = new Date((startUnix) * 1000);
let endDate = new Date((endUnix) * 1000);
let datamap = [];
let newData = [];
@ -65,7 +65,7 @@ function prepareData(startUnix, endUnix, data) {
d = data[i];
// replace date with actual date object & store in datamap
dateParts = d.Date.split('T')[0].split('-');
date = new Date(dateParts[0], dateParts[1]-1, dateParts[2], 0, 0, 0)
date = new Date(Date.UTC(dateParts[0], dateParts[1]-1, dateParts[2], 0, 0, 0))
key = date.getFullYear() + "-" + padZero(date.getMonth() + 1) + "-" + padZero(date.getDate());
d.Date = date;
datamap[key] = d;

View File

@ -46,7 +46,6 @@ const availablePeriods = {
},
}
const timezoneOffset = (new Date()).getTimezoneOffset() * 60;
const padZero = function(n){return n<10? '0'+n:''+n;}
class DatePicker extends Component {
@ -55,10 +54,10 @@ class DatePicker extends Component {
this.state = {
period: props.value,
before: 0,
after: 0,
startDate: null,
endDate: null,
before: 0, // UTC timestamp
after: 0, // UTC timestamp
startDate: null, // local date object
endDate: null, // local date object
}
this.updateDatesFromPeriod(this.state.period)
@ -87,8 +86,8 @@ class DatePicker extends Component {
// create unix timestamps from local date objects
let before, after;
before = Math.round(((+endDate) / 1000) - timezoneOffset);
after = Math.round(((+startDate) / 1000) - timezoneOffset);
before = Math.round((+endDate) / 1000);
after = Math.round((+startDate) / 1000);
this.setState({
period: period || '',