I have a task of using a JSON
response from the Eventbrite API to showcase the upcoming event tour date. The goal is to automatically calculate this date based on the current time, identifying the next event after the current moment.
Below is the JSON
response I need to dissect:
https://jsfiddle.net/dgc223/k9dbvzoo/
If I were to check it right now, I would expect the date on line 277 to be returned (2017-11-11T11:00:00)
. If checking in a few hours, the expected return should be from line 350 (2017-12-09T11:00:00)
, as that represents the following available date for the tour.
The current script provided (below) fetches the FIRST date in the sequence from the aforementioned JSON
response. However, I require a modification to retrieve the NEXT Tour date, factoring in the present time. This enhancement will offer more detailed information to users by specifying the upcoming tour date.
<script>
$.getJSON('eventbrite_api2.php', {
eventid: '35719663475',
function: 'events'
}, function(response) {
var date = new Date(response.start.utc); //this formats the date to local
time zone
date.toString();
event_start = date.toLocaleString('en-US', {
weekday: 'long',
day: 'numeric',
month: 'long',
year: 'numeric',
hour: 'numeric',
hour12: true,
timeZone: "America/New_York"
}); //this formats the date to eastern time zone, and makes some other formatting of the date
var content = "<h4>" + response.name.text + "</h4><p>The next event starts " + event_start + "</p>" + "<p>" + "<img width=\"350\" src=" + response.logo.original.url + "</img>";
$("#eventbrite").append(content);
});
</script>