Created
February 24, 2019 05:40
-
-
Save poteto/f3186ef2409446b90b7993643693332e to your computer and use it in GitHub Desktop.
WIP: Create busy placeholders in GCal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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