62 lines
2.1 KiB
HTML
62 lines
2.1 KiB
HTML
<div id="hours-content-container">
|
|
<div id="hours-content"></div>
|
|
<p>See our <a href="https://library.kbcc.cuny.edu/calendar">hours</a> page for more info.</p>
|
|
</div>
|
|
|
|
<script>
|
|
|
|
$(document).ready(function(){
|
|
|
|
// a function to add the offset
|
|
Date.prototype.addHours= function(h){
|
|
this.setHours(this.getHours()+h);
|
|
return this;
|
|
}
|
|
|
|
$.ajax({
|
|
url: "https://kbcc-cuny.libcal.com/widget/hours/grid?iid=5570&format=json&weeks=1&systemTime=0",
|
|
type: 'GET',
|
|
cache: false,
|
|
dataType: 'jsonp'
|
|
})
|
|
.done( function (data) {
|
|
for (let i = 0; i < data.locations.length; i++) {
|
|
if (data.locations[i].lid === 16733) {
|
|
weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
for (let j = 0; j < weekdays.length; j++) {
|
|
let x = weekdays[j];
|
|
hours = data.locations[i].weeks[0][x]["rendered"];
|
|
currently = data.locations[i].weeks[0][x]["times"]["currently_open"];
|
|
let start_and_end = hours.split(" - ");
|
|
let target_date = new Date(data.locations[i].weeks[0][x]["date"]);
|
|
offset = target_date.getTimezoneOffset() / 60;
|
|
target_date.addHours(offset);
|
|
let today = new Date()
|
|
let isToday = (today.toDateString() == target_date.toDateString());
|
|
if (isToday) {
|
|
if (start_and_end.length === 1) {
|
|
document.getElementById("hours-content").innerHTML += "The library is <strong>CLOSED</strong> today.<br />"
|
|
} else if (currently) {
|
|
document.getElementById("hours-content").innerHTML += "The library is currently <strong>OPEN</strong>.<br />Today's hours are <strong>" + hours + "</strong>.<br />";
|
|
} else {
|
|
document.getElementById("hours-content").innerHTML += "The library is currently <strong>CLOSED</strong>.<br />Today's hours are <strong>" + hours + "</strong>.<br />";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
});
|
|
|
|
</script>
|
|
|
|
<style>
|
|
|
|
#hours-content-container {
|
|
margin-top: -10px;
|
|
text-align: center;
|
|
font-size: 1.7em;
|
|
}
|
|
|
|
</style>
|