Commit b68c309d authored by Renfred Harper's avatar Renfred Harper

Fix bug consecutive open_times bug

Noticed a corner case in which the info pane would display open_times that incorrectly for certain non-consecutive days. Fix it and created a new custom jQuery function that handles displaying the schedule.
parent 0122836f
......@@ -12,6 +12,52 @@ function compareTimes(time1, time2) {
return true;
}
function areConsecutiveDays(time1, time2) {
if (time1 === undefined || time2 === undefined) {
return false;
}
else if (time1.start_day !== time2.start_day - 1) {
return false;
}
return true;
}
$.fn.displaySchedule = function(open_times){
/* Display each open time in a concise format. The following loop will
* determine if two consecutive days have the same open and closing times.
* If that is the case, the time will be shown as a range.
* (ie. Mon - Sat: 10:00 AM - 6:00 PM")
* Otherwise, each date is displayed for its individual day.
* (ie. Sun: "4:00 PM - 12:00 AM
*/
var element = '';
for(var i = 0; i < open_times.length; i++){
if (!compareTimes(open_times[i], open_times[i-1]) ||
!areConsecutiveDays(open_times[i-1], open_times[i])) {
element += '<div class="col-md-3"><b>';
}
if ((!compareTimes(open_times[i], open_times[i-1])
|| !areConsecutiveDays(open_times[i-1], open_times[i]))
&& compareTimes(open_times[i], open_times[i+1])
&& areConsecutiveDays(open_times[i], open_times[i+1])) {
// Add: "StartDay - "
element += days[open_times[i].start_day] + ' - ';
}
if (!compareTimes(open_times[i], open_times[i+1]) ||
open_times[i].start_day !== (open_times[i+1].start_day - 1)) {
// Add "EndDay: OpenTime - CloseTime"
opening = Date.parse(open_times[i].start_time);
closing = Date.parse(open_times[i].end_time);
element += days[open_times[i].start_day] + '</b>: ' +
opening.toLocaleTimeString().replace(/(\d+:\d{2})(:\d+ )/, "$1 ") + ' - ' +
closing.toLocaleTimeString().replace(/(\d+:\d{2})(:\d+ )/, "$1 ") + '</div>';
$(this).append(element);
element = '';
}
}
}
function dispalyInfo(restaurant) {
// Display restaurant info in the info-body without bracketed locations
$('#info-name').text(restaurant.name.replace(/ ?\[(.+)\]/, ''));
......@@ -31,30 +77,10 @@ function dispalyInfo(restaurant) {
$('#info-status').html('<b>Status:</b> Closed');
$('#info-next').empty().hide()
}
$('#info-schedule').empty();
// Display all open times for the main schedule
var open_times = restaurant.current_schedule.open_times;
var element = '';
$('#info-schedule').empty();
for(var i = 0; i < open_times.length; i++){
if (!compareTimes(open_times[i], open_times[i-1])){
element += '<div class="col-md-3"><b>';
}
if (!compareTimes(open_times[i], open_times[i-1]) &&
// Add: "StartDay - "
compareTimes(open_times[i], open_times[i+1])){
element += days[open_times[i].start_day] + ' - ';
}
if (!compareTimes(open_times[i], open_times[i+1])){
// Add "EndDay: OpenTime - CloseTime"
opening = Date.parse(open_times[i].start_time);
closing = Date.parse(open_times[i].end_time);
element += days[open_times[i].start_day] + '</b>: ' +
opening.toLocaleTimeString().replace(/(\d+:\d{2})(:\d+ )/, "$1 ") + ' - ' +
closing.toLocaleTimeString().replace(/(\d+:\d{2})(:\d+ )/, "$1 ") + '</div>';
$("#info-schedule").append(element);
element = '';
}
}
$('#info-schedule').displaySchedule(open_times);
}
days = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment