This code looks good, I only have 2 minor items from a once over;
I would have a constant for
-1
meaning an all day eventvar ALL_DAY_EVENT = -1; // <-- Declared somewhere on top if (position === ALL_DAY_EVENT) { ...
This:
if (secondHalf.indexOf("AM") !== -1) { var title = secondHalf.substring(secondHalf.indexOf("AM") + 3); //Title if has AM } else { var title = secondHalf.substring(secondHalf.indexOf("PM") + 3); //Title if has PM }
Declares
title
withvar
twice, you should declaretitle
only once, ideally on top before your loop. Also, there is some serious code repetition there. I would suggest something like://Declare meridiem and title somewhere higher prior to the loop meridiem = ~secondHalf.indexOf("AM") ? "AM" : "PM"; title = secondHalf.substring(secondHalf.indexOf(meridiem) + 3);