Commit 3346e09a authored by mdsecurity's avatar mdsecurity
Browse files

openFor and isOpen methods now take into account special schedules

parent d4b3f299
......@@ -88,27 +88,27 @@ export class DataProviderService {
}
for (let e = 0; e < data[i].special_schedules.length; e++) {
const jsonSchedule = data[i].special_schedules[e];
let open_times:Day[] = [];
for(let f = 0; f < jsonSchedule.open_times.length;f++){
let open_times: Day[] = [];
for (let f = 0; f < jsonSchedule.open_times.length; f++) {
let jsonDay = jsonSchedule.open_times[f];
const day = new Day(
jsonDay.id,
jsonDay.last_modified,
jsonDay.schedule,
jsonDay.start_day,
parseTime(jsonDay.start_time),
jsonDay.end_day,
parseTime(jsonDay.end_time));
jsonDay.id,
jsonDay.last_modified,
jsonDay.schedule,
jsonDay.start_day,
parseTime(jsonDay.start_time),
jsonDay.end_day,
parseTime(jsonDay.end_time));
open_times.push(Object.freeze(day));
}
const schedule = new SpecialSchedule(jsonSchedule.valid_start,jsonSchedule.valid_end,open_times);
const schedule = new SpecialSchedule(jsonSchedule.valid_start, jsonSchedule.valid_end, open_times);
special_schedules.push(Object.freeze(schedule));
}
console.log(special_schedules);
places.push(new Place(
main_schedule_times,
[],
special_schedules,
data[i].id,
data[i].last_modified,
data[i].name,
......
......@@ -10,7 +10,7 @@ export class Place {
name: string;
category: number;
location: string;
constructor(main_schedule_times?: Day[], special_schedules?:SpecialSchedule[], id?: number, last_modified?: string,
constructor(main_schedule_times?: Day[], special_schedules?: SpecialSchedule[], id?: number, last_modified?: string,
name?: string, category?: number, location?: string) {
this.main_schedule_times = main_schedule_times || [];
......@@ -26,8 +26,14 @@ export class Place {
const currTime = new Date();
const inSeconds = currTime.getHours() * 60 * 60 + currTime.getMinutes() * 60 + currTime.getSeconds();
const dayOfWeek = currTime.getDay() - 1;
for (let i = 0; i < this.main_schedule_times.length; i++) {
const useSpecialSchedule = this.useSpecial();
let schedule;
if(useSpecialSchedule === -1){
schedule = this.main_schedule_times;
}else{
schedule = this.special_schedules[useSpecialSchedule].openTimes;
}
for (let i = 0; i < schedule.length; i++) {
const day = this.main_schedule_times[i];
// change the order of if statements at some point
if (day.start_day !== day.end_day) {
......@@ -76,6 +82,21 @@ export class Place {
return timeTilClose;
}
}
useSpecial(): number {
const todaysDate = new Date();
for (let i = 0; i < this.special_schedules.length; i++) {
let parsedStart = this.special_schedules[i].validStart.split('-');
let parsedEnd = this.special_schedules[i].validEnd.split('-');
if (todaysDate.getFullYear() >= Number(parsedStart[0]) && todaysDate.getFullYear() <= Number(parsedEnd[0])) {
if (todaysDate.getMonth() >= Number(parsedStart[1]) && todaysDate.getMonth() <= Number(parsedEnd[1])) {
if (todaysDate.getDate() >= Number(parsedStart[2]) && todaysDate.getDate() <= Number(parsedEnd[2])) {
return i;
}
}
}
}
return -1;
}
}
// useSpecial():
......@@ -3,13 +3,13 @@ import { Time } from './time';
export class SpecialSchedule {
open_times: Day[];
valid_start: string;
valid_end: string;
openTimes: Day[];
validStart: string;
validEnd: string;
constructor(valid_start:string,valid_end:string,open_times?: Day[]){
this.open_times = open_times || [];
this.valid_end = valid_end;
this.valid_start = valid_start;
this.openTimes = open_times || [];
this.validEnd = valid_end;
this.validStart = valid_start;
}
}
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