Fixed date parsing in database queries.

This commit is contained in:
Mike Cao 2020-08-29 23:17:32 -07:00
parent 2ce2885b44
commit 07cc61f5c3
3 changed files with 38 additions and 16 deletions

View file

@ -95,17 +95,22 @@ export function getDateArray(data, startDate, endDate, unit) {
const arr = [];
const [diff, add, normalize] = dateFuncs[unit];
const n = diff(endDate, startDate) + 1;
console.log({ startDate, endDate, n });
function findData(t) {
const x = data.find(e => {
return getLocalTime(new Date(e.t)).getTime() === normalize(new Date(t)).getTime();
if (unit === 'day') {
const [year, month, day] = e.t.split('-');
return normalize(new Date(year, month - 1, day)).getTime() === t.getTime();
}
return normalize(new Date(e.t)).getTime() === t.getTime();
});
return x?.y || 0;
}
for (let i = 0; i < n; i++) {
const t = add(startDate, i);
const t = normalize(add(startDate, i));
const y = findData(t);
arr.push({ ...data[i], t, y });