fix: display timezone name in some representation (fix #349):

- in web UI for online events and events coming from fedi
- in webcomponent / embedded calendar for online events and events coming from fedi
- in AP event's summary
This commit is contained in:
lesion 2024-08-17 18:53:12 +02:00
parent 31b6e33178
commit 0d581cec69
No known key found for this signature in database
GPG key ID: 352918250B012177
3 changed files with 11 additions and 6 deletions

View file

@ -55,6 +55,7 @@ export default ({ app, store }, inject) => {
when (event) {
const currentYear = app.$time.currentYear()
const addTimezone = event.ap_id || event.place.name === 'online'
const opt = {
zone: store.state.settings.instance_timezone,
@ -62,7 +63,7 @@ export default ({ app, store }, inject) => {
}
const start = DateTime.fromSeconds(event.start_datetime, opt)
let time = start.toLocaleString({ weekday: 'long', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' })
let time = start.toLocaleString({ weekday: 'long', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit', ...( addTimezone && { timeZoneName: 'short' }) })
const end = event.end_datetime && DateTime.fromSeconds(event.end_datetime, opt)
if (end) {

View file

@ -46,7 +46,9 @@ module.exports = (sequelize, DataTypes) => {
zone: settings.instance_timezone,
locale: settings.instance_locale
}
const summary = `${this.place && this.place.name}, ${DateTime.fromSeconds(this.start_datetime, opt).toFormat('EEEE, d MMMM (HH:mm)')}`
const datetime = DateTime.fromSeconds(this.start_datetime, opt).toLocaleString({ weekday: 'long', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit', timeZoneName: 'short' })
const summary = `${this.place && this.place.name}, ${datetime}`
let attachment = []

View file

@ -1,4 +1,4 @@
function formatDatetime(timestamp, type = 'long') {
function formatDatetime(timestamp, type = 'long', addTimezone = false ) {
const options =
type === 'long'
? {
@ -7,6 +7,7 @@ function formatDatetime(timestamp, type = 'long') {
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
...(addTimezone && { timeZoneName: 'short' })
}
: { hour: '2-digit', minute: '2-digit' }
return new Date(timestamp * 1000).toLocaleString(undefined, options)
@ -14,11 +15,12 @@ function formatDatetime(timestamp, type = 'long') {
export function when(event) {
const addTimezone = event.ap_id || event.place.name === 'online'
if (event.multidate) {
return formatDatetime(event.start_datetime) + ' - ' + formatDatetime(event.end_datetime)
return formatDatetime(event.start_datetime, 'long', addTimezone) + ' - ' +
formatDatetime(event.end_datetime, 'long', addTimezone)
}
return (
formatDatetime(event.start_datetime) +
(event.end_datetime ? '-' + formatDatetime(event.end_datetime, 'short') : '')
formatDatetime(event.start_datetime, 'long', addTimezone)
)
}