aboutsummaryrefslogtreecommitdiff
path: root/src/models/EventInfo.js
blob: c1624a8b1e1627336f4b400160b9ba0ef7b961f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
export default class EventInfo {
  constructor(days = '', start = 0, end = 0) {
    this.days = days;
    this.start = start;
    this.end = end;
  }

  static timeToStr(time) {
    let hour = Math.floor(time / 100);
    let minute = time % 100;
    const meridiem = (hour < 12) ? 'AM' : 'PM';

    if (hour === 0) {
      hour = 12;
    } else if (hour > 12) {
      hour -= 12;
    }

    if (minute < 10) {
      minute = `0${minute}`;
    }

    return `${hour}:${minute} ${meridiem}`;
  }

  conflictsWith(event) {
    const daysConflict = event.days.match(new RegExp(`[${this.days}]`));

    if (daysConflict) {
      return (this.start <= event.end) && (event.start <= this.end);
    }
    return false;
  }

  get info() {
    if (this.days === '') {
      return 'ONLINE';
    }
    return `${this.days} ${EventInfo.timeToStr(this.start)}-${EventInfo.timeToStr(this.end)}`;
  }
}