Skip to content

Instantly share code, notes, and snippets.

@poteto
Created February 24, 2019 05:40
Show Gist options
  • Save poteto/f3186ef2409446b90b7993643693332e to your computer and use it in GitHub Desktop.
Save poteto/f3186ef2409446b90b7993643693332e to your computer and use it in GitHub Desktop.
WIP: Create busy placeholders in GCal
function toDateRanges(items) {
return items
.filter(calEvent => {
return (
calEvent.start &&
calEvent.start.dateTime &&
calEvent.end &&
calEvent.end.dateTime
);
})
.map(calEvent => {
return {
startDate: new Date(calEvent.start.dateTime),
endDate: new Date(calEvent.end.dateTime)
};
})
.sort((a, b) => {
if (a.startDate.valueOf() < b.startDate.valueOf()) {
return -1;
}
if (a.startDate.valueOf() > b.startDate.valueOf()) {
return 1;
}
return 0;
});
}
function findGaps(ranges) {
let holes = [];
for (let i = 1; i < ranges.length; i++) {
const beginningOfHole = ranges[i - 1].endDate;
const endOfHole = ranges[i].startDate;
if (beginningOfHole.valueOf() < endOfHole.valueOf()) {
holes.push({ from: beginningOfHole, until: endOfHole });
}
}
return holes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment