Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I compare a time object in JSON with another time using date.js
    primarykey
    data
    text
    <p>I am using JavaScript, JSON, and date.js and I'm trying to parse the JSON file to display only the list of classes that are taking place at the current time. I've been able to parse the JSON file so it only shows classes that take place on the current day. I haven't been able to parse the times correctly though.</p> <p>Part of my JSON file:</p> <pre><code>[ { "day": "Monday", "activities": [ { "activity": "Freestyle ", "times": [ {"start":"6:30 AM","end":"7:15 AM"}, {"start":"7:15 AM","end":"8:15 AM"}, {"start":"5:15 PM","end":"6:00 PM"} ] }, { "activity": "Open Skate ", "times": [ {"start":"11:30 AM","end":"5:00 PM"}, {"start":"7:30 PM","end":"9:30 PM"} ] }, { "activity": "Holiday Snowbunnies 1 ", "times": [ {"start":"6:00 PM","end":"6:30 PM"} ] } ] }, { "day": "Tuesday", "activities": [ { "activity": "Freestyle ", "times": [ {"start":"5:45 AM","end":"6:30 AM"}, {"start":"6:30 AM","end":"7:15 AM"}, {"start":"6:45 PM","end":"7:30 PM"} ] }, { "activity": "Open Skate ", "times": [ {"start":"10:00 AM","end":"5:00 PM"}, {"start":"7:30 PM","end":"9:30 PM"} ] }, { "activity": "Patch ", "times": [ {"start":"10:00 AM","end":"10:30 AM"} ] } ] } ] </code></pre> <p>My JavaScript - With Appropriate Function:</p> <pre><code>function updateSchedule(responseText){ var activitiesDiv = document.getElementById("activities"); var skActivities = JSON.parse(responseText); var toDay = Date.today().getDayName(); var now = new Date(); var curHour = now.toTimeString('hh:mm tt'); for(var i=0;i&lt;skActivities.length;i++){ var activityDay = skActivities[i]; if(activityDay.day == toDay) { var toDaysActivities = activityDay.activities; for(var j=0;j&lt;toDaysActivities.length;j++){ var toDayActivity = toDaysActivities[j]; var curTimeDayActivities = toDayActivity.times; for(var k=0;k&lt;curTimeDayActivities.length;k++){ var curTimeDayStartActivity = curTimeDayActivities[k].start; if(curTimeDayStartActivity &gt;= curHour){ var div = document.createElement("div"); div.innerHTML = toDayActivity.activity + ": " + curTimeDayActivities[k].start; activitiesDiv.appendChild(div); } } } } continue; } } </code></pre> <p>Currently the function is returning all classes and their times that take place on the current day of the week. <strong>NOTE</strong>: The exception is the "11:30 AM Open Skate". It seems like the only values returned are those that are 9 and under.</p> <p>Again, my intent is for a user to visit the site and see the classes that are currently taking place.</p> <p><strong>NOTE</strong>: If we don't need the solution to utilize date.js, I'm fine with that. Just thought I would incorporate it.</p> <p>Any recommendations would be greatly appreciated. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload