place.ts 1.67 KB
Newer Older
1
import { Day } from './day';
mdsecurity's avatar
mdsecurity committed
2
3
import { Time } from './time';

mdsecurity's avatar
mdsecurity committed
4
export class Place {
mdsecurity's avatar
mdsecurity committed
5
6
7
8
9
10
11
12
13
	main_schedule_times: Day[] = [];
	special_schedule_times = [];
	id: number;
	last_modified: string;
	name: string;
	category: number;
	location: string;
	constructor(main_schedule_times: Day[], special_schedule_times, id: number, last_modified: string,
		name: string, category: number, location: string) {
mdsecurity's avatar
mdsecurity committed
14

mdsecurity's avatar
mdsecurity committed
15
16
17
18
19
20
21
22
23
24
25
26
27
		this.main_schedule_times = main_schedule_times;
		this.special_schedule_times = special_schedule_times;
		this.id = id;
		this.last_modified = last_modified;
		this.name = name;
		this.category = category;
		this.location = location;
	}
	// This method does NOT work with Special schedules
	isOpen(): boolean {
		const currTime = new Date();
		const inSeconds = currTime.getHours() * 60 * 60 + currTime.getMinutes() * 60 + currTime.getSeconds();
		const dayOfWeek = currTime.getDay() - 1;
mdsecurity's avatar
mdsecurity committed
28

mdsecurity's avatar
mdsecurity committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
		for (let i = 0; i < this.main_schedule_times.length; i++) {
			const day = this.main_schedule_times[i];
			if (day.start_day === dayOfWeek && day.end_day === dayOfWeek) {
				if (day.end_time.inSeconds() > inSeconds) {
					return true;
				}
			}
			if (day.end_day === dayOfWeek) {
				if (day.end_time.inSeconds() > inSeconds) {
					return true;
				}
			}
		}
		return false;
	}
	openFor() {
		const currTime = new Date();
		// const today = currTime.getDay() - 1;
		// const openDays: Day[] = this.onDay(today);
		// const inSeconds = currTime.getHours() * 60 * 60 + currTime.getMinutes() * 60 + currTime.getSeconds();
mdsecurity's avatar
mdsecurity committed
49

mdsecurity's avatar
mdsecurity committed
50
51
52
53
54
		// let sumSeconds = 0;
		// for (let i = 0; i < openDays.length; i++) {
		//     let day = openDays[i];
		//     sumSeconds += day.end_time.inSeconds() - day.end_time.inSeconds();
		// }
mdsecurity's avatar
mdsecurity committed
55

mdsecurity's avatar
mdsecurity committed
56

mdsecurity's avatar
mdsecurity committed
57
	}
mdsecurity's avatar
mdsecurity committed
58
59
}