-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathEventsForDay.ts
More file actions
76 lines (72 loc) · 2.89 KB
/
EventsForDay.ts
File metadata and controls
76 lines (72 loc) · 2.89 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import * as dto from './dto';
import * as list from './list';
import * as moment from 'moment';
import Event from './Event'
import UiComponent from './UiComponent';
import ComponentsArray from './ComponentsArray';
import DayOff from './DayOff';
// TODO(#69): EventsForDay can be a concatenation of RecurringEventsForDay and ScheduledEventsForDay objects
export default class EventsForDay implements UiComponent {
constructor(private _state: dto.State,
private _date: string) {
}
appendTo(entry: HTMLElement | null): void {
const events = this._asArray();
if (events.length > 0) {
new ComponentsArray(events).appendTo(entry);
} else {
new DayOff(this._state, this._date).appendTo(entry);
}
}
_asArray(): Array<Event> {
let weekday = moment.tz(this._date, this._state.timezone).isoWeekday();
return !this._state.projects ? [] : this._state.projects
.filter(
(p) => {
let thisDate = moment.tz(`${this._date}`, this._state.timezone).utc().unix();
let starts = p.starts ? moment.tz(`${p.starts}`, this._state.timezone).utc().unix() : 0;
let ends = p.ends ? moment.tz(`${p.ends}`, this._state.timezone).utc().unix() : Number.MAX_SAFE_INTEGER;
return starts <= thisDate && thisDate <= ends;
}
)
.filter(
(p) => p.days.includes(weekday)
)
.map(
(p) => {
return {
datetime: moment.tz(`${this._date} ${p.time}`, this._state.timezone).utc(),
title: p.name,
description: p.description,
url: p.url,
channel: p.channel,
};
}
)
.concat(
!this._state.extraEvents ? [] : this._state.extraEvents
.filter(
(ee) => ee.date == this._date
)
.map(
(ee) => {
return {
datetime: moment.tz(`${this._date} ${ee.time}`, this._state.timezone).utc(),
title: ee.title,
description: ee.description,
url: ee.url,
channel: ee.channel,
};
}
)
)
.map(
(e) => new Event(
this._state.eventPatches
? new dto.PatchedEvent(e as dto.Event, this._state.eventPatches[e.datetime.utc().unix()])
: e as dto.Event,
this._state.cancelledEvents
)
)
}
}