place.ts 1.8 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 {
5
6
    main_schedule_times: Day[] = [];
    special_schedule_times = [];
mdsecurity's avatar
mdsecurity committed
7
8
9
10
11
12
13
14
    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) {

15
16
17
18
        this.main_schedule_times = main_schedule_times;
        this.special_schedule_times = special_schedule_times;
        this.id = id;
        this.last_modified = last_modified;
mdsecurity's avatar
mdsecurity committed
19
        this.name = name;
20
        this.category = category;
21
        this.location = location;
22
    }
23
    // This method does NOT work with Special schedules
mdsecurity's avatar
mdsecurity committed
24
    isOpen(): boolean {
25
        const currTime = new Date();
mdsecurity's avatar
mdsecurity committed
26
27
28
29
30
31
32
33
34
        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 day = this.main_schedule_times[i];
            if (day.start_day === dayOfWeek || day.end_day === dayOfWeek + 1) {
                if (day.end_time.inSeconds() > inSeconds) {
                    return true;
                }
35
36
37
38
            }
        }
        return false;
    }
mdsecurity's avatar
mdsecurity committed
39
    openFor() {
40
        const currTime = new Date();
mdsecurity's avatar
mdsecurity committed
41
42
43
44
45
46
47
48
49
50
        // const today = currTime.getDay() - 1;
        // const openDays: Day[] = this.onDay(today);
        // const inSeconds = currTime.getHours() * 60 * 60 + currTime.getMinutes() * 60 + currTime.getSeconds();

        // 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
51

52
    }
mdsecurity's avatar
mdsecurity committed
53
54
}