Answer the question
In order to leave comments, you need to log in
Algorithm for finding missing days?
The task is as follows:
The user requests data from 06/25/2019 to 07/04/2019 , for example
, not all data may come from the server, for example, from 06/30/2019 to 07/2/2019
My task is to find the missing dates, put them in intervals and request at intervals
approximately should look like this
intervals = [
{
start: '25.06.2019',
end: '29.06.2019'
},
{
start: '3.07.2019',
end: '4.07.2017'
}
]
import moment from 'moment';
export default function (start, end, obj) {
const arr = [];
let interval = null;
const newStart = moment(start, 'DD.MM.YYYY').format('YYYY-MM-DD').valueOf();
const newEnd = moment(end, 'DD.MM.YYYY').format('YYYY-MM-DD').valueOf();
console.log(!moment(newStart).isSame(newEnd));
for (let i = newStart; !moment(newStart).isSame(newEnd); i = moment(i, 'YYYY-MM-DD').add(1, 'd').format('YYYY-MM-DD')); {
let y = 0;
const newDate = moment(obj[y].date, 'DD.MM.YYYY').format('YYYY-MM-DD').valueOf();
const bool = moment(newDate).isSame(newEnd);
if (bool) {
if (interval) {
interval.end = i;
arr.push(interval);
interval = null;
}
} else if (!interval) {
interval.start = i;
}
y += 1;
}
return arr;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question