I'm building a calendar that takes a JS object input from an RSS feed. This RSS feed is generated automatically from a CMS used internally in my company. I cannot change anything on the CMS side nor the returned RSS feed. All I have access to is the object that is built from that feed.
The RSS feed joins the start date, end date, time, and title all in one string. I need to separate them into keys in my object so my calendar can display them.
The problem I'm running into is the RSS feed formats the string differently depending on how the event is setup in the CMS. For example:
"7/15/2013 8:00 PM - 9:00 PM Blah" //Date, Time, Title
"7/12/2013 Blue" //Date for all day event, Title
"7/6/2013 8:00 AM - 7/23/2013 9:00 AM Banana" //Long event - Start Date, Start Time, End Date, End Time, Title
As you can see, how different these are I'm having a hard time deciding how I should go about parsing these into my object. The object should look like this:
{
title: 'Banana',
start: new Date(2013, 7, 24, 10, 30),
end: new Date(2013, 7, 24, 11, 30),
allDay: false
}
My question comes down to this: What would be a the best way to approach this? Use regex, try to parse it manually with things like .indexOf("/"), build test cases for each one, or some other suggestion.
PS: A jQuery example is an acceptable answer as well.