Commit 4ec4d92c authored by mdsecurity's avatar mdsecurity
Browse files

fixing openFor method so it works with Food Trucks

parent 7e154b7c
......@@ -7,12 +7,15 @@ import { Place } from '../../Place';
styleUrls: ['./area.component.scss']
})
export class AreaComponent implements OnInit {
private places: Place[] = []
private places: Place[] = [];
private placee:Place = new Place();
constructor(private dataProvider: DataProviderService) { }
ngOnInit() {
this.dataProvider.getFacilities().subscribe(
(places) => { this.places = places;},
(places) => { this.places = places;
this.placee = places[2];
console.log(places[2]);},
(error) => { console.log(error); }
)
}
......
......@@ -24,12 +24,13 @@
</div>
</div>
<ng-template #elseBlock>
<div class="closed-shader"></div>
hello
<!--<div class="closed-shader"></div>
<div class="place-open-badge" style="width:102px;background-color:#C4B9B9;">
<div class="place-status">CLOSED</div>
<div class="place-divider"></div>
<div class="place-time-remaining">~{{place.openFor().hour}}Hrs</div>
</div>
</div>-->
</ng-template>
<div class="place-location">{{place.location }}</div>
......
......@@ -14,18 +14,18 @@ import {DomSanitizer} from '@angular/platform-browser';
export class PlaceCardComponent implements OnInit {
@Input() private place: Place;
private status: string;
private show;
private week: string[] = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"];
private url;
constructor(private dataProvider: DataProviderService, public dialog: MdDialog,private sanitizer: DomSanitizer) { }
ngOnInit() {
this.url = this.sanitizer.bypassSecurityTrustUrl('https://unsplash.it/200/300?image='+Math.floor((Math.random()*999+1)));
}
openInContext() {
this.dataProvider.setContext(this.place);
// console.log(this.place.openFor().hour+ " "+ this.place.openFor().minute+ " "+ this.place.openFor().second)
console.log(this.place);
// console.log(this.place);
}
openDialog() {
let dialogRef = this.dialog.open(FeedbackDialogComponent);
......
......@@ -25,7 +25,7 @@ export class Place {
isOpen(): boolean {
const currTime = new Date();
const inSeconds = currTime.getHours() * 60 * 60 + currTime.getMinutes() * 60 + currTime.getSeconds();
const dayOfWeekShift = [6, 5, 4, 3, 2, 1, 0];
const dayOfWeekShift = [6, 0, 1, 2, 3, 4, 5];
const dayOfWeek = dayOfWeekShift[currTime.getDay()];
const useSpecialSchedule = this.useSpecial();
let schedule;
......@@ -34,36 +34,61 @@ export class Place {
} else {
schedule = this.special_schedules[useSpecialSchedule].openTimes;
}
// for (let i = 0; i < schedule.length; i++) {
// const day = schedule[i];
// // change the order of if statements at some point
// if (day.start_day !== day.end_day) {
// if (day.end_day === dayOfWeek) {
// if (day.end_time.inSeconds() > inSeconds) {
// return true;
// }
// } else if (day.start_day === dayOfWeek) {
// return true;
// }
// } else {
// if (day.start_day === dayOfWeek) {
// if (day.end_time.inSeconds() > inSeconds) {
// return true;
// }
// }
// }
// }
for (let i = 0; i < schedule.length; i++) {
const day = schedule[i];
// change the order of if statements at some point
if (day.start_day !== day.end_day) {
if (day.end_day === dayOfWeek) {
if (day.end_time.inSeconds() > inSeconds) {
if ((dayOfWeek === day.start_day || dayOfWeek === day.end_day) && day.start_day === day.end_day) {
if (inSeconds >= day.start_time.inSeconds()) {
if (inSeconds <= day.end_time.inSeconds()) {
return true;
}
} else if (day.start_day === dayOfWeek) {
return true;
return false;
}
} else {
if (day.start_day === dayOfWeek) {
if (day.end_time.inSeconds() > inSeconds) {
return false;
} else if (dayOfWeek >= day.start_day && dayOfWeek <= day.end_day) {
if (dayOfWeek === day.start_day) {
if (inSeconds >= day.start_time.inSeconds()) {
return true;
}
return false;
} else if (dayOfWeek === day.end_day) {
if (inSeconds >= day.end_time.inSeconds()) {
return false;
}
return true;
} else {
return true;
}
}
}
console.log('false');
return false;
}
openFor(): Time {
openFor(): any {
const currTime = new Date();
const today = currTime.getDay() - 1;
const inSeconds = currTime.getHours() * 60 * 60 + currTime.getMinutes() * 60 + currTime.getSeconds();
const dayOfWeekShift = [6, 5, 4, 3, 2, 1, 0];
const dayOfWeekShift = [6, 0, 1, 2, 3, 4, 5];
const dayOfWeek = dayOfWeekShift[currTime.getDay()];
const useSpecialSchedule = this.useSpecial();
let timeTilClose = new Time();
let sumSeconds = 0;
......@@ -73,25 +98,59 @@ export class Place {
} else {
schedule = this.special_schedules[useSpecialSchedule].openTimes;
}
// clean up if statements later
// if (this.isOpen()) {
for (let i = 0; i < schedule.length; i++) {
const day = schedule[i];
if (day.end_day !== day.start_day) {
if (dayOfWeek === day.end_day) {
sumSeconds = day.end_time.inSeconds() - inSeconds - 86400;
} else if (dayOfWeek === day.start_day) {
sumSeconds = day.end_time.inSeconds() + 86400 - inSeconds;
// for (let i = 0; i < schedule.length; i++) {
// const day = schedule[i];
// if (day.end_day !== day.start_day) {
// if (dayOfWeek === day.end_day) {
// sumSeconds = day.end_time.inSeconds() - inSeconds - 86400;
// } else if (dayOfWeek === day.start_day) {
// sumSeconds = day.end_time.inSeconds() + 86400 - inSeconds;
// }
// } else {
// sumSeconds = day.end_time.inSeconds() - inSeconds;
// }
// return timeTilClose.fromSeconds(sumSeconds);
// }
for (let i = 0; i < schedule.length; i++) {
const day = schedule[i];
if ((dayOfWeek === day.start_day || dayOfWeek === day.end_day) && day.start_day === day.end_day) {
if (inSeconds >= day.start_time.inSeconds()) {
if (inSeconds <= day.end_time.inSeconds()) {
sumSeconds = day.end_time.inSeconds() - inSeconds;
} else {
//not done
sumSeconds = 86400 - inSeconds;
}
} else {
sumSeconds = day.end_time.inSeconds() - inSeconds;
sumSeconds = day.start_time.inSeconds() - inSeconds;
}
// console.log(sumSeconds);
return timeTilClose.fromSeconds(sumSeconds);
} else if (dayOfWeek >= day.start_day && dayOfWeek <= day.end_day) {
if (dayOfWeek === day.start_day) {
if (inSeconds >= day.start_time.inSeconds()) {
sumSeconds = 86400 - inSeconds + (86400 * (day.end_day - day.start_day - 1)) + day.end_time.inSeconds();
} else {
sumSeconds = day.start_time.inSeconds() - inSeconds;
}
} else if (dayOfWeek === day.end_day) {
if (inSeconds >= day.end_time.inSeconds()) {
//not done
sumSeconds = 86400 - inSeconds;
} else {
sumSeconds = day.end_time.inSeconds() - inSeconds;
}
} else {
sumSeconds = 86400 - inSeconds + (86400 * (day.end_day - dayOfWeek - 2)) + day.end_time.inSeconds();
}
// console.log(sumSeconds);
return timeTilClose.fromSeconds(sumSeconds);
}
// } else {
return timeTilClose;
// }
}
return { "hour": "closed" };
}
useSpecial(): number {
......
......@@ -4,7 +4,7 @@ export class Time {
second: number;
constructor(hour?: number, minute?: number, second?: number) {
this.hour = hour || 1;
this.hour = hour || 0;
this.minute = minute || 0;
this.second = second || 0;
}
......
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