2021-04-26 23:13:59 +02:00
|
|
|
import dayjs from 'dayjs'
|
2021-03-10 16:09:35 +01:00
|
|
|
|
2022-09-05 15:28:00 +02:00
|
|
|
export function attributesFromEvents(_events) {
|
2022-05-31 15:14:54 +02:00
|
|
|
// merge events with same date
|
2021-03-10 16:09:35 +01:00
|
|
|
let attributes = []
|
2021-04-26 23:13:59 +02:00
|
|
|
const now = dayjs().unix()
|
2022-09-05 15:28:00 +02:00
|
|
|
for (let e of _events) {
|
2022-09-22 09:20:32 +02:00
|
|
|
const key = dayjs.unix(e.start_datetime).tz().format('MMDD') // Math.floor(e.start_datetime/(3600*24)) // dayjs.unix(e.start_datetime).tz().format('YYYYMMDD')
|
2022-09-05 15:28:00 +02:00
|
|
|
const c = (e.end_datetime || e.start_datetime) < now ? 'vc-past' : ''
|
|
|
|
|
|
|
|
if (e.multidate) {
|
|
|
|
attributes.push({
|
|
|
|
dates: { start: new Date(e.start_datetime * 1000), end: new Date(e.end_datetime * 1000) },
|
|
|
|
highlight: {
|
|
|
|
start: { fillMode: 'outline' },
|
|
|
|
base: { fillMode: 'light' },
|
|
|
|
end: { fillMode: 'outline' },
|
|
|
|
}
|
|
|
|
})
|
|
|
|
continue
|
|
|
|
}
|
2021-03-10 16:09:35 +01:00
|
|
|
|
2022-05-31 15:14:54 +02:00
|
|
|
const i = attributes.find(a => a.day === key)
|
|
|
|
if (!i) {
|
2022-09-05 15:28:00 +02:00
|
|
|
attributes.push({
|
|
|
|
day: key, key: e.id, n: 1, dates: new Date(e.start_datetime * 1000),
|
|
|
|
dot: { color: 'teal', class: c }
|
|
|
|
})
|
2022-05-31 15:14:54 +02:00
|
|
|
continue
|
2021-05-08 11:34:12 +02:00
|
|
|
}
|
2021-03-10 16:09:35 +01:00
|
|
|
|
2022-05-31 15:14:54 +02:00
|
|
|
i.n++
|
2022-09-05 15:28:00 +02:00
|
|
|
if (i.n >= 20) {
|
2022-05-31 15:14:54 +02:00
|
|
|
i.dot = { color: 'purple', class: c }
|
2022-09-05 15:28:00 +02:00
|
|
|
} else if (i.n >= 10) {
|
|
|
|
i.dot = { color: 'red', class: c }
|
|
|
|
} else if (i.n >= 5) {
|
|
|
|
i.dot = { color: 'orange', class: c }
|
|
|
|
} else if (i.n >= 3) {
|
|
|
|
i.dot = { color: 'yellow', class: c }
|
2022-05-31 15:14:54 +02:00
|
|
|
} else {
|
|
|
|
i.dot = { color: 'teal', class: c }
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-03-10 16:09:35 +01:00
|
|
|
|
2022-05-31 15:14:54 +02:00
|
|
|
// add a bar to highlight today
|
|
|
|
attributes.push({ key: 'today', dates: new Date(), highlight: { color: 'green', fillMode: 'outline' } })
|
2021-03-10 16:09:35 +01:00
|
|
|
|
|
|
|
return attributes
|
|
|
|
}
|