Last active
January 13, 2017 20:28
-
-
Save leoherzog/0d2b2222c068e4cbbbfc3a84edf8f696 to your computer and use it in GitHub Desktop.
Sort your array of CalendarEvent objects that were returned from the Google Apps Script CalendarApp
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
// copy this to the bottom of your script, then call it on your array of CalendarEvent objects that you got from the CalendarApp | |
// | |
// ex: | |
// var sortedEvents = sortArrayOfCalendarEventsChronologically(events); | |
// or | |
// events = sortArrayOfCalendarEventsChronologically(events); | |
function sortArrayOfCalendarEventsChronologically(array) { | |
if (!array || array.length == 0) { | |
return 0; | |
} | |
var temp = []; | |
for (var i in array) { | |
var startTime = new Date(array[i].getStartTime()); | |
var startTimeMilli = startTime.getTime(); | |
for (var j in temp) { | |
var iteratorStartTime = temp[j].getStartTime(); | |
var iteratorStartTimeMilli = iteratorStartTime.getTime(); | |
if (startTimeMilli < iteratorStartTimeMilli) { | |
break; | |
} | |
} | |
temp.splice(j, 0, array[i]); | |
} | |
return temp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment