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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
import { TZDate } from "@date-fns/tz";
import { defineStore } from "pinia";
interface Schedule {
conference: Conference;
tracks: Track[];
days: Day[];
}
interface Conference {
title: string;
venue: string;
city: string;
start: Date;
end: Date;
days: number;
dayChange: string;
timeslotDuration: string;
baseUrl: string;
timeZoneName: string;
}
interface Track {
name: string;
slug: string;
}
interface Day {
date: string;
start: Date;
end: Date;
rooms: Room[];
}
interface Room {
name: string;
events: Event[];
}
export interface Event {
id: number;
guid: string;
date: string;
start: Date;
end: Date;
duration: string;
room: string;
url: string;
track: Track;
type: string;
title: string;
abstract: string;
persons: Person[];
attachments: Attachment[];
links: Link[];
}
interface Person {
id: number;
name: string;
}
interface Attachment {
type: string;
href: string;
name: string;
}
interface Link {
href: string;
name: string;
}
export const useScheduleStore = defineStore('schedule', () => {
const schedule = ref(null as Schedule | null)
const events = ref([] as Event[])
const eventsPerDay = ref({} as { [key: string]: Event[] })
const eventsPerTrack = ref({} as { [key: string]: Event[] })
const tracks = ref({} as { [key: string]: Track })
const setSchedule = (newSchedule: Schedule) => {
tracks.value = {}
newSchedule.tracks.forEach(track => {
track.slug = convertToSlug(track.name)
tracks.value[track.name] = track
});
events.value = []
newSchedule.days.forEach(day => {
day.start = new TZDate(day.start, newSchedule.conference.timeZoneName)
day.end = new TZDate(day.end, newSchedule.conference.timeZoneName)
day.rooms.forEach(room => {
room.events.forEach(event => {
normalizeDates(event, newSchedule.conference.timeZoneName)
events.value.push(event)
event.track = tracks.value[event.track as unknown as string]
})
})
})
events.value.sort((a, b) => {
return a.start.getTime() - b.start.getTime()
})
schedule.value = newSchedule
eventsPerDay.value = {}
events.value.forEach(event => {
const date = event.date.split('T')[0]
if (!eventsPerDay.value[date]) {
eventsPerDay.value[date] = []
}
eventsPerDay.value[date].push(event)
})
eventsPerTrack.value = {}
events.value.forEach(event => {
if (!eventsPerTrack.value[event.track.name]) {
eventsPerTrack.value[event.track.name] = []
}
eventsPerTrack.value[event.track.name].push(event)
});
}
const isConferenceOngoing = () => {
if (!schedule.value) {
return false
}
return new Date() >= schedule.value.conference.start && new Date() < schedule.value.conference.end
}
const isConferenceFinished = () => {
if (!schedule.value) {
return false
}
return new Date() > schedule.value.conference.end
}
const getStartDate = () => {
return schedule.value?.conference.start || 0
}
return {schedule, events, eventsPerDay, eventsPerTrack, setSchedule, isConferenceOngoing, isConferenceFinished, getStartDate}
})
function normalizeDates(event: Event, timeZone: string) {
event.start = new TZDate(event.start, timeZone)
event.end = new TZDate(event.end, timeZone)
}
function parseDuration(duration: string) {
const [hours, minutes] = duration.split(':').map(Number)
return hours * 60 * 60 * 1000 + minutes * 60 * 1000
}
function convertToSlug(text: string) {
return text
.toLowerCase()
.replace(/ /g, '-')
.replace(/[^\w-]+/g, '')
}
|