Widget:AvailableCritters: Difference between revisions
Jump to navigation
Jump to search
Marblemadmax (talk | contribs) mNo edit summary |
Marblemadmax (talk | contribs) mNo edit summary |
||
Line 59: | Line 59: | ||
"Red and Beige Monkey": { "Monday": "12 AM to 12 PM", "Tuesday": "All day", "Wednesday": "12 AM to 12 PM", "Friday": "12 AM to 12 PM", "Saturday": "All day" } | "Red and Beige Monkey": { "Monday": "12 AM to 12 PM", "Tuesday": "All day", "Wednesday": "12 AM to 12 PM", "Friday": "12 AM to 12 PM", "Saturday": "All day" } | ||
}; | }; | ||
function isAvailable(critter, day, hour) { | |||
const availability = critters[critter][day]; | |||
if (!availability) return false; // 'n/a' or undefined | |||
if (availability === 'All day') return true; | |||
const [start, end] = availability.split(' to '); | |||
const startHour = parseHour(start); | |||
const endHour = parseHour(end); | |||
return hour >= startHour && hour < endHour; | |||
} | |||
function parseHour(timeStr) { | |||
const [time, period] = timeStr.split(' '); | |||
let [hours, minutes] = time.split(':'); | |||
hours = parseInt(hours); | |||
if (period === 'PM' && hours !== 12) hours += 12; | |||
if (period === 'AM' && hours === 12) hours = 0; | |||
return hours; | |||
} | |||
function updateCritterList() { | function updateCritterList() { | ||
Line 87: | Line 106: | ||
fetch(apiEndpoint + "?" + params.toString(), { | fetch(apiEndpoint + "?" + params.toString(), { | ||
method: 'POST', | method: 'POST', | ||
credentials: 'same-origin' | credentials: 'same-origin' | ||
}) | }) | ||
.then(response => response.json()) | .then(response => response.json()) |