Commit b4e02b97 authored by Mattias J Duffy's avatar Mattias J Duffy
Browse files

sidebar and facility card hours can now handle when there are two schedules for the same day

parent 7a4660d2
Pipeline #1875 passed with stage
in 1 minute and 47 seconds
import React from 'react'
import Grid from 'material-ui/Grid';
import FacilityUtils from '../utils/facilityUtils';
import facilityUtils from '../utils/facilityUtils';
const WeekHours = ({facility}) => {
const weekDays = [
......@@ -14,15 +14,19 @@ const WeekHours = ({facility}) => {
];
let output = [];
try {
let index = 0;
for (let dayOfWeek = 0; dayOfWeek < 7; dayOfWeek++) {
output[dayOfWeek] = (
<Grid container key={facility.slug + dayOfWeek} className='week-hours-row'>
<Grid item xs={2} className='week-hours-day'>{weekDays[dayOfWeek]}</Grid>
<Grid item className='week-hours-times'>{FacilityUtils.getHoursByDay(facility, dayOfWeek)}</Grid>
</Grid>
)
const todaysHours = facilityUtils.getHoursByDay(facility,dayOfWeek)
for(let i = 0; i < todaysHours.length; i++){
output[index] = (
<Grid container spacing={0} key={facility.slug + index} className='week-hours-row'>
<Grid item xs={2} className='week-hours-day'>{weekDays[dayOfWeek]}</Grid>
<Grid item className='week-hours-times'>{todaysHours[i].text}</Grid>
</Grid>
)
index++;
}
}
} catch (e) {
}
......
......@@ -40,6 +40,7 @@ class FacilityCard extends React.Component {
isHovered:false
})
};
render() {
const {facility, facilities, favorites, selectedFacility, addFavoriteFacility, removeFavoriteFacility} = this.props;
......@@ -47,6 +48,20 @@ class FacilityCard extends React.Component {
const isSelected = selectedFacility.slug === facility.slug;
const dayOfWeek = [6, 0, 1, 2, 3, 4, 5][new Date().getDay()];
const getDisplayHours = () => {
let currentHour = new Date().getHours();
const todaysHours = FacilityUtils.getHoursByDay(facility, dayOfWeek)
if(todaysHours.length > 1){
for(let i = 0; i < todaysHours.length; i++){
const hour = todaysHours[i]
if(currentHour <= parseInt(hour.end) && currentHour >= parseInt(hour.start)){
return hour.text;
}
}
}
return todaysHours[0].text
}
return (
<Card onClick={this.handleCardClick} className={classnames('fc-root', isSelected && 'fc-selected')}
......@@ -75,7 +90,7 @@ class FacilityCard extends React.Component {
</Grid>
<Grid item className={'fc-small-grid-item-spacing'}>
<Typography type={'body1'}>
{"Today: " + FacilityUtils.getHoursByDay(facility, dayOfWeek)}
{"Today: " + getDisplayHours()}
</Typography>
</Grid>
</Grid>
......
......@@ -14,7 +14,7 @@
}
.sidebar-open {
flex: 1 0 100px;
flex: 1 0 400px;
}
.sidebar-closed {
......
......@@ -52,7 +52,7 @@
}
.layout-card-container {
height: calc(100% - 86px);
height: calc(100% - 70px);
overflow-y: auto;
overflow-x: hidden;
}
......
......@@ -167,12 +167,12 @@ const getActiveEntry = schedule => {
ex. start day is Sunday (6), end day is Monday (0)
*/
if ((scheduleEntry.start_day <= scheduleEntry.end_day &&
dayOfWeek >= scheduleEntry.start_day &&
dayOfWeek <= scheduleEntry.end_day) ||
(dayOfWeek >= scheduleEntry.start_day &&
dayOfWeek <= scheduleEntry.end_day)) ||
(scheduleEntry.start_day > scheduleEntry.end_day &&
dayOfWeek >= scheduleEntry.start_day ||
dayOfWeek <= scheduleEntry.end_day)
(dayOfWeek >= scheduleEntry.start_day ||
dayOfWeek <= scheduleEntry.end_day))
) {
if (scheduleEntry.start_day === scheduleEntry.end_day) {
......@@ -219,12 +219,12 @@ const getEntryByDay = (schedule, dayOfWeek) => {
const endDay = entry.end_day;
if ((startDay <= endDay &&
dayOfWeek >= startDay &&
dayOfWeek <= endDay) ||
(dayOfWeek >= startDay &&
dayOfWeek <= endDay)) ||
(startDay > endDay &&
dayOfWeek >= startDay ||
dayOfWeek <= endDay)
(dayOfWeek >= startDay ||
dayOfWeek <= endDay))
) {
return entry;
}
......@@ -233,21 +233,73 @@ const getEntryByDay = (schedule, dayOfWeek) => {
return null;
};
/**
* Determines an array of entires based on the day of the week.
*
* @param schedule A schedule.
* @param dayOfWeek The day of the week
* @returns {*} an array of entries that are active on the given day of the week
*/
const getEntriesByDay = (schedule, dayOfWeek) => {
const openTimes = schedule.open_times;
let entries = []
for (let i = 0; i < openTimes.length; i++) {
const entry = openTimes[i];
const startDay = entry.start_day;
const endDay = entry.end_day;
if ((startDay <= endDay &&
(dayOfWeek >= startDay &&
dayOfWeek <= endDay)) ||
(startDay > endDay &&
(dayOfWeek >= startDay ||
dayOfWeek <= endDay))
) {
// console.log(entry)
entries.push(entry)
}
}
// if(entries.length === 0){
// return null;
// }
return entries;
};
const getHoursByDay = (facility, dayOfWeek) => {
const schedule = getFacilityActiveSchedule(facility);
if (schedule.twenty_four_hours) {
return 'All Day';
return [{text:'All Day',
start:0,
end:0,
allDayOrClosed:true}]
}
const entry = getEntryByDay(schedule, dayOfWeek);
if (entry === null) {
return 'Closed';
const entries = getEntriesByDay(schedule, dayOfWeek);
if (entries.length === 0) {
return [{text:'Closed',
start:0,
end:0,
allDayOrClosed:true}];
}
return convertToMeridiemTime(entry.start_time) + ' - ' + convertToMeridiemTime(entry.end_time);
let hours = [];
for(let i = 0; i < entries.length; i++){
hours.push({
text:convertToMeridienTime(entries[i].start_time) + ' - ' + convertToMeridienTime(entries[i].end_time),
start:entries[i].start_time,
end:entries[i].end_time,
allDayOrClosed:false
})
}
return hours.sort((a,b) => {
return parseInt(a.start) - parseInt(b.start)
})
};
......@@ -258,7 +310,7 @@ const getHoursByDay = (facility, dayOfWeek) => {
* @param time The time as military time
* @returns {string} The time as 12-hour time.
*/
const convertToMeridiemTime = (time) => {
const convertToMeridienTime = (time) => {
const timeArr = time
.split(":")
.map((item) => {
......@@ -301,6 +353,7 @@ const daysTill = (dayFrom, dayTo) => {
export default {
getFacilityActiveSchedule: getFacilityActiveSchedule,
isFacilityOpen: isFacilityOpen,
getEntriesByDay:getEntriesByDay,
getHoursByDay: getHoursByDay,
calcTimeTillOpen: calcTimeTillOpen,
calcTimeTillClose: calcTimeTillClose
......
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