2019-04-03 00:25:12 +02:00
|
|
|
import Vue from 'vue'
|
2020-10-16 14:46:45 +02:00
|
|
|
import dayjs from 'dayjs'
|
|
|
|
import relativeTime from 'dayjs/plugin/relativeTime'
|
|
|
|
import utc from 'dayjs/plugin/utc'
|
|
|
|
import timezone from 'dayjs/plugin/timezone'
|
2022-02-24 10:20:40 +01:00
|
|
|
import localizedFormat from 'dayjs/plugin/localizedFormat'
|
|
|
|
|
2020-10-16 14:46:45 +02:00
|
|
|
|
2020-10-25 00:33:03 +02:00
|
|
|
import 'dayjs/locale/it'
|
2022-04-27 11:58:58 +02:00
|
|
|
import 'dayjs/locale/en'
|
2020-10-25 00:33:03 +02:00
|
|
|
import 'dayjs/locale/es'
|
|
|
|
import 'dayjs/locale/ca'
|
|
|
|
import 'dayjs/locale/pl'
|
|
|
|
import 'dayjs/locale/eu'
|
|
|
|
import 'dayjs/locale/nb'
|
|
|
|
import 'dayjs/locale/fr'
|
2022-04-27 11:58:58 +02:00
|
|
|
import 'dayjs/locale/de'
|
|
|
|
import 'dayjs/locale/gl'
|
2020-10-25 00:33:03 +02:00
|
|
|
|
2020-10-16 14:46:45 +02:00
|
|
|
dayjs.extend(relativeTime)
|
|
|
|
dayjs.extend(utc)
|
|
|
|
dayjs.extend(timezone)
|
2022-02-24 10:20:40 +01:00
|
|
|
dayjs.extend(localizedFormat)
|
2019-04-03 00:25:12 +02:00
|
|
|
|
2019-06-25 01:05:38 +02:00
|
|
|
export default ({ app, store }) => {
|
2019-10-20 14:22:55 +02:00
|
|
|
// set timezone to instance_timezone!!
|
|
|
|
// to show local time relative to event's place
|
2020-02-09 18:15:44 +01:00
|
|
|
// not where in the world I'm looking at the page from
|
2022-04-27 11:58:58 +02:00
|
|
|
const instance_timezone = store.state.settings.instance_timezone
|
|
|
|
const locale = store.state.locale
|
|
|
|
dayjs.tz.setDefault(instance_timezone)
|
|
|
|
dayjs.locale(locale)
|
2019-10-20 14:22:55 +02:00
|
|
|
|
2019-07-23 01:31:43 +02:00
|
|
|
// replace links with anchors
|
2020-02-09 18:15:44 +01:00
|
|
|
// TODO: remove fb tracking id?
|
2019-10-20 14:22:55 +02:00
|
|
|
Vue.filter('linkify', value => value.replace(/(https?:\/\/([^\s]+))/g, '<a href="$1">$2</a>'))
|
2019-08-02 13:43:28 +02:00
|
|
|
Vue.filter('url2host', url => url.match(/^https?:\/\/(.[^/:]+)/i)[1])
|
2022-04-27 11:58:58 +02:00
|
|
|
Vue.filter('datetime', value => dayjs.tz(value).locale(locale).format('ddd, D MMMM HH:mm'))
|
|
|
|
Vue.filter('dateFormat', (value, format) => dayjs.tz(value).format(format))
|
|
|
|
Vue.filter('unixFormat', (timestamp, format) => dayjs.unix(timestamp).tz(instance_timezone).format(format))
|
2019-07-23 01:31:43 +02:00
|
|
|
|
|
|
|
// shown in mobile homepage
|
2022-04-27 11:58:58 +02:00
|
|
|
Vue.filter('day', value => dayjs.unix(value).tz(instance_timezone).locale(store.state.locale).format('dddd, D MMM'))
|
|
|
|
Vue.filter('mediaURL', (event, type, format = '.jpg') => {
|
2021-07-15 16:18:56 +02:00
|
|
|
if (event.media && event.media.length) {
|
|
|
|
if (type === 'alt') {
|
|
|
|
return event.media[0].name
|
|
|
|
} else {
|
2022-04-27 11:58:58 +02:00
|
|
|
return store.state.settings.baseurl + '/media/' + (type === 'thumb' ? 'thumb/' : '') + event.media[0].url.replace(/.jpg$/, format)
|
2021-07-15 16:18:56 +02:00
|
|
|
}
|
|
|
|
} else if (type !== 'alt') {
|
|
|
|
return store.state.settings.baseurl + '/media/' + (type === 'thumb' ? 'thumb/' : '') + 'logo.svg'
|
|
|
|
}
|
|
|
|
return ''
|
|
|
|
})
|
2019-07-23 01:31:43 +02:00
|
|
|
|
2022-04-27 11:58:58 +02:00
|
|
|
Vue.filter('from', timestamp => dayjs.unix(timestamp).tz(instance_timezone).fromNow())
|
2020-02-11 11:53:32 +01:00
|
|
|
|
2020-02-11 15:39:57 +01:00
|
|
|
Vue.filter('recurrentDetail', event => {
|
2020-11-17 00:34:56 +01:00
|
|
|
const parent = event.parent
|
2021-01-11 00:17:56 +01:00
|
|
|
const { frequency, type } = parent.recurrent
|
2020-02-11 15:39:57 +01:00
|
|
|
let recurrent
|
|
|
|
if (frequency === '1w' || frequency === '2w') {
|
2022-04-27 11:58:58 +02:00
|
|
|
recurrent = app.i18n.t(`event.recurrent_${frequency}_days`, { days: dayjs.unix(parent.start_datetime).tz(instance_timezone).format('dddd') })
|
2020-02-11 15:39:57 +01:00
|
|
|
} else if (frequency === '1m' || frequency === '2m') {
|
2022-04-27 11:58:58 +02:00
|
|
|
const d = type === 'ordinal' ? dayjs.unix(parent.start_datetime).date() : dayjs.unix(parent.start_datetime).tz(instance_timezone).format('dddd')
|
2021-05-11 15:12:49 +02:00
|
|
|
if (type === 'ordinal') {
|
|
|
|
recurrent = app.i18n.t(`event.recurrent_${frequency}_days`, { days: d })
|
|
|
|
} else {
|
|
|
|
recurrent = app.i18n.t(`event.recurrent_${frequency}_ordinal`,
|
|
|
|
{ n: app.i18n.t('ordinal.' + type), days: d })
|
|
|
|
}
|
2020-02-11 15:39:57 +01:00
|
|
|
}
|
|
|
|
return recurrent
|
|
|
|
})
|
2020-03-24 18:50:32 +01:00
|
|
|
|
2020-02-11 11:53:32 +01:00
|
|
|
Vue.filter('when', (event) => {
|
2022-04-27 11:58:58 +02:00
|
|
|
const start = dayjs.unix(event.start_datetime).tz(instance_timezone)
|
|
|
|
const end = dayjs.unix(event.end_datetime).tz(instance_timezone)
|
2019-10-28 17:33:20 +01:00
|
|
|
|
2020-02-11 11:53:32 +01:00
|
|
|
// const normal = `${start.format('dddd, D MMMM (HH:mm-')}${end.format('HH:mm) ')}`
|
|
|
|
// // recurrent event
|
|
|
|
// if (event.parent && where !== 'home') {
|
|
|
|
// const { frequency, days, type } = event.parent.recurrent
|
|
|
|
// if (frequency === '1w' || frequency === '2w') {
|
2020-10-16 14:46:45 +02:00
|
|
|
// const recurrent = app.i18n.tc(`event.recurrent_${frequency}_days`, days.length, { days: days.map(d => dayjs().day(d - 1).format('dddd')) })
|
2020-02-11 11:53:32 +01:00
|
|
|
// return `${normal} - ${recurrent}`
|
|
|
|
// } else if (frequency === '1m' || frequency === '2m') {
|
2020-10-16 14:46:45 +02:00
|
|
|
// const d = type === 'ordinal' ? days : days.map(d => dayjs().day(d - 1).format('dddd'))
|
2020-02-11 11:53:32 +01:00
|
|
|
// const recurrent = app.i18n.tc(`event.recurrent_${frequency}_${type}`, days.length, { days: d })
|
|
|
|
// return `${normal} - ${recurrent}`
|
|
|
|
// }
|
|
|
|
// return 'recurrent '
|
|
|
|
// }
|
2019-07-23 01:31:43 +02:00
|
|
|
|
|
|
|
// multidate
|
2019-05-30 12:04:14 +02:00
|
|
|
if (event.multidate) {
|
2021-01-22 21:16:22 +01:00
|
|
|
return `${start.format('ddd, D MMM HH:mm')} - ${end.format('ddd, D MMM')}`
|
2019-09-11 19:12:24 +02:00
|
|
|
}
|
2019-07-23 01:31:43 +02:00
|
|
|
|
|
|
|
// normal event
|
2020-02-11 11:53:32 +01:00
|
|
|
return start.format('ddd, D MMMM HH:mm')
|
2019-05-30 12:04:14 +02:00
|
|
|
})
|
2019-06-07 17:02:33 +02:00
|
|
|
}
|