I have a scenario where by I select a date from a jQuery Calendar and then, via ajax, iterate over a JSON file. My issue arises due to the use of date ranges, for example, see startdate and enddate:
{ "campus" : "A", "periods": [
{ "startdate" : "2013-01-02",
"enddate" : "2013-01-06",
"labels" : [
{ "Wednesday":
{ "00:00" : "Closed",
"09:00" : "Open",
"18:00" : "Closed"
},
"Thursday":
{ "00:00" : "Closed",
"09:00" : "Open",
"18:00" : "Closed"
},
"Friday":
{ "00:00" : "Closed",
"09:00" : "Open",
"18:00" : "Closed"
},
"Saturday":
{ "00:00" : "Closed"
},
"Sunday":
{ "00:00" : "Closed"
}
}]
},
{ "startdate" : "2013-01-07",
"enddate" : "2013-03-24",
"labels" : [
{ "Monday":
{ "00:00" : "Closed",
"09:00" : "Open",
"18:00" : "Closed"
},
"Tuesday":
{ "00:00" : "Closed",
"09:00" : "Open",
"18:00" : "Closed"
},
"Wednesday":
{ "00:00" : "Closed",
"09:00" : "Open",
"18:00" : "Closed"
},
"Thursday":
{ "00:00" : "Closed",
"09:00" : "Open",
"18:00" : "Closed"
},
"Friday":
{ "00:00" : "Closed",
"09:00" : "Open",
"18:00" : "Closed"
},
"Saturday":
{ "00:00" : "Closed"
},
"Sunday":
{ "00:00" : "Closed"
}
}]
}
As you can see from the snippet above, the startdate and enddate are a range. I was wondering what the best approach would be to try and select a date from within a range inside the JSON file.
I have considered using a PHP explode to break up the date that is passed to the ajax and then returned to the original page by doing a comparison between the exploded parameters and the data within the startdate and enddate. I Wondered if exploding the date and then iterating between the startdate and enddate to see if there is a match on the date would work?
If my above idea wouldn't work what other ways would be possible?